Skip to content

Commit 3f4bccc

Browse files
committed
💻 refactor pokemon list
1 parent 7590718 commit 3f4bccc

3 files changed

Lines changed: 39 additions & 25 deletions

File tree

‎App.js‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useEffect, useState} from 'react';
2-
import { StyleSheet, Text, View, ScrollView, SafeAreaView } from 'react-native'; // React Native API Reference -> https://facebook.github.io/react-native/docs/activityindicator
3-
import { Header } from './components'
2+
import { StyleSheet, View } from 'react-native'; // React Native API Reference -> https://facebook.github.io/react-native/docs/activityindicator
3+
import { Header, ScrollableList } from './components'
44

55
const POKEMON_API = `https://pokeapi.co/api/v2/`
66
const GET_50_POKEMON_PATH = `pokemon?limit=50`
@@ -20,13 +20,7 @@ export default function App() {
2020
return (
2121
<View style={styles.container}>
2222
<Header/>
23-
<SafeAreaView style={styles.pokemonList}>
24-
<ScrollView>
25-
{
26-
pokemonList.map(pokemon => <View style={styles.listItem}><Text style={styles.listItemText}>{pokemon.name}</Text></View>)
27-
}
28-
</ScrollView>
29-
</SafeAreaView>
23+
<ScrollableList list={pokemonList}/>
3024
</View>
3125
);
3226
}
@@ -38,20 +32,5 @@ const styles = StyleSheet.create({
3832
alignItems: 'flex-start',
3933
justifyContent: 'center',
4034
flexDirection: 'column'
41-
},
42-
pokemonList: {
43-
flex: 1,
44-
flexDirection: 'column',
45-
width: '100%',
46-
},
47-
listItem: {
48-
height: 40,
49-
alignItems: 'center',
50-
justifyContent: 'center',
51-
borderBottomWidth: 1,
52-
borderBottomColor: 'black',
53-
},
54-
listItemText: {
55-
fontSize: 20,
5635
}
5736
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
3+
import { StyleSheet, SafeAreaView, ScrollView, Text, View } from 'react-native'
4+
export default function ScrollableList({list}) {
5+
return(
6+
<SafeAreaView style={styles.container}>
7+
<ScrollView>
8+
{
9+
list.map((pokemon, i) => <View key={i} style={styles.listItem}><Text style={styles.listItemText}>{pokemon.name}</Text></View>)
10+
}
11+
</ScrollView>
12+
</SafeAreaView>
13+
)
14+
}
15+
16+
const styles = StyleSheet.create({
17+
container: {
18+
flex: 1,
19+
flexDirection: 'column',
20+
width: '100%',
21+
},
22+
listItem: {
23+
height: 40,
24+
alignItems: 'center',
25+
justifyContent: 'center',
26+
borderBottomWidth: 1,
27+
borderBottomColor: 'black',
28+
},
29+
listItemText: {
30+
fontSize: 20,
31+
}
32+
})

‎components/index.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Header from './Header'
2+
import ScrollableList from './ScrollableList'
3+
24
export {
3-
Header
5+
Header,
6+
ScrollableList
47
}

0 commit comments

Comments
 (0)