|
@@ -1,468 +1 @@
|
1
|
|
-/**
|
2
|
|
- * copy paste from deprecated - for now
|
3
|
|
- */
|
4
|
|
-
|
5
|
|
-import utils from './utils';
|
6
|
|
-import Navigation from './../Navigation';
|
7
|
|
-import Controllers, {Modal, Notification} from 'react-native-controllers';
|
8
|
|
-const React = Controllers.hijackReact();
|
9
|
|
-const {
|
10
|
|
- ControllerRegistry,
|
11
|
|
- TabBarControllerIOS,
|
12
|
|
- NavigationControllerIOS,
|
13
|
|
- DrawerControllerIOS
|
14
|
|
-} = React;
|
15
|
|
-
|
16
|
|
-function startTabBasedApp(params) {
|
17
|
|
- if (!params.tabs) {
|
18
|
|
- console.error('startTabBasedApp(params): params.tabs is required');
|
19
|
|
- return;
|
20
|
|
- }
|
21
|
|
- const controllerID = utils.getRandomId();
|
22
|
|
- const Controller = Controllers.createClass({
|
23
|
|
- render: function() {
|
24
|
|
- if (!params.drawer || (!params.drawer.left && !params.drawer.right)) {
|
25
|
|
- return this.renderBody();
|
26
|
|
- } else {
|
27
|
|
- const navigatorID = controllerID + '_drawer';
|
28
|
|
- return (
|
29
|
|
- <DrawerControllerIOS id={navigatorID}
|
30
|
|
- componentLeft={params.drawer.left ? params.drawer.left.screen : undefined}
|
31
|
|
- passPropsLeft={{navigatorID: navigatorID}}
|
32
|
|
- componentRight={params.drawer.right ? params.drawer.right.screen : undefined}
|
33
|
|
- passPropsRight={{navigatorID: navigatorID}}
|
34
|
|
- disableOpenGesture={params.drawer.disableOpenGesture}
|
35
|
|
- type={params.drawer.type ? params.drawer.type : undefined}
|
36
|
|
- animationType={params.drawer.animationType ? params.drawer.animationType : undefined}
|
37
|
|
- >
|
38
|
|
- {this.renderBody()}
|
39
|
|
- </DrawerControllerIOS>
|
40
|
|
- );
|
41
|
|
- }
|
42
|
|
- },
|
43
|
|
- renderBody: function() {
|
44
|
|
- return (
|
45
|
|
- <TabBarControllerIOS
|
46
|
|
- id={controllerID + '_tabs'}
|
47
|
|
- style={params.tabsStyle}>
|
48
|
|
- {
|
49
|
|
- params.tabs.map(function(tab, index) {
|
50
|
|
- const navigatorID = controllerID + '_nav' + index;
|
51
|
|
- const screenInstanceID = utils.getRandomId();
|
52
|
|
- if (!tab.screen) {
|
53
|
|
- console.error('startTabBasedApp(params): every tab must include a screen property, take a look at tab#' + (index + 1));
|
54
|
|
- return;
|
55
|
|
- }
|
56
|
|
- const {
|
57
|
|
- navigatorStyle,
|
58
|
|
- navigatorButtons,
|
59
|
|
- navigatorEventID
|
60
|
|
- } = _mergeScreenSpecificSettings(tab.screen, screenInstanceID, tab);
|
61
|
|
- return (
|
62
|
|
- <TabBarControllerIOS.Item {...tab} title={tab.label}>
|
63
|
|
- <NavigationControllerIOS
|
64
|
|
- id={navigatorID}
|
65
|
|
- title={tab.title}
|
66
|
|
- titleImage={tab.titleImage}
|
67
|
|
- component={tab.screen}
|
68
|
|
- passProps={{
|
69
|
|
- navigatorID: navigatorID,
|
70
|
|
- screenInstanceID: screenInstanceID,
|
71
|
|
- navigatorEventID: navigatorEventID
|
72
|
|
- }}
|
73
|
|
- style={navigatorStyle}
|
74
|
|
- leftButtons={navigatorButtons.leftButtons}
|
75
|
|
- rightButtons={navigatorButtons.rightButtons}
|
76
|
|
- />
|
77
|
|
- </TabBarControllerIOS.Item>
|
78
|
|
- );
|
79
|
|
- })
|
80
|
|
- }
|
81
|
|
- </TabBarControllerIOS>
|
82
|
|
- );
|
83
|
|
- }
|
84
|
|
- });
|
85
|
|
- ControllerRegistry.registerController(controllerID, () => Controller);
|
86
|
|
- ControllerRegistry.setRootController(controllerID, params.animationType, params.passProps || {});
|
87
|
|
-}
|
88
|
|
-
|
89
|
|
-function startSingleScreenApp(params) {
|
90
|
|
- if (!params.screen) {
|
91
|
|
- console.error('startSingleScreenApp(params): params.screen is required');
|
92
|
|
- return;
|
93
|
|
- }
|
94
|
|
- const controllerID = utils.getRandomId();
|
95
|
|
- const Controller = Controllers.createClass({
|
96
|
|
- render: function() {
|
97
|
|
- if (!params.drawer || (!params.drawer.left && !params.drawer.right)) {
|
98
|
|
- return this.renderBody();
|
99
|
|
- } else {
|
100
|
|
- const navigatorID = controllerID + '_drawer';
|
101
|
|
- return (
|
102
|
|
- <DrawerControllerIOS id={navigatorID}
|
103
|
|
- componentLeft={params.drawer.left ? params.drawer.left.screen : undefined}
|
104
|
|
- passPropsLeft={{navigatorID: navigatorID}}
|
105
|
|
- componentRight={params.drawer.right ? params.drawer.right.screen : undefined}
|
106
|
|
- passPropsRight={{navigatorID: navigatorID}}
|
107
|
|
- disableOpenGesture={params.drawer.disableOpenGesture}>
|
108
|
|
- {this.renderBody()}
|
109
|
|
- </DrawerControllerIOS>
|
110
|
|
- );
|
111
|
|
- }
|
112
|
|
- },
|
113
|
|
- renderBody: function() {
|
114
|
|
- const screen = params.screen;
|
115
|
|
- const navigatorID = controllerID + '_nav';
|
116
|
|
- const screenInstanceID = utils.getRandomId();
|
117
|
|
- if (!screen.screen) {
|
118
|
|
- console.error('startSingleScreenApp(params): screen must include a screen property');
|
119
|
|
- return;
|
120
|
|
- }
|
121
|
|
- const {
|
122
|
|
- navigatorStyle,
|
123
|
|
- navigatorButtons,
|
124
|
|
- navigatorEventID
|
125
|
|
- } = _mergeScreenSpecificSettings(screen.screen, screenInstanceID, screen);
|
126
|
|
- return (
|
127
|
|
- <NavigationControllerIOS
|
128
|
|
- id={navigatorID}
|
129
|
|
- title={screen.title}
|
130
|
|
- titleImage={screen.titleImage}
|
131
|
|
- component={screen.screen}
|
132
|
|
- passProps={{
|
133
|
|
- navigatorID: navigatorID,
|
134
|
|
- screenInstanceID: screenInstanceID,
|
135
|
|
- navigatorEventID: navigatorEventID
|
136
|
|
- }}
|
137
|
|
- style={navigatorStyle}
|
138
|
|
- leftButtons={navigatorButtons.leftButtons}
|
139
|
|
- rightButtons={navigatorButtons.rightButtons}
|
140
|
|
- />
|
141
|
|
- );
|
142
|
|
- }
|
143
|
|
- });
|
144
|
|
- ControllerRegistry.registerController(controllerID, () => Controller);
|
145
|
|
- ControllerRegistry.setRootController(controllerID, params.animationType, params.passProps || {});
|
146
|
|
-}
|
147
|
|
-
|
148
|
|
-function _mergeScreenSpecificSettings(screenID, screenInstanceID, params) {
|
149
|
|
- const screenClass = Navigation.getRegisteredScreen(screenID);
|
150
|
|
- if (!screenClass) {
|
151
|
|
- console.error('Cannot create screen ' + screenID + '. Are you it was registered with Navigation.registerScreen?');
|
152
|
|
- return;
|
153
|
|
- }
|
154
|
|
- const navigatorStyle = Object.assign({}, screenClass.navigatorStyle);
|
155
|
|
- if (params.navigatorStyle) {
|
156
|
|
- Object.assign(navigatorStyle, params.navigatorStyle);
|
157
|
|
- }
|
158
|
|
-
|
159
|
|
- const navigatorEventID = screenInstanceID + '_events';
|
160
|
|
- const navigatorButtons = Object.assign({}, screenClass.navigatorButtons);
|
161
|
|
- if (params.navigatorButtons) {
|
162
|
|
- Object.assign(navigatorButtons, params.navigatorButtons);
|
163
|
|
- }
|
164
|
|
- if (navigatorButtons.leftButtons) {
|
165
|
|
- for (let i = 0; i < navigatorButtons.leftButtons.length; i++) {
|
166
|
|
- navigatorButtons.leftButtons[i].onPress = navigatorEventID;
|
167
|
|
- }
|
168
|
|
- }
|
169
|
|
- if (navigatorButtons.rightButtons) {
|
170
|
|
- for (let i = 0; i < navigatorButtons.rightButtons.length; i++) {
|
171
|
|
- navigatorButtons.rightButtons[i].onPress = navigatorEventID;
|
172
|
|
- }
|
173
|
|
- }
|
174
|
|
- return {navigatorStyle, navigatorButtons, navigatorEventID};
|
175
|
|
-}
|
176
|
|
-
|
177
|
|
-function navigatorPush(navigator, params) {
|
178
|
|
- if (!params.screen) {
|
179
|
|
- console.error('Navigator.push(params): params.screen is required');
|
180
|
|
- return;
|
181
|
|
- }
|
182
|
|
- const screenInstanceID = utils.getRandomId();
|
183
|
|
- const {
|
184
|
|
- navigatorStyle,
|
185
|
|
- navigatorButtons,
|
186
|
|
- navigatorEventID
|
187
|
|
- } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
|
188
|
|
- const passProps = Object.assign({}, params.passProps);
|
189
|
|
- passProps.navigatorID = navigator.navigatorID;
|
190
|
|
- passProps.screenInstanceID = screenInstanceID;
|
191
|
|
- passProps.navigatorEventID = navigatorEventID;
|
192
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).push({
|
193
|
|
- title: params.title,
|
194
|
|
- titleImage: params.titleImage,
|
195
|
|
- component: params.screen,
|
196
|
|
- animated: params.animated,
|
197
|
|
- passProps: passProps,
|
198
|
|
- style: navigatorStyle,
|
199
|
|
- backButtonTitle: params.backButtonTitle,
|
200
|
|
- backButtonHidden: params.backButtonHidden,
|
201
|
|
- leftButtons: navigatorButtons.leftButtons,
|
202
|
|
- rightButtons: navigatorButtons.rightButtons
|
203
|
|
- });
|
204
|
|
-}
|
205
|
|
-
|
206
|
|
-function navigatorPop(navigator, params) {
|
207
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).pop({
|
208
|
|
- animated: params.animated
|
209
|
|
- });
|
210
|
|
-}
|
211
|
|
-
|
212
|
|
-function navigatorPopToRoot(navigator, params) {
|
213
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).popToRoot({
|
214
|
|
- animated: params.animated
|
215
|
|
- });
|
216
|
|
-}
|
217
|
|
-
|
218
|
|
-function navigatorResetTo(navigator, params) {
|
219
|
|
- if (!params.screen) {
|
220
|
|
- console.error('Navigator.resetTo(params): params.screen is required');
|
221
|
|
- return;
|
222
|
|
- }
|
223
|
|
- const screenInstanceID = utils.getRandomId();
|
224
|
|
- const {
|
225
|
|
- navigatorStyle,
|
226
|
|
- navigatorButtons,
|
227
|
|
- navigatorEventID
|
228
|
|
- } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
|
229
|
|
- const passProps = Object.assign({}, params.passProps);
|
230
|
|
- passProps.navigatorID = navigator.navigatorID;
|
231
|
|
- passProps.screenInstanceID = screenInstanceID;
|
232
|
|
- passProps.navigatorEventID = navigatorEventID;
|
233
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).resetTo({
|
234
|
|
- title: params.title,
|
235
|
|
- titleImage: params.titleImage,
|
236
|
|
- component: params.screen,
|
237
|
|
- animated: params.animated,
|
238
|
|
- passProps: passProps,
|
239
|
|
- style: navigatorStyle,
|
240
|
|
- leftButtons: navigatorButtons.leftButtons,
|
241
|
|
- rightButtons: navigatorButtons.rightButtons
|
242
|
|
- });
|
243
|
|
-}
|
244
|
|
-
|
245
|
|
-function navigatorSetTitle(navigator, params) {
|
246
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).setTitle({
|
247
|
|
- title: params.title
|
248
|
|
- });
|
249
|
|
-}
|
250
|
|
-
|
251
|
|
-function navigatorSetTitleImage(navigator, params) {
|
252
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).setTitleImage({
|
253
|
|
- titleImage: params.titleImage
|
254
|
|
- });
|
255
|
|
-}
|
256
|
|
-
|
257
|
|
-function navigatorToggleNavBar(navigator, params) {
|
258
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).setHidden({
|
259
|
|
- hidden: ((params.to === 'hidden') ? true : false),
|
260
|
|
- animated: params.animated
|
261
|
|
- });
|
262
|
|
-}
|
263
|
|
-
|
264
|
|
-function navigatorToggleDrawer(navigator, params) {
|
265
|
|
- const controllerID = navigator.navigatorID.split('_')[0];
|
266
|
|
- if (params.to == 'open') {
|
267
|
|
- Controllers.DrawerControllerIOS(controllerID + '_drawer').open({
|
268
|
|
- side: params.side,
|
269
|
|
- animated: params.animated
|
270
|
|
- });
|
271
|
|
- } else if (params.to == 'closed') {
|
272
|
|
- Controllers.DrawerControllerIOS(controllerID + '_drawer').close({
|
273
|
|
- side: params.side,
|
274
|
|
- animated: params.animated
|
275
|
|
- });
|
276
|
|
- } else {
|
277
|
|
- Controllers.DrawerControllerIOS(controllerID + '_drawer').toggle({
|
278
|
|
- side: params.side,
|
279
|
|
- animated: params.animated
|
280
|
|
- });
|
281
|
|
- }
|
282
|
|
-}
|
283
|
|
-
|
284
|
|
-function navigatorToggleTabs(navigator, params) {
|
285
|
|
- const controllerID = navigator.navigatorID.split('_')[0];
|
286
|
|
- Controllers.TabBarControllerIOS(controllerID + '_tabs').setHidden({
|
287
|
|
- hidden: params.to == 'hidden',
|
288
|
|
- animated: !(params.animated === false)
|
289
|
|
- });
|
290
|
|
-}
|
291
|
|
-
|
292
|
|
-function navigatorSetTabBadge(navigator, params) {
|
293
|
|
- const controllerID = navigator.navigatorID.split('_')[0];
|
294
|
|
- if (params.tabIndex || params.tabIndex === 0) {
|
295
|
|
- Controllers.TabBarControllerIOS(controllerID + '_tabs').setBadge({
|
296
|
|
- tabIndex: params.tabIndex,
|
297
|
|
- badge: params.badge
|
298
|
|
- });
|
299
|
|
- } else {
|
300
|
|
- Controllers.TabBarControllerIOS(controllerID + '_tabs').setBadge({
|
301
|
|
- contentId: navigator.navigatorID,
|
302
|
|
- contentType: 'NavigationControllerIOS',
|
303
|
|
- badge: params.badge
|
304
|
|
- });
|
305
|
|
- }
|
306
|
|
-}
|
307
|
|
-
|
308
|
|
-function navigatorSwitchToTab(navigator, params) {
|
309
|
|
- const controllerID = navigator.navigatorID.split('_')[0];
|
310
|
|
- if (params.tabIndex || params.tabIndex === 0) {
|
311
|
|
- Controllers.TabBarControllerIOS(controllerID + '_tabs').switchTo({
|
312
|
|
- tabIndex: params.tabIndex
|
313
|
|
- });
|
314
|
|
- } else {
|
315
|
|
- Controllers.TabBarControllerIOS(controllerID + '_tabs').switchTo({
|
316
|
|
- contentId: navigator.navigatorID,
|
317
|
|
- contentType: 'NavigationControllerIOS'
|
318
|
|
- });
|
319
|
|
- }
|
320
|
|
-}
|
321
|
|
-
|
322
|
|
-function navigatorSetButtons(navigator, navigatorEventID, params) {
|
323
|
|
- if (params.leftButtons) {
|
324
|
|
- const buttons = params.leftButtons.slice(); // clone
|
325
|
|
- for (let i = 0; i < buttons.length; i++) {
|
326
|
|
- buttons[i].onPress = navigatorEventID;
|
327
|
|
- }
|
328
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).setLeftButtons(buttons, params.animated);
|
329
|
|
- }
|
330
|
|
- if (params.rightButtons) {
|
331
|
|
- const buttons = params.rightButtons.slice(); // clone
|
332
|
|
- for (let i = 0; i < buttons.length; i++) {
|
333
|
|
- buttons[i].onPress = navigatorEventID;
|
334
|
|
- }
|
335
|
|
- Controllers.NavigationControllerIOS(navigator.navigatorID).setRightButtons(buttons, params.animated);
|
336
|
|
- }
|
337
|
|
-}
|
338
|
|
-
|
339
|
|
-function showModal(params) {
|
340
|
|
- if (!params.screen) {
|
341
|
|
- console.error('showModal(params): params.screen is required');
|
342
|
|
- return;
|
343
|
|
- }
|
344
|
|
- const controllerID = utils.getRandomId();
|
345
|
|
- const Controller = Controllers.createClass({
|
346
|
|
- render: function() {
|
347
|
|
- const navigatorID = controllerID + '_nav';
|
348
|
|
- const screenInstanceID = utils.getRandomId();
|
349
|
|
- const {
|
350
|
|
- navigatorStyle,
|
351
|
|
- navigatorButtons,
|
352
|
|
- navigatorEventID
|
353
|
|
- } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
|
354
|
|
- const passProps = Object.assign({}, params.passProps);
|
355
|
|
- passProps.navigatorID = navigatorID;
|
356
|
|
- passProps.screenInstanceID = screenInstanceID;
|
357
|
|
- passProps.navigatorEventID = navigatorEventID;
|
358
|
|
- return (
|
359
|
|
- <NavigationControllerIOS
|
360
|
|
- id={navigatorID}
|
361
|
|
- title={params.title}
|
362
|
|
- titleImage={params.titleImage}
|
363
|
|
- component={params.screen}
|
364
|
|
- passProps={passProps}
|
365
|
|
- style={navigatorStyle}
|
366
|
|
- leftButtons={navigatorButtons.leftButtons}
|
367
|
|
- rightButtons={navigatorButtons.rightButtons}/>
|
368
|
|
- );
|
369
|
|
- }
|
370
|
|
- });
|
371
|
|
- ControllerRegistry.registerController(controllerID, () => Controller);
|
372
|
|
- Modal.showController(controllerID, params.animationType);
|
373
|
|
-}
|
374
|
|
-
|
375
|
|
-function dismissModal(params) {
|
376
|
|
- Modal.dismissController(params.animationType);
|
377
|
|
-}
|
378
|
|
-
|
379
|
|
-function dismissAllModals(params) {
|
380
|
|
- Modal.dismissAllControllers(params.animationType);
|
381
|
|
-}
|
382
|
|
-
|
383
|
|
-function showLightBox(params) {
|
384
|
|
- if (!params.screen) {
|
385
|
|
- console.error('showLightBox(params): params.screen is required');
|
386
|
|
- return;
|
387
|
|
- }
|
388
|
|
- const controllerID = utils.getRandomId();
|
389
|
|
- const navigatorID = controllerID + '_nav';
|
390
|
|
- const screenInstanceID = utils.getRandomId();
|
391
|
|
- const {
|
392
|
|
- navigatorStyle,
|
393
|
|
- navigatorButtons,
|
394
|
|
- navigatorEventID
|
395
|
|
- } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
|
396
|
|
- const passProps = Object.assign({}, params.passProps);
|
397
|
|
- passProps.navigatorID = navigatorID;
|
398
|
|
- passProps.screenInstanceID = screenInstanceID;
|
399
|
|
- passProps.navigatorEventID = navigatorEventID;
|
400
|
|
- Modal.showLightBox({
|
401
|
|
- component: params.screen,
|
402
|
|
- passProps: passProps,
|
403
|
|
- style: params.style
|
404
|
|
- });
|
405
|
|
-}
|
406
|
|
-
|
407
|
|
-function dismissLightBox(params) {
|
408
|
|
- Modal.dismissLightBox();
|
409
|
|
-}
|
410
|
|
-
|
411
|
|
-function showInAppNotification(params) {
|
412
|
|
- if (!params.screen) {
|
413
|
|
- console.error('showInAppNotification(params): params.screen is required');
|
414
|
|
- return;
|
415
|
|
- }
|
416
|
|
-
|
417
|
|
- const controllerID = utils.getRandomId();
|
418
|
|
- const navigatorID = controllerID + '_nav';
|
419
|
|
- const screenInstanceID = utils.getRandomId();
|
420
|
|
- const {
|
421
|
|
- navigatorStyle,
|
422
|
|
- navigatorButtons,
|
423
|
|
- navigatorEventID
|
424
|
|
- } = _mergeScreenSpecificSettings(params.screen, screenInstanceID, params);
|
425
|
|
- const passProps = Object.assign({}, params.passProps);
|
426
|
|
- passProps.navigatorID = navigatorID;
|
427
|
|
- passProps.screenInstanceID = screenInstanceID;
|
428
|
|
- passProps.navigatorEventID = navigatorEventID;
|
429
|
|
-
|
430
|
|
- Notification.show({
|
431
|
|
- component: params.screen,
|
432
|
|
- passProps: passProps,
|
433
|
|
- style: params.style,
|
434
|
|
- animation: params.animation || Notification.AnimationPresets.default,
|
435
|
|
- position: params.position,
|
436
|
|
- shadowRadius: params.shadowRadius,
|
437
|
|
- dismissWithSwipe: params.dismissWithSwipe || true,
|
438
|
|
- autoDismissTimerSec: params.autoDismissTimerSec || 5
|
439
|
|
- });
|
440
|
|
-}
|
441
|
|
-
|
442
|
|
-function dismissInAppNotification(params) {
|
443
|
|
- Notification.dismiss(params);
|
444
|
|
-}
|
445
|
|
-
|
446
|
|
-export default {
|
447
|
|
- startTabBasedApp,
|
448
|
|
- startSingleScreenApp,
|
449
|
|
- navigatorPush,
|
450
|
|
- navigatorPop,
|
451
|
|
- navigatorPopToRoot,
|
452
|
|
- navigatorResetTo,
|
453
|
|
- showModal,
|
454
|
|
- dismissModal,
|
455
|
|
- dismissAllModals,
|
456
|
|
- showLightBox,
|
457
|
|
- dismissLightBox,
|
458
|
|
- showInAppNotification,
|
459
|
|
- dismissInAppNotification,
|
460
|
|
- navigatorSetButtons,
|
461
|
|
- navigatorSetTitle,
|
462
|
|
- navigatorSetTitleImage,
|
463
|
|
- navigatorToggleDrawer,
|
464
|
|
- navigatorToggleTabs,
|
465
|
|
- navigatorSetTabBadge,
|
466
|
|
- navigatorSwitchToTab,
|
467
|
|
- navigatorToggleNavBar
|
468
|
|
-}
|
|
1
|
+module.exports = {};
|