Browse Source

fixed passProps for iOS when starting app (tabs or single screen)

Artal Druk 8 years ago
parent
commit
88e8c90955
1 changed files with 56 additions and 31 deletions
  1. 56
    31
      src/deprecated/platformSpecificDeprecated.ios.js

+ 56
- 31
src/deprecated/platformSpecificDeprecated.ios.js View File

9
 } = React;
9
 } = React;
10
 import _ from 'lodash';
10
 import _ from 'lodash';
11
 
11
 
12
+import PropRegistry from '../PropRegistry';
13
+
12
 function startTabBasedApp(params) {
14
 function startTabBasedApp(params) {
13
   if (!params.tabs) {
15
   if (!params.tabs) {
14
     console.error('startTabBasedApp(params): params.tabs is required');
16
     console.error('startTabBasedApp(params): params.tabs is required');
15
     return;
17
     return;
16
   }
18
   }
19
+
20
+  params.tabs.map(function(tab, index) {
21
+    const navigatorID = controllerID + '_nav' + index;
22
+    const screenInstanceID = _.uniqueId('screenInstanceID');
23
+    if (!tab.screen) {
24
+      console.error('startTabBasedApp(params): every tab must include a screen property, take a look at tab#' + (index + 1));
25
+      return;
26
+    }
27
+    const {
28
+      navigatorStyle,
29
+      navigatorButtons,
30
+      navigatorEventID
31
+    } = _mergeScreenSpecificSettings(tab.screen, screenInstanceID, tab);
32
+    tab.navigationParams = {
33
+      screenInstanceID,
34
+      navigatorStyle,
35
+      navigatorButtons,
36
+      navigatorEventID,
37
+      navigatorID
38
+    };
39
+  });
40
+
17
   const controllerID = _.uniqueId('controllerID');
41
   const controllerID = _.uniqueId('controllerID');
18
   const Controller = Controllers.createClass({
42
   const Controller = Controllers.createClass({
19
     render: function() {
43
     render: function() {
43
           style={params.tabsStyle}>
67
           style={params.tabsStyle}>
44
           {
68
           {
45
             params.tabs.map(function(tab, index) {
69
             params.tabs.map(function(tab, index) {
46
-              const navigatorID = controllerID + '_nav' + index;
47
-              const screenInstanceID = _.uniqueId('screenInstanceID');
48
-              if (!tab.screen) {
49
-                console.error('startTabBasedApp(params): every tab must include a screen property, take a look at tab#' + (index + 1));
50
-                return;
51
-              }
52
-              const {
53
-                navigatorStyle,
54
-                navigatorButtons,
55
-                navigatorEventID
56
-              } = _mergeScreenSpecificSettings(tab.screen, screenInstanceID, tab);
57
               return (
70
               return (
58
                 <TabBarControllerIOS.Item {...tab} title={tab.label}>
71
                 <TabBarControllerIOS.Item {...tab} title={tab.label}>
59
                   <NavigationControllerIOS
72
                   <NavigationControllerIOS
60
-                    id={navigatorID}
73
+                    id={tab.navigationParams.navigatorID}
61
                     title={tab.title}
74
                     title={tab.title}
62
                     titleImage={tab.titleImage}
75
                     titleImage={tab.titleImage}
63
                     component={tab.screen}
76
                     component={tab.screen}
64
                     passProps={{
77
                     passProps={{
65
-                    navigatorID: navigatorID,
66
-                    screenInstanceID: screenInstanceID,
67
-                    navigatorEventID: navigatorEventID
78
+                    navigatorID: tab.navigationParams.navigatorID,
79
+                    screenInstanceID: tab.navigationParams.screenInstanceID,
80
+                    navigatorEventID: tab.navigationParams.navigatorEventID
68
                   }}
81
                   }}
69
-                    style={navigatorStyle}
70
-                    leftButtons={navigatorButtons.leftButtons}
71
-                    rightButtons={navigatorButtons.rightButtons}
82
+                    style={tab.navigationParams.navigatorStyle}
83
+                    leftButtons={tab.navigationParams.navigatorButtons.leftButtons}
84
+                    rightButtons={tab.navigationParams.navigatorButtons.rightButtons}
72
                   />
85
                   />
73
                 </TabBarControllerIOS.Item>
86
                 </TabBarControllerIOS.Item>
74
               );
87
               );
89
     console.error('startSingleScreenApp(params): params.screen is required');
102
     console.error('startSingleScreenApp(params): params.screen is required');
90
     return;
103
     return;
91
   }
104
   }
105
+
92
   const controllerID = _.uniqueId('controllerID');
106
   const controllerID = _.uniqueId('controllerID');
107
+  const screen = params.screen;
108
+  if (!screen.screen) {
109
+    console.error('startSingleScreenApp(params): screen must include a screen property');
110
+    return;
111
+  }
112
+
113
+  const navigatorID = controllerID + '_nav';
114
+  const screenInstanceID = _.uniqueId('screenInstanceID');
115
+  const {
116
+    navigatorStyle,
117
+    navigatorButtons,
118
+    navigatorEventID
119
+  } = _mergeScreenSpecificSettings(screen.screen, screenInstanceID, screen);
120
+  params.navigationParams = {
121
+    screenInstanceID,
122
+    navigatorStyle,
123
+    navigatorButtons,
124
+    navigatorEventID,
125
+    navigatorID
126
+  };
127
+
93
   const Controller = Controllers.createClass({
128
   const Controller = Controllers.createClass({
94
     render: function() {
129
     render: function() {
95
       if (!params.drawer || (!params.drawer.left && !params.drawer.right)) {
130
       if (!params.drawer || (!params.drawer.left && !params.drawer.right)) {
112
       }
147
       }
113
     },
148
     },
114
     renderBody: function() {
149
     renderBody: function() {
115
-      const screen = params.screen;
116
-      const navigatorID = controllerID + '_nav';
117
-      const screenInstanceID = _.uniqueId('screenInstanceID');
118
-      if (!screen.screen) {
119
-        console.error('startSingleScreenApp(params): screen must include a screen property');
120
-        return;
121
-      }
122
-      const {
123
-        navigatorStyle,
124
-        navigatorButtons,
125
-        navigatorEventID
126
-      } = _mergeScreenSpecificSettings(screen.screen, screenInstanceID, screen);
127
       return (
150
       return (
128
         <NavigationControllerIOS
151
         <NavigationControllerIOS
129
           id={navigatorID}
152
           id={navigatorID}
475
 
498
 
476
   if (params.tabs) {
499
   if (params.tabs) {
477
     _.forEach(params.tabs, (tab) => {
500
     _.forEach(params.tabs, (tab) => {
478
-      tab.passProps = params.passProps;
501
+      if(!tab.passProps) {
502
+        tab.passProps = params.passProps;
503
+      }
479
       savePassProps(tab);
504
       savePassProps(tab);
480
     });
505
     });
481
   }
506
   }