Creating Some Helpers
Our app is going to use NavigationExperimental and setup the navigation state to be handled by Redux. To start, we'll configure some helpers to make the navigation component easier to reason about. Then we'll set up the navigator itself and hook it up with our Redux store. Let's get started.
Create a file called navigator-helpers.js in src/containers/Navigator/ and import the following modules:
import {
Animated,
NavigationExperimental,
Easing,
} from 'react-native';
import clrs from '../../utils/clrs';
import React, { PropTypes } from 'react';
import * as actions from '../../actions';
const { Header: NavigationHeader } = NavigationExperimental;State and Dispatch
Let's export some functions for our navigator component to make use of. To start, we'll configure the functions we'll use to setup our components props and actions with connect
src/containers/Navigator/navigator-helpers.js
export function mapStateToProps(state) {
return {
navigationState: state.navigator,
pokemon: state.pokemon.get('all'),
activePokemon: state.pokemon.get('active'),
};
}
export function mapDispatchToProps(state) {
return {
goToPokemonDetail: artist => {
dispatch(actions.goToPokemonDetail(artist));
},
gotoPokedex: () => dispatch(actions.gotoPokedex()),
onNavigate: payload => dispatch(actions.onNavigate(payload)),
catchEmAll: () => dispatch(actions.catchEmAll()),
iChooseYou: url => dispatch(actions.iChooseYou(url)),
clearChoice: () => dispatch(actions.clearChoice()),
};
}Animations
We'll also create a helper function for handling animation in our navigator.
Title and Header
Finally, we'll create some helper functions to render out our navigations header, and the title for the current state.
That does it for the helpers file! Next we'll setup the actual navigator component.
Last updated
Was this helpful?