123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- 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";
- import {registerScreens} from "./screens";
- import {Platform} from "react-native";
-
-
- const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
- const reducer = combineReducers(reducers);
- const store = createStoreWithMiddleware(reducer);
-
-
- registerScreens(store, Provider);
-
-
- export default class App {
- constructor() {
-
- store.subscribe(this.onStoreUpdate.bind(this));
- store.dispatch(appActions.appInitialized());
- }
-
- onStoreUpdate() {
- const {root} = store.getState().app;
-
-
- if (this.currentRoot != root) {
- this.currentRoot = root;
- this.startApp(root);
- }
- }
-
- startApp(root) {
- switch (root) {
- case 'login':
- if (Platform.OS === 'ios') {
- 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,
- fn: function() {
- return 'Hello from a function!';
- }
- }
- });
- } else {
- 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,
- fn: function() {
- return 'Hello from a function!';
- }
- }
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- 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',
- overrideBackPress: true,
- 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',
- drawer: {
- left: {
- screen: 'example.BottomTabsSideMenu'
- },
- disableOpenGesture: false,
- passProps: {
- title: 'Hello from SideMenu'
- }
- },
- appStyle: {
- bottomTabBadgeTextColor: '#ffffff',
- bottomTabBadgeBackgroundColor: '#ff0000'
- }
- });
- return;
- default:
- console.error('Unknown app root');
- }
- }
- }
|