Daniel Zlotin vor 7 Jahren
Ursprung
Commit
66afbb4f06

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactInitializer.java Datei anzeigen

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

+ 30
- 28
lib/src/containers/ContainerWrapper.test.js Datei anzeigen

7
 import Store from './Store';
7
 import Store from './Store';
8
 
8
 
9
 describe('ContainerWrapper', () => {
9
 describe('ContainerWrapper', () => {
10
-  let myContainerRef;
11
-  let testParentRef;
12
   let store;
10
   let store;
13
   const containerName = 'example.MyContainer';
11
   const containerName = 'example.MyContainer';
14
 
12
 
15
   class MyContainer extends Component {
13
   class MyContainer extends Component {
16
     constructor(props) {
14
     constructor(props) {
17
       super(props);
15
       super(props);
18
-      myContainerRef = this;
19
     }
16
     }
20
 
17
 
21
     render() {
18
     render() {
26
   class TestParent extends Component {
23
   class TestParent extends Component {
27
     constructor(props) {
24
     constructor(props) {
28
       super(props);
25
       super(props);
29
-      testParentRef = this;
30
       this.ChildClass = props.ChildClass;
26
       this.ChildClass = props.ChildClass;
31
       this.state = { propsFromState: {} };
27
       this.state = { propsFromState: {} };
32
     }
28
     }
34
     render() {
30
     render() {
35
       const Child = this.ChildClass;
31
       const Child = this.ChildClass;
36
       return (
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
     expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
58
     expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
59
     const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
59
     const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
60
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
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
   it('injects props from wrapper into original container', () => {
64
   it('injects props from wrapper into original container', () => {
65
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
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
   it('updates props from wrapper into original container', () => {
70
   it('updates props from wrapper into original container', () => {
71
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
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
   it('pulls props from the store and injects them into the inner container', () => {
78
   it('pulls props from the store and injects them into the inner container', () => {
79
     store.setPropsForContainerId('container123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
79
     store.setPropsForContainerId('container123', { numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
80
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
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
   it('updates props from store into inner container', () => {
86
   it('updates props from store into inner container', () => {
86
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
87
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
87
-    renderer.create(<TestParent ChildClass={NavigationContainer} />);
88
+    const tree = renderer.create(<TestParent ChildClass={NavigationContainer} />);
88
     store.setPropsForContainerId('container1', { myProp: 'hello' });
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
   it('protects id from change', () => {
97
   it('protects id from change', () => {
97
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
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
   it('assignes key by id', () => {
105
   it('assignes key by id', () => {
105
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
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
   it('saves self ref into store', () => {
112
   it('saves self ref into store', () => {
126
   it('holds ref to OriginalContainer', () => {
127
   it('holds ref to OriginalContainer', () => {
127
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
128
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
128
     const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
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
   it('cleans ref to internal container on unount', () => {
134
   it('cleans ref to internal container on unount', () => {