|
@@ -1,6 +1,6 @@
|
1
|
1
|
import utils from './utils';
|
2
|
2
|
import Navigation from './Navigation';
|
3
|
|
-import Controllers from 'react-native-controllers';
|
|
3
|
+import Controllers, { Modal } from 'react-native-controllers';
|
4
|
4
|
const React = Controllers.hijackReact();
|
5
|
5
|
const {
|
6
|
6
|
ControllerRegistry,
|
|
@@ -14,32 +14,24 @@ function startTabBasedApp(params) {
|
14
|
14
|
console.error('startTabBasedApp(params): params.tabs is required');
|
15
|
15
|
return;
|
16
|
16
|
}
|
17
|
|
- const appID = utils.getRandomId();
|
18
|
|
- const App = Controllers.createClass({
|
|
17
|
+ const controllerID = utils.getRandomId();
|
|
18
|
+ const Controller = Controllers.createClass({
|
19
|
19
|
render: function() {
|
20
|
20
|
return (
|
21
|
|
- <TabBarControllerIOS id={appID + '_tabs'}>
|
|
21
|
+ <TabBarControllerIOS id={controllerID + '_tabs'}>
|
22
|
22
|
{
|
23
|
23
|
params.tabs.map(function(tab, index) {
|
24
|
|
- const navigatorID = appID + '_nav' + index;
|
|
24
|
+ const navigatorID = controllerID + '_nav' + index;
|
25
|
25
|
if (!tab.screen) {
|
26
|
26
|
console.error('startTabBasedApp(params): every tab must include a screen property, take a look at tab#' + (index+1));
|
27
|
27
|
return;
|
28
|
28
|
}
|
29
|
|
- const screenClass = Navigation.getRegisteredScreen(tab.screen);
|
30
|
|
- if (!screenClass) {
|
31
|
|
- console.error('Cannot create screen ' + tab.screen + '. Are you it was registered with Navigation.registerScreen?');
|
32
|
|
- return;
|
33
|
|
- }
|
34
|
|
- const navigatorStyle = Object.assign({}, screenClass.navigatorStyle);
|
35
|
|
- if (tab.navigatorStyle) {
|
36
|
|
- Object.assign(navigatorStyle, tab.navigatorStyle);
|
37
|
|
- }
|
|
29
|
+ const { navigatorStyle } = _mergeScreenSpecificSettings(tab.screen, tab);
|
38
|
30
|
return (
|
39
|
|
- <TabBarControllerIOS.Item {...tab}>
|
|
31
|
+ <TabBarControllerIOS.Item {...tab} title={tab.label}>
|
40
|
32
|
<NavigationControllerIOS
|
41
|
33
|
id={navigatorID}
|
42
|
|
- title={tab.screenTitle}
|
|
34
|
+ title={tab.title}
|
43
|
35
|
component={tab.screen}
|
44
|
36
|
passProps={{navigatorID: navigatorID}}
|
45
|
37
|
style={navigatorStyle}
|
|
@@ -52,8 +44,8 @@ function startTabBasedApp(params) {
|
52
|
44
|
);
|
53
|
45
|
}
|
54
|
46
|
});
|
55
|
|
- ControllerRegistry.registerController(appID, () => App);
|
56
|
|
- ControllerRegistry.setRootController(appID);
|
|
47
|
+ ControllerRegistry.registerController(controllerID, () => Controller);
|
|
48
|
+ ControllerRegistry.setRootController(controllerID);
|
57
|
49
|
}
|
58
|
50
|
|
59
|
51
|
function startSingleScreenApp(params) {
|
|
@@ -61,28 +53,20 @@ function startSingleScreenApp(params) {
|
61
|
53
|
console.error('startSingleScreenApp(params): params.screen is required');
|
62
|
54
|
return;
|
63
|
55
|
}
|
64
|
|
- const appID = utils.getRandomId();
|
65
|
|
- const App = Controllers.createClass({
|
|
56
|
+ const controllerID = utils.getRandomId();
|
|
57
|
+ const Controller = Controllers.createClass({
|
66
|
58
|
render: function() {
|
67
|
59
|
const screen = params.screen;
|
68
|
|
- const navigatorID = appID + '_nav';
|
|
60
|
+ const navigatorID = controllerID + '_nav';
|
69
|
61
|
if (!screen.screen) {
|
70
|
62
|
console.error('startSingleScreenApp(params): screen must include a screen property');
|
71
|
63
|
return;
|
72
|
64
|
}
|
73
|
|
- const screenClass = Navigation.getRegisteredScreen(screen.screen);
|
74
|
|
- if (!screenClass) {
|
75
|
|
- console.error('Cannot create screen ' + screen.screen + '. Are you it was registered with Navigation.registerScreen?');
|
76
|
|
- return;
|
77
|
|
- }
|
78
|
|
- const navigatorStyle = Object.assign({}, screenClass.navigatorStyle);
|
79
|
|
- if (screen.navigatorStyle) {
|
80
|
|
- Object.assign(navigatorStyle, screen.navigatorStyle);
|
81
|
|
- }
|
|
65
|
+ const { navigatorStyle } = _mergeScreenSpecificSettings(screen.screen, screen);
|
82
|
66
|
return (
|
83
|
67
|
<NavigationControllerIOS
|
84
|
68
|
id={navigatorID}
|
85
|
|
- title={screen.screenTitle}
|
|
69
|
+ title={screen.title}
|
86
|
70
|
component={screen.screen}
|
87
|
71
|
passProps={{navigatorID: navigatorID}}
|
88
|
72
|
style={navigatorStyle}
|
|
@@ -90,25 +74,30 @@ function startSingleScreenApp(params) {
|
90
|
74
|
);
|
91
|
75
|
}
|
92
|
76
|
});
|
93
|
|
- ControllerRegistry.registerController(appID, () => App);
|
94
|
|
- ControllerRegistry.setRootController(appID);
|
|
77
|
+ ControllerRegistry.registerController(controllerID, () => Controller);
|
|
78
|
+ ControllerRegistry.setRootController(controllerID);
|
95
|
79
|
}
|
96
|
80
|
|
97
|
|
-function navigatorPush(navigator, params) {
|
98
|
|
- if (!params.screen) {
|
99
|
|
- console.error('Navigator.push(params): params.screen is required');
|
100
|
|
- return;
|
101
|
|
- }
|
102
|
|
- const passProps = params.passProps || {};
|
103
|
|
- const screenClass = Navigation.getRegisteredScreen(params.screen);
|
|
81
|
+function _mergeScreenSpecificSettings(screenID, params) {
|
|
82
|
+ const screenClass = Navigation.getRegisteredScreen(screenID);
|
104
|
83
|
if (!screenClass) {
|
105
|
|
- console.error('Cannot create screen ' + params.screen + '. Are you it was registered with Navigation.registerScreen?');
|
|
84
|
+ console.error('Cannot create screen ' + screenID + '. Are you it was registered with Navigation.registerScreen?');
|
106
|
85
|
return;
|
107
|
86
|
}
|
108
|
87
|
const navigatorStyle = Object.assign({}, screenClass.navigatorStyle);
|
109
|
88
|
if (params.navigatorStyle) {
|
110
|
89
|
Object.assign(navigatorStyle, params.navigatorStyle);
|
111
|
90
|
}
|
|
91
|
+ return { navigatorStyle };
|
|
92
|
+}
|
|
93
|
+
|
|
94
|
+function navigatorPush(navigator, params) {
|
|
95
|
+ if (!params.screen) {
|
|
96
|
+ console.error('Navigator.push(params): params.screen is required');
|
|
97
|
+ return;
|
|
98
|
+ }
|
|
99
|
+ const { navigatorStyle } = _mergeScreenSpecificSettings(params.screen, params);
|
|
100
|
+ const passProps = params.passProps || {};
|
112
|
101
|
passProps.navigatorID = navigator.navigatorID;
|
113
|
102
|
Controllers.NavigationControllerIOS(navigator.navigatorID).push({
|
114
|
103
|
title: params.title,
|
|
@@ -126,9 +115,41 @@ function navigatorPop(navigator, params) {
|
126
|
115
|
});
|
127
|
116
|
}
|
128
|
117
|
|
|
118
|
+function showModal(params) {
|
|
119
|
+ if (!params.screen) {
|
|
120
|
+ console.error('showModal(params): params.screen is required');
|
|
121
|
+ return;
|
|
122
|
+ }
|
|
123
|
+ const { navigatorStyle } = _mergeScreenSpecificSettings(params.screen, params);
|
|
124
|
+ const controllerID = utils.getRandomId();
|
|
125
|
+ const Controller = Controllers.createClass({
|
|
126
|
+ render: function() {
|
|
127
|
+ const navigatorID = controllerID + '_nav';
|
|
128
|
+ const { navigatorStyle } = _mergeScreenSpecificSettings(params.screen, params);
|
|
129
|
+ return (
|
|
130
|
+ <NavigationControllerIOS
|
|
131
|
+ id={navigatorID}
|
|
132
|
+ title={params.title}
|
|
133
|
+ component={params.screen}
|
|
134
|
+ passProps={{navigatorID: navigatorID}}
|
|
135
|
+ style={navigatorStyle}
|
|
136
|
+ />
|
|
137
|
+ );
|
|
138
|
+ }
|
|
139
|
+ });
|
|
140
|
+ ControllerRegistry.registerController(controllerID, () => Controller);
|
|
141
|
+ Modal.showController(controllerID, params.animationType);
|
|
142
|
+}
|
|
143
|
+
|
|
144
|
+function dismissModal(params) {
|
|
145
|
+ Modal.dismissController(params.animationType);
|
|
146
|
+}
|
|
147
|
+
|
129
|
148
|
export default platformSpecific = {
|
130
|
149
|
startTabBasedApp,
|
131
|
150
|
startSingleScreenApp,
|
132
|
151
|
navigatorPush,
|
133
|
|
- navigatorPop
|
|
152
|
+ navigatorPop,
|
|
153
|
+ showModal,
|
|
154
|
+ dismissModal
|
134
|
155
|
}
|