344303947 / RN-NavigationExperimental-Redux-Example

A small demonstration app showing how to use Redux to manage navigation state in a React Native (>0.21) application using NavigationExperimental

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RN-NavigationExperimental-Redux-Example

A small demonstration app showing how to use Redux to manage navigation state in a React Native (>0.21) application using NavigationExperimental.

Screencast of flipping through a few different screes

The key elements to note when trying to implement NavigationExperimental with Redux include the following:

  • You don't need a <NavigationRootContainer />, which otherwise runs the navigation reducers, because Redux will do that for us. We lose the constant onNavigate() method in React's context, but that's okay because we just make more specific dispatches to navigation methods where they are needed, connected via Redux.
  • This implementation is still following the NavigationState and NavigationParentState conventions established by NavigationExperimental.
  • It also uses NavigationStateUtils to do the dirty work when reducing state.
  • You can skip your own implementation of the reducers and use React Native's versions. See this comment and the pure-rn-reducers branch.

Finally, this was just an attempt to figure out how to connect Redux and NavigationExperimental, and does not represent an ideal implementation. If you see room for improvement, please let me know.

A note about branches

At this time, NavigationExperimental is moving quite quickly and the API is still a bit of a moving target. Master branch will attempt to follow the current stable release (this is a change from previous) since things are starting to quiet down. For version-specific implementations older than the current stable release, I'm creating a branch per RN version. For example, see the 0.23 branch of this repo to see how to implement against the NavigationExperimental API in RN 0.23.

In the future, when NavigationExperimental is changing little between versions, we'll switch to a tag-based approach instead of branches.

About

A small demonstration app showing how to use Redux to manage navigation state in a React Native (>0.21) application using NavigationExperimental

License:MIT License


Languages

Language:JavaScript 60.1%Language:Objective-C 26.7%Language:Python 7.8%Language:Java 5.4%