The Navigator Component
Our application is going to use the navigator and its state to decide which one our of container views to display. We'll use our navigator in the root view of our application and let it handle the logic for switching our views as needed.
Let's start by creating a file index.js
in src/containers/Navigator/
and setup our imports:
The Navigator Container Class
There is a lot going on here, so let's take a minute to go through this one step at a time.
We start by calling the catchEmAll
action in our componentWillMount
method. This is just to get our app setup to display our lists of pokemon in the views we'll be creating later. _getActiveScene
is a method we'll pass to the NavigationAnimatedView
in order to determine which container component to render based off the current navigation state.
After that, we're returning a NavigationCard
component in our _renderCard
method. This is used by the NavigationAnimatedView
for rendering a single card in our navigation state's card stack. The _renderScene
method is in charge of setting up the view around our active scene. In this case we're just creating a simple view that accommodates for the height of our navigation header, and sets the status bar style to the default look and feel (black text with light background).
Finally, we are rendering out our NavigationAnimatedView
passing it our navigations state, a simple style declaration to cause the navigation to fill whatever space it can, and then we are passing it our appropriate helper functions for rendering our view.
Now let's tell react about our components props and export the connected component!
Hook Our Navigator Up
Our final step is to import our newly created Navigator component and plug it into our root container. Edit the src/containers/Root.js
file to reflect the following:
Last updated
Was this helpful?