- create a new application:
PokeDex
- add git repository to application
- open
$projectsDirectory/PokeDex/android
in Android Studio, do not go inside this directory, just open it in AS. - Create a new Android device, with PIE (SDK 28 + Google play API) -- optionally remove frames, to save desktop space, we won't need them
- if everything works fine just type in your terminal window:
npx react-native run android
-- if for some reason it doesn't work, try run button in AS
- open
$projectsDirectory/PokeDex/ios
in XCode. Wait until indexing is over, it can take a while. - select desired simulator device (iPhone SE 2nd gen. is fine)
- you can type:
npx react-native run-ios
in your terminal or just click on the play button in XCode
After all that you are almost there to start writing some code!
Let's see how to open the dev menu. On any screen just press:
- Android:
CTRL + M
orCMD + M
- iOS:
CMD + D
There is two main option, that is interesting for us: - Reload - works like a refreshing browser
- Start / Stop JS Debugging - it allows us to see what happens in-app
- I highly recommend disabling Fast Refreshing
There is also a shortcut to reload app:
- Android: double-tap
R
- ios:
CMD + R
- Change something on the main screen and reload the app, just test if everything works 1.a optionally remove flow
- Remove everything from
const App
, just leave it as an empty function - Remove imports from
react-native/Libraries/NewAppScreen
we won't need them anymore - We can also remove everything inside styles, same here, we won't use them
- Create
components
folder - Create
apiService.js
file - First, create a container:
- StatusBar
- SafeAreaView
- View
- Text
- Add some styles to make it look nice (at this point treat is only as exercise)
- Move to
apiService.js
and add fetch function- We will use PoeApi to create PokeDex: https://pokeapi.co/
- Create an async fetch function
- fetch URL: https://pokeapi.co/api/v2/pokemon/
- Move to App.js
- fetch data
- console log it
- put data into state
- add
FlatList
- render
FlatList
with data, justname
for now
- Create a PokeDex List Item component:
- name
- style it
- Use this component in FlatList renderer
- Style it nicely (at this moment there is no design)
- Change item to a button
- On button, press fetch pokemon data
- After fetch display alert with OK button and pokemon
id, type or types and weight
https://www.figma.com/file/oIEzr0GaNDfcBKsLIhVMsi/pokedex-app-iphone-x-daniel-motta?node-id=0%3A1
- Install: https://github.com/react-native-community/async-storage
- Set and get data form AsyncStorage
- Load full list of pokemons from API to asyncStore
- Create hook for asyncStorage operations
- Use this hook
- Add FlatList header
- Add input to header and set it's placeholder to 'search'
- Add filtering pokemons function
- Pass function to list header with filtering stored pokemons
- Add debounce to filtering function: https://css-tricks.com/debouncing-throttling-explained-examples/
- Add hook for debouncing and use it
- Add refresh action: load whole pokemons list and store it in AsyncStorage
- Add background task for loading pokemons details:
- show spinner while loading image
- save data in asyncstore
- if data is in asyncStore do not load new one
- show image, when it is in asyncStore
- Create hook for asyncStorage operations
- Add background task for loading pokemons details:
- show spinner while loading image
- save data in asyncstore
- if data is in asyncStore do not load new one
- show image, when it is in asyncStore
- Add Navigation
- HomeScreen
- DetailsScreen
- Stack navigation
- Add Pokemon Details Page