-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
72 lines (66 loc) · 1.54 KB
/
App.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, useEffect} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Platform,
FlatList,
TouchableOpacity,
Alert,
} from 'react-native';
import {fetchPokemonsList} from './apiService';
const App = () => {
const [data, setData] = useState([]);
const barStyle = Platform.OS === 'ios' ? 'default' : 'light-content';
useEffect(() => {
(async () => {
const response = await fetchPokemonsList();
setData(response.results);
})();
}, []);
return (
<>
<StatusBar barStyle={barStyle} backgroundColor="red" />
<SafeAreaView style={styles.appContainer}>
<View style={styles.container}>
<FlatList
data={data}
keyExtractor={(item, index) => item.name + index}
renderItem={({item, index, separator}) => (
<TouchableOpacity
style={styles.button}
onPress={() => Alert.alert(item.name, item.url)}
key={Date.now() + index}>
<Text style={styles.text}>{item.name}</Text>
</TouchableOpacity>
)}
/>
</View>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
appContainer: {
backgroundColor: 'white',
flex: 1,
},
container: {
backgroundColor: '#eee',
flex: 1,
},
text: {
fontSize: 20,
fontWeight: '100',
},
button: {
alignItems: 'center',
padding: 8,
borderBottomColor: 'black',
borderBottomWidth: 1,
},
});
export default App;