forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
196 lines (191 loc) · 6.43 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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";
// redux related book keeping
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
const reducer = combineReducers(reducers);
const store = createStoreWithMiddleware(reducer);
// screen related book keeping
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':
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!';
}
}
});
// Navigation.startSingleScreenApp({
// screen: {
// title: 'Example',
// screen: 'example.TopTabsScreen',
// topTabs: [
// {
// screenId: 'example.FirstTabScreen',
// title: 'Tab1',
// passProps: {
// str: 'This is a prop passed to Tab1',
// fn: () => 'Hello from a function passed as passProps!'
// }
// },
// {
// screenId: 'example.PushedScreen',
// title: 'Tab2',
// passProps: {
// str: 'This is a prop passed to Tab2'
// }
// },
// {
// screenId: 'example.ListScreen',
// title: 'Tab3',
// passProps: {
// str: 'This is a prop passed to Tab3'
// }
// }
// ],
// navigatorStyle: {}
// },
// drawer: { // optional, add this if you want a side menu drawer in your app
// left: { // optional, define if you want a drawer from the left
// screen: 'example.SideMenu' // unique ID registered with Navigation.registerScreen
// },
// disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
// }
// });
}
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: { // optional, add this if you want a side menu drawer in your app
left: { // optional, define if you want a drawer from the left
screen: 'example.BottomTabsSideMenu' // unique ID registered with Navigation.registerScreen
},
disableOpenGesture: false, // optional, can the drawer be opened with a swipe instead of button
passProps: {
title: 'Hello from SideMenu'
}
},
appStyle: {
bottomTabBadgeTextColor: '#ffffff',
bottomTabBadgeBackgroundColor: '#ff0000'
}
});
return;
default:
console.error('Unknown app root');
}
}
}