- 
      
- 
        Save juanchoperezj/b8936f5d9de4cecc01d1cd400745ec9f to your computer and use it in GitHub Desktop. 
    react-native-navigation redux middleware example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { createAction } from 'redux-actions'; | |
| import { | |
| NAVIGATION_PUSH, | |
| NAVIGATION_POP, | |
| NAVIGATION_RESET_TO, | |
| NAVIGATION_POP_TO_ROOT | |
| } from './actions'; | |
| export const push = createAction(NAVIGATION_PUSH); | |
| export const pop = createAction(NAVIGATION_POP); | |
| export const resetTo = createAction(NAVIGATION_RESET_TO); | |
| export const popToRoot = createAction(NAVIGATION_POP_TO_ROOT); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import React, { Component } from 'react'; | |
| import hoistStatics from 'hoist-non-react-statics'; | |
| import { setNavigator } from './navigation'; | |
| import getDisplayName from './getDisplayName'; // Copied from react-redux source | |
| /** | |
| * This HOC is meant to decorate any screen component that is at the | |
| * root of the navigation stack. It uses its constructor to set the global | |
| * navigation object. Having a global navigation object that lives in a | |
| * redux middleware allows us to control navigation by dispatching redux | |
| * actions. | |
| */ | |
| export default function rootScreen(WrappedComponent) { | |
| class RootScreen extends Component { | |
| constructor(props) { | |
| super(props); | |
| const { navigator } = props; | |
| setNavigator(navigator); | |
| } | |
| render() { | |
| return <WrappedComponent {...this.props} />; | |
| } | |
| } | |
| const hoisted = hoistStatics(RootScreen, WrappedComponent); | |
| hoisted.displayName = 'RootScreen(' + getDisplayName(WrappedComponent) + ')'; | |
| return hoisted; | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import { Navigation } from 'react-native-navigation'; | |
| import SomeScreen from './SomeScreen'; | |
| import rootScreen from './rootScreen'; | |
| export function registerScreens(store, Provider) { | |
| Navigation.registerComponent( | |
| 'prefix.SomeScreen', | |
| () => rootScreen(SomeScreen), | |
| store, | |
| Provider | |
| ); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment