11import utils from './utils' ;
22import Navigation from './Navigation' ;
3- import Controllers from 'react-native-controllers' ;
3+ import Controllers , { Modal } from 'react-native-controllers' ;
44const React = Controllers . hijackReact ( ) ;
55const {
66 ControllerRegistry,
@@ -14,32 +14,24 @@ function startTabBasedApp(params) {
1414 console . error ( 'startTabBasedApp(params): params.tabs is required' ) ;
1515 return ;
1616 }
17- const appID = utils . getRandomId ( ) ;
18- const App = Controllers . createClass ( {
17+ const controllerID = utils . getRandomId ( ) ;
18+ const Controller = Controllers . createClass ( {
1919 render : function ( ) {
2020 return (
21- < TabBarControllerIOS id = { appID + '_tabs' } >
21+ < TabBarControllerIOS id = { controllerID + '_tabs' } >
2222 {
2323 params . tabs . map ( function ( tab , index ) {
24- const navigatorID = appID + '_nav' + index ;
24+ const navigatorID = controllerID + '_nav' + index ;
2525 if ( ! tab . screen ) {
2626 console . error ( 'startTabBasedApp(params): every tab must include a screen property, take a look at tab#' + ( index + 1 ) ) ;
2727 return ;
2828 }
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 ) ;
3830 return (
39- < TabBarControllerIOS . Item { ...tab } >
31+ < TabBarControllerIOS . Item { ...tab } title = { tab . label } >
4032 < NavigationControllerIOS
4133 id = { navigatorID }
42- title = { tab . screenTitle }
34+ title = { tab . title }
4335 component = { tab . screen }
4436 passProps = { { navigatorID : navigatorID } }
4537 style = { navigatorStyle }
@@ -52,63 +44,60 @@ function startTabBasedApp(params) {
5244 ) ;
5345 }
5446 } ) ;
55- ControllerRegistry . registerController ( appID , ( ) => App ) ;
56- ControllerRegistry . setRootController ( appID ) ;
47+ ControllerRegistry . registerController ( controllerID , ( ) => Controller ) ;
48+ ControllerRegistry . setRootController ( controllerID ) ;
5749}
5850
5951function startSingleScreenApp ( params ) {
6052 if ( ! params . screen ) {
6153 console . error ( 'startSingleScreenApp(params): params.screen is required' ) ;
6254 return ;
6355 }
64- const appID = utils . getRandomId ( ) ;
65- const App = Controllers . createClass ( {
56+ const controllerID = utils . getRandomId ( ) ;
57+ const Controller = Controllers . createClass ( {
6658 render : function ( ) {
6759 const screen = params . screen ;
68- const navigatorID = appID + '_nav' ;
60+ const navigatorID = controllerID + '_nav' ;
6961 if ( ! screen . screen ) {
7062 console . error ( 'startSingleScreenApp(params): screen must include a screen property' ) ;
7163 return ;
7264 }
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 ) ;
8266 return (
8367 < NavigationControllerIOS
8468 id = { navigatorID }
85- title = { screen . screenTitle }
69+ title = { screen . title }
8670 component = { screen . screen }
8771 passProps = { { navigatorID : navigatorID } }
8872 style = { navigatorStyle }
8973 />
9074 ) ;
9175 }
9276 } ) ;
93- ControllerRegistry . registerController ( appID , ( ) => App ) ;
94- ControllerRegistry . setRootController ( appID ) ;
77+ ControllerRegistry . registerController ( controllerID , ( ) => Controller ) ;
78+ ControllerRegistry . setRootController ( controllerID ) ;
9579}
9680
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 ) ;
10483 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?' ) ;
10685 return ;
10786 }
10887 const navigatorStyle = Object . assign ( { } , screenClass . navigatorStyle ) ;
10988 if ( params . navigatorStyle ) {
11089 Object . assign ( navigatorStyle , params . navigatorStyle ) ;
11190 }
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 || { } ;
112101 passProps . navigatorID = navigator . navigatorID ;
113102 Controllers . NavigationControllerIOS ( navigator . navigatorID ) . push ( {
114103 title : params . title ,
@@ -126,9 +115,41 @@ function navigatorPop(navigator, params) {
126115 } ) ;
127116}
128117
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+
129148export default platformSpecific = {
130149 startTabBasedApp,
131150 startSingleScreenApp,
132151 navigatorPush,
133- navigatorPop
152+ navigatorPop,
153+ showModal,
154+ dismissModal
134155}
0 commit comments