You have a few options for building out the navigation of your app with React Native. For example there is a NavigatorIOS component which you can use to build out a simple navigation for your iOS specific apps. There is also the generic Navigator component which can be used for either iOS or Android Applications.
In this workshop we will be working with a third option: NavigationExperimental. NavigationExperimental differs from the Navigator component in that it attempts to be more like Redux using a single-direction flow of data and reducers to manage its state.
At the time of this writing, NavigationExperimental is replacing the Navigator. The documentation will be updated to reflect this.
Some Setup
We're going to need to add a few things to our project that will be used by our Navigator. Firstly, we will need to create some navigation specific actions, as well as the reducers our redux store will need to use to properly manage our state.
Let's get started by adding a few new constants to our src/constants/index.js file:
The only other thing left to do now is setup our navigation's reducer!
// src/reducers/navigator.jsimport {ROUTES, GOTO_ROUTE} from'../constants';import {NavigationExperimental} from'react-native';const { Reducer: NavigationReducer } = NavigationExperimental;constnavigatorReducer=NavigationReducer.StackReducer({getPushedReducerForAction: action => {if (action.type ===GOTO_ROUTE) {/* The below line is confusing as other NavigationReducer's may consist of a state, however for StackReducer, it is always null so the action.payload is taken as the next route */return state => state ||action.payload; }returnnull; },getReducerForState: initialState => state => state || initialState, initialState:ROUTES.POKEDEX,});exportdefault navigatorReducer;