123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- import { createStore, applyMiddleware, combineReducers } from 'redux';
- import { Provider } from 'react-redux';
- import { Navigation } from 'react-native-navigation';
- import thunk from 'redux-thunk';
- import * as reducers from './reducers';
- import * as appActions from './reducers/app/actions';
-
- // redux related book keeping
- const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
- const reducer = combineReducers(reducers);
- const store = createStoreWithMiddleware(reducer);
-
- // screen related book keeping
- import { registerScreens } from './screens';
- registerScreens(store, Provider);
-
- // notice that this is just a simple class, it's not a React component
- export default class App {
- constructor() {
- // since react-redux only works on components, we need to subscribe this class manually
- store.subscribe(this.onStoreUpdate.bind(this));
- store.dispatch(appActions.appInitialized());
- }
-
- onStoreUpdate() {
- const { root } = store.getState().app;
- // handle a root change
- // if your app doesn't change roots in runtime, you can remove onStoreUpdate() altogether
- if (this.currentRoot != root) {
- this.currentRoot = root;
- this.startApp(root);
- }
- }
-
- startApp(root) {
- switch (root) {
- case 'login':
- Navigation.startSingleScreenApp({
- screen: {
- screen: 'example.LoginScreen',
- title: 'Login',
- navigatorStyle: {}
- },
- passProps: {
- str: 'This is a prop passed in \'startSingleScreenApp()\'!',
- obj: {
- str: 'This is a prop passed in an object!',
- arr: [
- {
- str: 'This is a prop in an object in an array in an object!'
- }
- ],
- arr2: [
- [
- 'array of strings',
- 'with two strings'
- ],
- [
- 1, 2, 3
- ]
- ]
- },
- num: 1234
- }
- });
- return;
- case 'after-login':
- Navigation.startTabBasedApp({
- tabs: [
- {
- label: 'One',
- screen: 'example.FirstTabScreen',
- icon: require('../img/one.png'),
- selectedIcon: require('../img/one_selected.png'),
- title: 'Screen One',
- navigatorStyle: {},
- },
- {
- label: 'Two',
- screen: 'example.SecondTabScreen',
- icon: require('../img/two.png'),
- selectedIcon: require('../img/two_selected.png'),
- title: 'Screen Two',
- navigatorStyle: {},
- }
- ],
- passProps: {
- str: 'This is a prop passed in \'startTabBasedApp\'!',
- obj: {
- str: 'This is a prop passed in an object!',
- arr: [
- {
- str: 'This is a prop in an object in an array in an object!'
- }
- ]
- },
- num: 1234
- },
- animationType: 'slide-down',
- title: 'Redux Example'
- });
- return;
- default:
- console.error('Unknown app root');
- }
- }
- }
|