в корне в index.js, это код:
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
и App.js в корне:
import React from 'react';
import { createStackNavigator, createSwitchNavigator, createAppContainer } from 'react-navigation';
import AuthLoadingScreen from './src/routes/Splash';
import HomeScreen from "./src/routes/Tabs/Home2";
const AppStack = createStackNavigator({ Home: HomeScreen });
const AuthStack = createStackNavigator({ SignIn: SignInScreen,Forget:ForgetLogin });
const SwitchNavigator = createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
App: HomeScreen,
},
{
initialRouteName: 'AuthLoading',
});
export default createAppContainer(SwitchNavigator);
Итак, я пытаюсь подключиться:
step1:
создать 3 папки в корне ./src
index.js---app.js
|
----src
|
redux
|
--------actions
|
----reducers
|
----store---index.js
Шаг 2: передать Store в приложение React Native
Я создаю index.js в папке магазина:
import { createStore , applyMiddleware , compose} from 'redux';
import {AsyncStorage} from 'react-native';
import thunk from 'redux-thunk';
import { createLogger } from "redux-logger";
import reducers from './../reducers';
import {autoRehydrate, persistStore} from "redux-persist";
const middleware = [ thunk ];
middleware.push(createLogger());
const store = createStore(
reducers,
undefined,
compose(
applyMiddleware(...middleware),
autoRehydrate()
)
);
persistStore(store, {storage: AsyncStorage});
export default store;
Теперь я меняю index.js в корне:
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { Provider } from 'react-redux';
import store from "./redux/store";
const RNRedux = () => (
<Provider store = { store }>
<App />
</Provider>
)
AppRegistry.registerComponent(appName, () => RNRedux);
Теперь я хочу подключить приложение React Native к магазину Redux, но как я могу это сделать с помощью SwitchNavigator?