Procházet zdrojové kódy

passProps android working

Daniel Zlotin před 8 roky
rodič
revize
d52ed003bf

+ 1
- 1
example-redux/package.json Zobrazit soubor

@@ -3,7 +3,7 @@
3 3
   "version": "0.0.1",
4 4
   "private": true,
5 5
   "scripts": {
6
-    "start": "watchman watch-del-all && node node_modules/react-native/local-cli/cli.js start --reset-cache"
6
+    "start": "node node_modules/react-native/local-cli/cli.js start"
7 7
   },
8 8
   "dependencies": {
9 9
     "react-native": "0.25.1",

+ 3
- 3
example-redux/src/app.js Zobrazit soubor

@@ -74,9 +74,9 @@ export default class App {
74 74
         //      {
75 75
         //        screenId: 'example.ListScreen',
76 76
         //        title: 'Tab1',
77
-        //         passProps: {
78
-        //           str: 'This is a prop passed to Tab1'
79
-        //         }
77
+        //        passProps: {
78
+        //          str: 'This is a prop passed to Tab1'
79
+        //        }
80 80
         //      },
81 81
         //      {
82 82
         //        screenId: 'example.PushedScreen',

+ 1
- 1
src/PropRegistry.js Zobrazit soubor

@@ -3,7 +3,7 @@ class PropRegistry {
3 3
     this.registry = {};
4 4
   }
5 5
 
6
-  save(screenInstanceId, passProps) {
6
+  save(screenInstanceId = '', passProps = {}) {
7 7
     this.registry[screenInstanceId] = passProps;
8 8
   }
9 9
 

+ 29
- 5
src/platformSpecific.android.js Zobrazit soubor

@@ -1,17 +1,17 @@
1 1
 import React, {Component} from 'react';
2 2
 import {AppRegistry, NativeModules} from 'react-native';
3
-
3
+import _ from 'lodash';
4 4
 import PropRegistry from './PropRegistry';
5 5
 
6 6
 const NativeReactModule = NativeModules.NavigationReactModule;
7 7
 
8 8
 function startApp(activityParams) {
9
-  PropRegistry.save(activityParams.screen.navigationParams.screenInstanceID, activityParams.screen.passProps);
9
+  savePassProps(activityParams);
10 10
   NativeReactModule.startApp(activityParams);
11 11
 }
12 12
 
13 13
 function push(screenParams) {
14
-  PropRegistry.save(screenParams.navigationParams.screenInstanceID, screenParams.passProps);
14
+  savePassProps(screenParams);
15 15
   NativeReactModule.push(screenParams);
16 16
 }
17 17
 
@@ -24,7 +24,7 @@ function popToRoot(screenParams) {
24 24
 }
25 25
 
26 26
 function newStack(screenParams) {
27
-  PropRegistry.save(screenParams.navigationParams.screenInstanceID, screenParams.passProps);
27
+  savePassProps(screenParams);
28 28
   NativeReactModule.newStack(screenParams);
29 29
 }
30 30
 
@@ -45,7 +45,7 @@ function setScreenTitleBarButtons(screenInstanceID, navigatorEventID, rightButto
45 45
 }
46 46
 
47 47
 function showModal(screenParams) {
48
-  PropRegistry.save(screenParams.navigationParams.screenInstanceID, screenParams.passProps);
48
+  savePassProps(screenParams);
49 49
   NativeReactModule.showModal(screenParams);
50 50
 }
51 51
 
@@ -57,6 +57,30 @@ function dismissAllModals() {
57 57
   NativeReactModule.dismissAllModals();
58 58
 }
59 59
 
60
+function savePassProps(params) {
61
+  //TODO this needs to be handled in a common place,
62
+  //TODO also, all global passProps should be handled differently
63
+  //TODO also, topTabs passProps not working
64
+  if (params.navigationParams && params.passProps) {
65
+    PropRegistry.save(params.navigationParams.screenInstanceID, params.passProps);
66
+  }
67
+
68
+  if (params.screen && params.screen.passProps) {
69
+    PropRegistry.save(params.screen.navigationParams.screenInstanceID, params.screen.passProps);
70
+  }
71
+
72
+  if (_.get(params, 'screen.topTabs')) {
73
+    _.forEach(params.screen.topTabs, (tab) => savePassProps(tab));
74
+  }
75
+
76
+  if (params.tabs) {
77
+    _.forEach(params.tabs, (tab) => {
78
+      tab.passProps = params.passProps;
79
+      savePassProps(tab);
80
+    });
81
+  }
82
+}
83
+
60 84
 module.exports = {
61 85
   startApp,
62 86
   push,