瀏覽代碼

Don't custom button props over the bridge (#2174)

This fix allows to pass unserializable props to custom buttons, such as navigator or functions.
Guy Carmeli 7 年之前
父節點
當前提交
e69f3801b9
No account linked to committer's email address
共有 2 個檔案被更改,包括 8 行新增2 行删除
  1. 2
    2
      src/Navigation.js
  2. 6
    0
      src/deprecated/platformSpecificDeprecated.android.js

+ 2
- 2
src/Navigation.js 查看文件

@@ -36,13 +36,13 @@ function _registerComponentNoRedux(screenID, generator) {
36 36
       constructor(props) {
37 37
         super(props);
38 38
         this.state = {
39
-          internalProps: {...props, ...PropRegistry.load(props.screenInstanceID)}
39
+          internalProps: {...props, ...PropRegistry.load(props.screenInstanceID || props.passPropsKey)}
40 40
         }
41 41
       }
42 42
 
43 43
       componentWillReceiveProps(nextProps) {
44 44
         this.setState({
45
-          internalProps: {...PropRegistry.load(this.props.screenInstanceID), ...nextProps}
45
+          internalProps: {...PropRegistry.load(this.props.screenInstanceID || props.passPropsKey), ...nextProps}
46 46
         })
47 47
       }
48 48
 

+ 6
- 0
src/deprecated/platformSpecificDeprecated.android.js 查看文件

@@ -2,6 +2,7 @@
2 2
 import React, {Component} from 'react';
3 3
 import ReactNative, {AppRegistry, NativeModules, processColor} from 'react-native';
4 4
 import _ from 'lodash';
5
+import PropRegistry from './../PropRegistry';
5 6
 
6 7
 import Navigation from './../Navigation';
7 8
 
@@ -331,6 +332,11 @@ function navigatorSetButtons(navigator, navigatorEventID, _params) {
331 332
       if (button.buttonColor) {
332 333
         button.color = processColor(button.buttonColor);
333 334
       }
335
+      if (button.component) {
336
+        const passPropsKey = _.uniqueId('customButtonComponent');
337
+        PropRegistry.save(passPropsKey, button.passProps);
338
+        button.passProps = {passPropsKey};
339
+      }
334 340
     });
335 341
   }
336 342
   let leftButton = getLeftButton(params);