-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.tsx
146 lines (134 loc) · 3.35 KB
/
App.tsx
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React, {memo} from 'react';
import {
FlatList,
Image,
SafeAreaView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from 'react-native';
import {Colors} from 'react-native/Libraries/NewAppScreen';
interface Pokemon {
gameIndex: string;
name: string;
types: {name: string}[];
imageUrl: string;
}
// Taken directly from https://github.com/MatheusPires99/pokedex
const POKEMON_TYPE_COLORS: {[type: string]: string} = {
normal: '#A8A878',
fighting: '#C03028',
flying: '#A890F0',
poison: '#A040A0',
ground: '#E0C068',
rock: '#B8A038',
bug: '#A8B820',
ghost: '#705898',
steel: '#B8B8D0',
fire: '#FA6C6C',
water: '#6890F0',
grass: '#48CFB2',
electric: '#FFCE4B',
psychic: '#F85888',
ice: '#98D8D8',
dragon: '#7038F8',
dark: '#705848',
fairy: '#EE99AC',
};
const pokedex: Pokemon[] = require('./pokedex.json');
const cardStyles = StyleSheet.create({
container: {width: '50%'},
innerContainer: {
padding: 10,
paddingRight: 0,
margin: 5,
borderRadius: 10,
elevation: 7,
},
name: {
fontSize: 16,
color: 'white',
fontWeight: 'bold',
flex: 1,
paddingRight: 5,
},
typeContainer: {
width: '100%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#6662',
borderRadius: 10,
marginTop: 5,
padding: 5,
},
nameAndIndexContainer: {
flexDirection: 'row',
width: '100%',
justifyContent: 'space-between',
paddingRight: 10,
},
index: {fontSize: 12, color: '#6666'},
type: {color: '#fffa'},
image: {width: 100, height: 100},
typesContainer: {flex: 1, paddingTop: 20},
typeRow: {
flexDirection: 'row',
width: '100%',
justifyContent: 'space-between',
},
});
const PokemonCard = memo(({item}: {item: Pokemon}) => {
return (
<View style={cardStyles.container}>
<View
style={[
cardStyles.innerContainer,
{
backgroundColor: POKEMON_TYPE_COLORS[item.types[0].name],
},
]}>
<View style={cardStyles.nameAndIndexContainer}>
<Text numberOfLines={1} style={cardStyles.name}>
{item.name.toUpperCase()}
</Text>
<Text style={cardStyles.index}>#{item.gameIndex}</Text>
</View>
<View style={cardStyles.typeRow}>
<View style={cardStyles.typesContainer}>
{item.types.map(type => (
<View key={type.name} style={cardStyles.typeContainer}>
<Text style={cardStyles.type}>{type.name}</Text>
</View>
))}
</View>
<Image source={{uri: item.imageUrl}} style={cardStyles.image} />
</View>
</View>
</View>
);
});
const renderItem = ({item}: {item: Pokemon}) => {
return <PokemonCard item={item} />;
};
const styles = StyleSheet.create({list: {paddingHorizontal: 5}});
const App = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<FlatList
numColumns={2}
keyExtractor={item => item.name}
data={pokedex}
renderItem={renderItem}
contentContainerStyle={styles.list}
/>
</SafeAreaView>
);
};
export default App;