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,11 +9,35 @@ const {
9 9
 } = React;
10 10
 import _ from 'lodash';
11 11
 
12
+import PropRegistry from '../PropRegistry';
13
+
12 14
 function startTabBasedApp(params) {
13 15
   if (!params.tabs) {
14 16
     console.error('startTabBasedApp(params): params.tabs is required');
15 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 41
   const controllerID = _.uniqueId('controllerID');
18 42
   const Controller = Controllers.createClass({
19 43
     render: function() {
@@ -43,32 +67,21 @@ function startTabBasedApp(params) {
43 67
           style={params.tabsStyle}>
44 68
           {
45 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 70
               return (
58 71
                 <TabBarControllerIOS.Item {...tab} title={tab.label}>
59 72
                   <NavigationControllerIOS
60
-                    id={navigatorID}
73
+                    id={tab.navigationParams.navigatorID}
61 74
                     title={tab.title}
62 75
                     titleImage={tab.titleImage}
63 76
                     component={tab.screen}
64 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 86
                 </TabBarControllerIOS.Item>
74 87
               );
@@ -89,7 +102,29 @@ function startSingleScreenApp(params) {
89 102
     console.error('startSingleScreenApp(params): params.screen is required');
90 103
     return;
91 104
   }
105
+
92 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 128
   const Controller = Controllers.createClass({
94 129
     render: function() {
95 130
       if (!params.drawer || (!params.drawer.left && !params.drawer.right)) {
@@ -112,18 +147,6 @@ function startSingleScreenApp(params) {
112 147
       }
113 148
     },
114 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 150
       return (
128 151
         <NavigationControllerIOS
129 152
           id={navigatorID}
@@ -475,7 +498,9 @@ function savePassProps(params) {
475 498
 
476 499
   if (params.tabs) {
477 500
     _.forEach(params.tabs, (tab) => {
478
-      tab.passProps = params.passProps;
501
+      if(!tab.passProps) {
502
+        tab.passProps = params.passProps;
503
+      }
479 504
       savePassProps(tab);
480 505
     });
481 506
   }