-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListOfMovies.js
73 lines (65 loc) · 1.92 KB
/
ListOfMovies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { useState } from 'react';
import { StyleSheet, Text, View, FlatList, TouchableOpacity } from 'react-native';
const ListOfMovies = ({ navigation }) => {
const startingDataSource = [
{ "title": "Elf", "releaseYear": "2003" },
{ "title": "The Grinch", "releaseYear": "1966" },
{ "title": "Die Hard", "releaseYear": "1988" },
{ "title": "Home Alone", "releaseYear": "1990" },
{ "title": "A Christmas Story", "releaseYear": "1983" }
];
const [movies, setMovies] = useState(startingDataSource);
async function loadMore() {
try {
const getMovie = await fetch('https://reactnative.dev/movies.json');
const getInfo = await getMovie.json();
setMovies(prevMovies => [...prevMovies, ...getInfo.movies]);
}
catch (error) {
console.error('You reached the end of list!', error);
}
};
return (
<View style={styles.container}>
<FlatList
data={movies}
keyExtractor={(item) => item.title}
renderItem = {({item}) => (
<TouchableOpacity
style={[styles.item, styles.border]}
onPress={() => {
navigation.navigate('Movie Details',{title: item.title, releaseYear: item.releaseYear });
}}>
<View>
<Text style={{ fontSize: 20 }}> {item.title} </Text>
</View>
</TouchableOpacity>
)}
extraData={movies}
/>
<Text style={[styles.loadMoreButton]} onPress={loadMore}>Load More</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
paddingTop: 50
},
item: {
padding: 10,
fontSize: 18,
height: 54,
},
border: {
borderWidth: 1,
borderColor: "gray",
},
loadMoreButton: {
backgroundColor: 'white',
padding: 10,
alignItems: 'center',
fontSize: 16,
color: 'blue',
},
});
export default ListOfMovies;