将react-native-navigation V2与redux集成

Ham*_*mid 2 react-native react-native-navigation

在RNNavigation的第1版中,我通过这种方式将我的商店发送到每个屏幕.

Navigation.registerComponent(RouterConstants.SplashScreen, () => SplashScreen, store, Provider)
Run Code Online (Sandbox Code Playgroud)

但在V2中似乎没有用. 在此输入图像描述

编辑:

index.js:

import configureNavigation from './routers/app_navigation'
import createStore from './reducers'

const store = createStore()
configureNavigation(store, Provider)

class App extends React.Component {
 constructor (props) {
   super(props)
   .
   .
   .
   this.startApp()
 }

 startApp () {
  Navigation.setRoot({
    stack: {
      children: [{
        component: {
          name: RouterConstants.SplashScreen
        }
      }]
    }
  })
 }
}

const app = new App()
Run Code Online (Sandbox Code Playgroud)

app_navigation.js:

import SplashScreen from '../containers/splash_screen_container'
.....
...


const initializeRouter = (store, Provider) => {
    Navigation.registerComponent(RouterConstants.SplashScreen, () => SplashScreen, store, Provider)
    ....
    ..

}
export default initializeRouter
Run Code Online (Sandbox Code Playgroud)

Pri*_*dya 9

好像你无法以旧方式注册到提供商.

因此,作为一种变通方法,您可以创建一个HOC,它包装屏幕供应商

定义

import React from "react";
import { Provider } from "react-redux";

...

function reduxStoreWrapper (MyComponent, store) {
    return () => {
        return class StoreWrapper extends React.Component {
            render () {
                return (
                    <Provider store={store}>
                        <MyComponent />
                    </Provider>
                );
            }
        };
    };
}
Run Code Online (Sandbox Code Playgroud)

用法

Navigation.registerComponent("RouterConstants.SplashScreen", reduxStoreWrapper(SplashScreen, store))
Run Code Online (Sandbox Code Playgroud)