Daniel Zlotin 7 lat temu
rodzic
commit
66afbb4f06

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactInitializer.java Wyświetl plik

@@ -20,6 +20,7 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
20 20
 	}
21 21
 
22 22
 	public void onActivityCreated(NavigationActivity activity) {
23
+		reactInstanceManager.addReactInstanceEventListener(this);
23 24
 		waitingForAppLaunchEvent = true;
24 25
 	}
25 26
 
@@ -28,7 +29,6 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
28 29
 			devPermissionRequest.askPermission(activity);
29 30
 		} else {
30 31
 			reactInstanceManager.onHostResume(activity, activity);
31
-			reactInstanceManager.addReactInstanceEventListener(this);
32 32
 			checkBundleThenPrepareReact(activity);
33 33
 		}
34 34
 	}

+ 30
- 28
lib/src/containers/ContainerWrapper.test.js Wyświetl plik

@@ -7,15 +7,12 @@ import ContainerWrapper from './ContainerWrapper';
7 7
 import Store from './Store';
8 8
 
9 9
 describe('ContainerWrapper', () => {
10
-  let myContainerRef;
11
-  let testParentRef;
12 10
   let store;
13 11
   const containerName = 'example.MyContainer';
14 12
 
15 13
   class MyContainer extends Component {
16 14
     constructor(props) {
17 15
       super(props);
18
-      myContainerRef = this;
19 16
     }
20 17
 
21 18
     render() {
@@ -26,7 +23,6 @@ describe('ContainerWrapper', () => {
26 23
   class TestParent extends Component {
27 24
     constructor(props) {
28 25
       super(props);
29
-      testParentRef = this;
30 26
       this.ChildClass = props.ChildClass;
31 27
       this.state = { propsFromState: {} };
32 28
     }
@@ -34,7 +30,11 @@ describe('ContainerWrapper', () => {
34 30
     render() {
35 31
       const Child = this.ChildClass;
36 32
       return (
37
-        <Child containerId="container1" {...this.state.propsFromState} />
33
+        <Child
34
+          ref="child"
35
+          containerId="container1"
36
+          {...this.state.propsFromState}
37
+        />
38 38
       );
39 39
     }
40 40
   }
@@ -58,54 +58,55 @@ describe('ContainerWrapper', () => {
58 58
     expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
59 59
     const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
60 60
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
61
-    expect(myContainerRef).toBeInstanceOf(MyContainer);
61
+    expect(tree.getInstance().originalContainerRef).toBeInstanceOf(MyContainer);
62 62
   });
63 63
 
64 64
   it('injects props from wrapper into original container', () => {
65 65
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
66
-    renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'} />);
67
-    expect(myContainerRef.props.myProp).toEqual('yo');
66
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'} />);
67
+    expect(tree.getInstance().originalContainerRef.props.myProp).toEqual('yo');
68 68
   });
69 69
 
70 70
   it('updates props from wrapper into original container', () => {
71 71
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
72
-    renderer.create(<TestParent ChildClass={NavigationContainer} />);
73
-    expect(myContainerRef.props.foo).toEqual(undefined);
74
-    testParentRef.setState({ propsFromState: { foo: 'yo' } });
75
-    expect(myContainerRef.props.foo).toEqual('yo');
72
+    const tree = renderer.create(<TestParent ChildClass={NavigationContainer} />);
73
+    expect(tree.getInstance().refs.child.props.foo).toEqual(undefined);
74
+    tree.getInstance().setState({ propsFromState: { foo: 'yo' } });
75
+    expect(tree.getInstance().refs.child.props.foo).toEqual('yo');
76 76
   });
77 77
 
78 78
   it('pulls props from the store and injects them into the inner container', () => {
79 79
     store.setPropsForContainerId('container123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
80 80
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
81
-    renderer.create(<NavigationContainer containerId={'container123'} />);
82
-    expect(myContainerRef.props).toEqual({ containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
81
+    const tree = renderer.create(<NavigationContainer containerId={'container123'} />);
82
+    originalContainerProps = tree.getInstance().originalContainerRef.props;
83
+    expect(originalContainerProps).toEqual({ containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
83 84
   });
84 85
 
85 86
   it('updates props from store into inner container', () => {
86 87
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
87
-    renderer.create(<TestParent ChildClass={NavigationContainer} />);
88
+    const tree = renderer.create(<TestParent ChildClass={NavigationContainer} />);
88 89
     store.setPropsForContainerId('container1', { myProp: 'hello' });
89
-    expect(myContainerRef.props.foo).toEqual(undefined);
90
-    expect(myContainerRef.props.myProp).toEqual(undefined);
91
-    testParentRef.setState({ propsFromState: { foo: 'yo' } });
92
-    expect(myContainerRef.props.foo).toEqual('yo');
93
-    expect(myContainerRef.props.myProp).toEqual('hello');
90
+    expect(tree.getInstance().refs.child.originalContainerRef.props.foo).toEqual(undefined);
91
+    expect(tree.getInstance().refs.child.originalContainerRef.props.myProp).toEqual(undefined);
92
+    tree.getInstance().setState({ propsFromState: { foo: 'yo' } });
93
+    expect(tree.getInstance().refs.child.originalContainerRef.props.foo).toEqual('yo');
94
+    expect(tree.getInstance().refs.child.originalContainerRef.props.myProp).toEqual('hello');
94 95
   });
95 96
 
96 97
   it('protects id from change', () => {
97 98
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
98
-    renderer.create(<TestParent ChildClass={NavigationContainer} />);
99
-    expect(myContainerRef.props.containerId).toEqual('container1');
100
-    testParentRef.setState({ propsFromState: { id: 'ERROR' } });
101
-    expect(myContainerRef.props.containerId).toEqual('container1');
99
+    const tree = renderer.create(<TestParent ChildClass={NavigationContainer} />);
100
+    expect(tree.getInstance().refs.child.originalContainerRef.props.containerId).toEqual('container1');
101
+    tree.getInstance().setState({ propsFromState: { id: 'ERROR' } });
102
+    expect(tree.getInstance().refs.child.originalContainerRef.props.containerId).toEqual('container1');
102 103
   });
103 104
 
104 105
   it('assignes key by id', () => {
105 106
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
106
-    renderer.create(<NavigationContainer containerId={'container1'} />);
107
-    expect(myContainerRef.props.containerId).toEqual('container1');
108
-    expect(myContainerRef._reactInternalInstance.key).toEqual('container1');
107
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
108
+    expect(tree.getInstance().originalContainerRef.props.containerId).toEqual('container1');
109
+    expect(tree.getInstance().originalContainerRef._reactInternalInstance.key).toEqual('container1');
109 110
   });
110 111
 
111 112
   it('saves self ref into store', () => {
@@ -126,7 +127,8 @@ describe('ContainerWrapper', () => {
126 127
   it('holds ref to OriginalContainer', () => {
127 128
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
128 129
     const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
129
-    expect(tree.getInstance().originalContainerRef).toBe(myContainerRef);
130
+    expect(tree.getInstance().originalContainerRef).toBeDefined();
131
+    expect(tree.getInstance().originalContainerRef).toBeInstanceOf(MyContainer);
130 132
   });
131 133
 
132 134
   it('cleans ref to internal container on unount', () => {