Преглед на файлове

Merge pull request #210 from wix/register_component_props_fix

Fix for register components not updating props
DanielZlotin преди 8 години
родител
ревизия
c5a010f48d
променени са 1 файла, в които са добавени 20 реда и са изтрити 4 реда
  1. 20
    4
      src/Navigation.js

+ 20
- 4
src/Navigation.js Целия файл

@@ -29,12 +29,20 @@ function _registerComponentNoRedux(screenID, generator) {
29 29
 
30 30
       constructor(props) {
31 31
         super(props);
32
-        this.allProps = {...props, ...PropRegistry.load(props.screenInstanceID)};
32
+        this.state = {
33
+          internalProps: {...props, ...PropRegistry.load(props.screenInstanceID)}
34
+        }
35
+      }
36
+  
37
+      componentWillReceiveProps(nextProps) {
38
+        this.setState({
39
+          internalProps: {...PropRegistry.load(this.props.screenInstanceID), ...nextProps}
40
+        })
33 41
       }
34 42
 
35 43
       render() {
36 44
         return (
37
-          <InternalComponent navigator={this.navigator} {...this.allProps} />
45
+          <InternalComponent navigator={this.navigator} {...this.state.internalProps} />
38 46
         );
39 47
       }
40 48
     };
@@ -52,13 +60,21 @@ function _registerComponentRedux(screenID, generator, store, Provider) {
52 60
 
53 61
       constructor(props) {
54 62
         super(props);
55
-        this.allProps = {...props, ...PropRegistry.load(props.screenInstanceID)};
63
+        this.state = {
64
+          internalProps: {...props, ...PropRegistry.load(props.screenInstanceID)}
65
+        }
66
+      }
67
+      
68
+      componentWillReceiveProps(nextProps) {
69
+        this.setState({
70
+          internalProps: {...PropRegistry.load(this.props.screenInstanceID), ...nextProps}
71
+        })
56 72
       }
57 73
 
58 74
       render() {
59 75
         return (
60 76
           <Provider store={store}>
61
-            <InternalComponent navigator={this.navigator} {...this.allProps} />
77
+            <InternalComponent navigator={this.navigator} {...this.state.internalProps} />
62 78
           </Provider>
63 79
         );
64 80
       }