Pārlūkot izejas kodu

changed this.props.id to this.props.containerId (#1327)

* changed this.props.id to this.props.containerId

* fixed js tests

* refactor
bogobogo 7 gadus atpakaļ
vecāks
revīzija
6b0ce5ba90

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/layout/ReactRootViewController.java Parādīt failu

@@ -60,7 +60,7 @@ public class ReactRootViewController extends ViewController {
60 60
 	protected View createView() {
61 61
 		reactRootView = new ReactRootView(getActivity());
62 62
 		Bundle opts = new Bundle();
63
-		opts.putString("id", getId());
63
+		opts.putString("containerId", getId());
64 64
 		reactRootView.startReactApplication(this.reactInstanceManager, this.name, opts);
65 65
 		reactRootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
66 66
 			@Override

+ 1
- 1
lib/ios/RNNReactRootViewCreator.m Parādīt failu

@@ -30,7 +30,7 @@
30 30
 	
31 31
 	UIView *view = [[RNNReactRootView alloc] initWithBridge:_bridge
32 32
 										 moduleName:name
33
-								  initialProperties:@{@"id": rootViewId}];
33
+								  initialProperties:@{@"containerId": rootViewId}];
34 34
 	return view;
35 35
 }
36 36
 

+ 1
- 1
lib/src/containers/ContainerRegistry.test.js Parādīt failu

@@ -40,7 +40,7 @@ describe('ContainerRegistry', () => {
40 40
   it('resulting in a normal component', () => {
41 41
     uut.registerContainer('example.MyContainer.name', () => MyContainer);
42 42
     const Container = AppRegistry.registerComponent.mock.calls[0][1]();
43
-    const tree = renderer.create(<Container id="123" />);
43
+    const tree = renderer.create(<Container containerId="123" />);
44 44
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
45 45
   });
46 46
 });

+ 11
- 11
lib/src/containers/ContainerWrapper.js Parādīt failu

@@ -7,20 +7,20 @@ export default class ContainerWrapper {
7 7
       constructor(props) {
8 8
         super(props);
9 9
         this._saveContainerRef = this._saveContainerRef.bind(this);
10
-        this._assertId(props);
10
+        this._assertContainerId(props);
11 11
         this._createState(props);
12 12
       }
13 13
 
14
-      _assertId(props) {
15
-        if (!props.id) {
16
-          throw new Error(`Container ${containerName} does not have an id!`);
14
+      _assertContainerId(props) {
15
+        if (!props.containerId) {
16
+          throw new Error(`Container ${containerName} does not have a containerId!`);
17 17
         }
18 18
       }
19 19
 
20 20
       _createState(props) {
21 21
         this.state = {
22
-          id: props.id,
23
-          allProps: _.merge({}, props, store.getPropsForContainerId(props.id))
22
+          containerId: props.containerId,
23
+          allProps: _.merge({}, props, store.getPropsForContainerId(props.containerId))
24 24
         };
25 25
       }
26 26
 
@@ -29,11 +29,11 @@ export default class ContainerWrapper {
29 29
       }
30 30
 
31 31
       componentWillMount() {
32
-        store.setRefForId(this.state.id, this);
32
+        store.setRefForContainerId(this.state.containerId, this);
33 33
       }
34 34
 
35 35
       componentWillUnmount() {
36
-        store.cleanId(this.state.id);
36
+        store.cleanId(this.state.containerId);
37 37
       }
38 38
 
39 39
       onStart() {
@@ -50,7 +50,7 @@ export default class ContainerWrapper {
50 50
 
51 51
       componentWillReceiveProps(nextProps) {
52 52
         this.setState({
53
-          allProps: _.merge({}, nextProps, store.getPropsForContainerId(this.state.id))
53
+          allProps: _.merge({}, nextProps, store.getPropsForContainerId(this.state.containerId))
54 54
         });
55 55
       }
56 56
 
@@ -59,8 +59,8 @@ export default class ContainerWrapper {
59 59
           <OriginalContainer
60 60
             ref={this._saveContainerRef}
61 61
             {...this.state.allProps}
62
-            id={this.state.id}
63
-            key={this.state.id}
62
+            containerId={this.state.containerId}
63
+            key={this.state.containerId}
64 64
           />
65 65
         );
66 66
       }

+ 22
- 22
lib/src/containers/ContainerWrapper.test.js Parādīt failu

@@ -34,7 +34,7 @@ describe('ContainerWrapper', () => {
34 34
     render() {
35 35
       const Child = this.ChildClass;
36 36
       return (
37
-        <Child id="container1" {...this.state.propsFromState} />
37
+        <Child containerId="container1" {...this.state.propsFromState} />
38 38
       );
39 39
     }
40 40
   }
@@ -43,27 +43,27 @@ describe('ContainerWrapper', () => {
43 43
     store = new Store();
44 44
   });
45 45
 
46
-  it('must have id as prop', () => {
46
+  it('must have containerId as prop', () => {
47 47
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
48 48
     const orig = console.error; //eslint-disable-line
49 49
     console.error = (a) => a; //eslint-disable-line
50 50
     expect(() => {
51 51
       renderer.create(<NavigationContainer />);
52
-    }).toThrow(new Error('Container example.MyContainer does not have an id!'));
52
+    }).toThrow(new Error('Container example.MyContainer does not have a containerId!'));
53 53
     console.error = orig; //eslint-disable-line
54 54
   });
55 55
 
56 56
   it('wraps the container', () => {
57 57
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
58 58
     expect(NavigationContainer).not.toBeInstanceOf(MyContainer);
59
-    const tree = renderer.create(<NavigationContainer id={'container1'} />);
59
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
60 60
     expect(tree.toJSON().children).toEqual(['Hello, World!']);
61 61
     expect(myContainerRef).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 id={'container1'} myProp={'yo'} />);
66
+    renderer.create(<NavigationContainer containerId={'container1'} myProp={'yo'} />);
67 67
     expect(myContainerRef.props.myProp).toEqual('yo');
68 68
   });
69 69
 
@@ -78,8 +78,8 @@ describe('ContainerWrapper', () => {
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 id={'container123'} />);
82
-    expect(myContainerRef.props).toEqual({ id: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
81
+    renderer.create(<NavigationContainer containerId={'container123'} />);
82
+    expect(myContainerRef.props).toEqual({ containerId: 'container123', numberProp: 1, stringProp: 'hello', objectProp: { a: 2 } });
83 83
   });
84 84
 
85 85
   it('updates props from store into inner container', () => {
@@ -96,42 +96,42 @@ describe('ContainerWrapper', () => {
96 96
   it('protects id from change', () => {
97 97
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
98 98
     renderer.create(<TestParent ChildClass={NavigationContainer} />);
99
-    expect(myContainerRef.props.id).toEqual('container1');
99
+    expect(myContainerRef.props.containerId).toEqual('container1');
100 100
     testParentRef.setState({ propsFromState: { id: 'ERROR' } });
101
-    expect(myContainerRef.props.id).toEqual('container1');
101
+    expect(myContainerRef.props.containerId).toEqual('container1');
102 102
   });
103 103
 
104 104
   it('assignes key by id', () => {
105 105
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
106
-    renderer.create(<NavigationContainer id={'container1'} />);
107
-    expect(myContainerRef.props.id).toEqual('container1');
106
+    renderer.create(<NavigationContainer containerId={'container1'} />);
107
+    expect(myContainerRef.props.containerId).toEqual('container1');
108 108
     expect(myContainerRef._reactInternalInstance.key).toEqual('container1');
109 109
   });
110 110
 
111 111
   it('saves self ref into store', () => {
112 112
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
113
-    const tree = renderer.create(<NavigationContainer id={'container1'} />);
114
-    expect(store.getRefForId('container1')).toBeDefined();
115
-    expect(store.getRefForId('container1')).toBe(tree.getInstance());
113
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
114
+    expect(store.getRefForContainerId('container1')).toBeDefined();
115
+    expect(store.getRefForContainerId('container1')).toBe(tree.getInstance());
116 116
   });
117 117
 
118 118
   it('cleans ref from store on unMount', () => {
119 119
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
120
-    const tree = renderer.create(<NavigationContainer id={'container1'} />);
121
-    expect(store.getRefForId('container1')).toBeDefined();
120
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
121
+    expect(store.getRefForContainerId('container1')).toBeDefined();
122 122
     tree.unmount();
123
-    expect(store.getRefForId('container1')).toBeUndefined();
123
+    expect(store.getRefForContainerId('container1')).toBeUndefined();
124 124
   });
125 125
 
126 126
   it('holds ref to OriginalContainer', () => {
127 127
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
128
-    const tree = renderer.create(<NavigationContainer id={'container1'} />);
128
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
129 129
     expect(tree.getInstance().originalContainerRef).toBe(myContainerRef);
130 130
   });
131 131
 
132 132
   it('cleans ref to internal container on unount', () => {
133 133
     const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
134
-    const tree = renderer.create(<NavigationContainer id={'container1'} />);
134
+    const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
135 135
     const instance = tree.getInstance();
136 136
     expect(instance.originalContainerRef).toBeInstanceOf(Component);
137 137
     tree.unmount();
@@ -154,14 +154,14 @@ describe('ContainerWrapper', () => {
154 154
 
155 155
     it('onStart and onStop are optional', () => {
156 156
       const NavigationContainer = ContainerWrapper.wrap(containerName, MyContainer, store);
157
-      const tree = renderer.create(<NavigationContainer id={'container1'} />);
157
+      const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
158 158
       expect(() => tree.getInstance().onStart()).not.toThrow();
159 159
       expect(() => tree.getInstance().onStop()).not.toThrow();
160 160
     });
161 161
 
162 162
     it('calls onStart on OriginalContainer', () => {
163 163
       const NavigationContainer = ContainerWrapper.wrap(containerName, MyLifecycleContainer, store);
164
-      const tree = renderer.create(<NavigationContainer id={'container1'} />);
164
+      const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
165 165
       expect(onStartCallback).toHaveBeenCalledTimes(0);
166 166
       tree.getInstance().onStart();
167 167
       expect(onStartCallback).toHaveBeenCalledTimes(1);
@@ -169,7 +169,7 @@ describe('ContainerWrapper', () => {
169 169
 
170 170
     it('calls onSop on OriginalContainer', () => {
171 171
       const NavigationContainer = ContainerWrapper.wrap(containerName, MyLifecycleContainer, store);
172
-      const tree = renderer.create(<NavigationContainer id={'container1'} />);
172
+      const tree = renderer.create(<NavigationContainer containerId={'container1'} />);
173 173
       expect(onStopCallback).toHaveBeenCalledTimes(0);
174 174
       tree.getInstance().onStop();
175 175
       expect(onStopCallback).toHaveBeenCalledTimes(1);

+ 2
- 2
lib/src/containers/Lifecycle.js Parādīt failu

@@ -6,14 +6,14 @@ export default class Lifecycle {
6 6
   }
7 7
 
8 8
   containerStart(id) {
9
-    const ref = this.store.getRefForId(id);
9
+    const ref = this.store.getRefForContainerId(id);
10 10
     if (ref && ref.onStart) {
11 11
       ref.onStart();
12 12
     }
13 13
   }
14 14
 
15 15
   containerStop(id) {
16
-    const ref = this.store.getRefForId(id);
16
+    const ref = this.store.getRefForContainerId(id);
17 17
     if (ref && ref.onStop) {
18 18
       ref.onStop();
19 19
     }

+ 3
- 3
lib/src/containers/Lifecycle.test.js Parādīt failu

@@ -11,7 +11,7 @@ describe('Lifecycle', () => {
11 11
       onStop: jest.fn()
12 12
     };
13 13
     store = new Store();
14
-    store.setRefForId('myUniqueId', mockRef);
14
+    store.setRefForContainerId('myUniqueId', mockRef);
15 15
 
16 16
     uut = new Lifecycle(store);
17 17
   });
@@ -30,7 +30,7 @@ describe('Lifecycle', () => {
30 30
     it('skips unimplemented onStart', () => {
31 31
       mockRef = {};
32 32
       expect(mockRef.onStart).toBeUndefined();
33
-      store.setRefForId('myUniqueId', mockRef);
33
+      store.setRefForContainerId('myUniqueId', mockRef);
34 34
       uut.containerStart('myUniqueId');
35 35
     });
36 36
   });
@@ -49,7 +49,7 @@ describe('Lifecycle', () => {
49 49
     it('skips unimplemented onStop', () => {
50 50
       mockRef = {};
51 51
       expect(mockRef.onStop).toBeUndefined();
52
-      store.setRefForId('myUniqueId', mockRef);
52
+      store.setRefForContainerId('myUniqueId', mockRef);
53 53
       uut.containerStop('myUniqueId');
54 54
     });
55 55
   });

+ 2
- 2
lib/src/containers/Store.js Parādīt failu

@@ -23,11 +23,11 @@ export default class Store {
23 23
     return _.get(this.containersByName, containerName);
24 24
   }
25 25
 
26
-  setRefForId(id, ref) {
26
+  setRefForContainerId(id, ref) {
27 27
     _.set(this.refsById, id, ref);
28 28
   }
29 29
 
30
-  getRefForId(id) {
30
+  getRefForContainerId(id) {
31 31
     return _.get(this.refsById, id);
32 32
   }
33 33
 

+ 5
- 5
lib/src/containers/Store.test.js Parādīt failu

@@ -32,18 +32,18 @@ describe('Store', () => {
32 32
 
33 33
   it('holds container refs by id', () => {
34 34
     const ref = {};
35
-    uut.setRefForId('refUniqueId', ref);
36
-    expect(uut.getRefForId('other')).toBeUndefined();
37
-    expect(uut.getRefForId('refUniqueId')).toBe(ref);
35
+    uut.setRefForContainerId('refUniqueId', ref);
36
+    expect(uut.getRefForContainerId('other')).toBeUndefined();
37
+    expect(uut.getRefForContainerId('refUniqueId')).toBe(ref);
38 38
   });
39 39
 
40 40
   it('clean by id', () => {
41
-    uut.setRefForId('refUniqueId', {});
41
+    uut.setRefForContainerId('refUniqueId', {});
42 42
     uut.setPropsForContainerId('refUniqueId', { foo: 'bar' });
43 43
 
44 44
     uut.cleanId('refUniqueId');
45 45
 
46
-    expect(uut.getRefForId('refUniqueId')).toBeUndefined();
46
+    expect(uut.getRefForContainerId('refUniqueId')).toBeUndefined();
47 47
     expect(uut.getPropsForContainerId('refUniqueId')).toEqual({});
48 48
   });
49 49
 });

+ 1
- 1
lib/src/events/PrivateEventsListener.test.js Parādīt failu

@@ -18,7 +18,7 @@ describe('PrivateEventsListener', () => {
18 18
     const mockRef = {
19 19
       onStart: jest.fn()
20 20
     };
21
-    store.setRefForId('myContainerId', mockRef);
21
+    store.setRefForContainerId('myContainerId', mockRef);
22 22
     uut.listenAndHandlePrivateEvents();
23 23
     expect(nativeEventsReceiver.containerStart).toHaveBeenCalledTimes(1);
24 24
     const callbackFunction = nativeEventsReceiver.containerStart.mock.calls[0][0];

+ 2
- 2
playground/src/containers/LifecycleScreen.js Parādīt failu

@@ -30,13 +30,13 @@ class LifecycleScreen extends Component {
30 30
         <Text style={styles.h1}>{`Lifecycle Screen`}</Text>
31 31
         <Text style={styles.h1}>{this.state.text}</Text>
32 32
         <Button title="Push to test onStop" onPress={this.onClickPush} />
33
-        <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
33
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
34 34
       </View>
35 35
     );
36 36
   }
37 37
 
38 38
   onClickPush() {
39
-    Navigation.push(this.props.id, {
39
+    Navigation.push(this.props.containerId, {
40 40
       name: 'navigation.playground.TextScreen'
41 41
     });
42 42
   }

+ 3
- 3
playground/src/containers/ModalScreen.js Parādīt failu

@@ -32,7 +32,7 @@ class ModalScreen extends Component {
32 32
         {this.getPreviousModalId() ? (<Button title="Dismiss Previous Modal" onPress={this.onClickDismissPreviousModal} />) : undefined}
33 33
         {this.props.previousModalIds ? (<Button title="Dismiss ALL Previous Modals" onPress={this.onClickDismissAllPreviousModals} />) : undefined}
34 34
         {this.props.previousModalIds ? (<Button title="Dismiss First In Stack" onPress={this.onClickDismissFirstInStack} />) : undefined}
35
-        <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
35
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
36 36
 
37 37
       </View>
38 38
     );
@@ -44,14 +44,14 @@ class ModalScreen extends Component {
44 44
         name: 'navigation.playground.ModalScreen',
45 45
         passProps: {
46 46
           modalPosition: this.getModalPosition() + 1,
47
-          previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.id)
47
+          previousModalIds: _.concat([], this.props.previousModalIds || [], this.props.containerId)
48 48
         }
49 49
       }
50 50
     });
51 51
   }
52 52
 
53 53
   onClickDismissModal() {
54
-    Navigation.dismissModal(this.props.id);
54
+    Navigation.dismissModal(this.props.containerId);
55 55
   }
56 56
 
57 57
   onClickDismissPreviousModal() {

+ 1
- 1
playground/src/containers/OptionsScreen.js Parādīt failu

@@ -24,7 +24,7 @@ class OptionsScreen extends Component {
24 24
       <View style={styles.root}>
25 25
         <Text style={styles.h1}>{`Options Screen`}</Text>
26 26
         <Button title="Dynamic Options" onPress={this.onClickDynamicOptions} />
27
-        <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
27
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
28 28
       </View>
29 29
     );
30 30
   }

+ 5
- 5
playground/src/containers/PushedScreen.js Parādīt failu

@@ -30,23 +30,23 @@ class PushedScreen extends Component {
30 30
         <Button title="Pop Previous" onPress={this.onClickPopPrevious} />
31 31
         <Button title="Pop To Root" onPress={this.onClickPopToRoot} />
32 32
         {stackPosition > 2 && <Button title="Pop To Stack Position 1" onPress={this.onClickPopToFirstPosition} />}
33
-        <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
33
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
34 34
       </View>
35 35
     );
36 36
   }
37 37
 
38 38
   onClickPush() {
39
-    Navigation.push(this.props.id, {
39
+    Navigation.push(this.props.containerId, {
40 40
       name: 'navigation.playground.PushedScreen',
41 41
       passProps: {
42 42
         stackPosition: this.getStackPosition() + 1,
43
-        previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.id)
43
+        previousScreenIds: _.concat([], this.props.previousScreenIds || [], this.props.containerId)
44 44
       }
45 45
     });
46 46
   }
47 47
 
48 48
   onClickPop() {
49
-    Navigation.pop(this.props.id);
49
+    Navigation.pop(this.props.containerId);
50 50
   }
51 51
 
52 52
   onClickPopPrevious() {
@@ -58,7 +58,7 @@ class PushedScreen extends Component {
58 58
   }
59 59
 
60 60
   onClickPopToRoot() {
61
-    Navigation.popToRoot(this.props.id);
61
+    Navigation.popToRoot(this.props.containerId);
62 62
   }
63 63
 
64 64
   getStackPosition() {

+ 1
- 1
playground/src/containers/TextScreen.js Parādīt failu

@@ -11,7 +11,7 @@ class TextScreen extends Component {
11 11
       <View style={styles.root}>
12 12
         <Text style={styles.h1}>{this.props.text || 'Text Screen'}</Text>
13 13
         {this.renderTextFromFunctionInProps()}
14
-        <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
14
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
15 15
       </View>
16 16
     );
17 17
   }

+ 4
- 4
playground/src/containers/WelcomeScreen.js Parādīt failu

@@ -23,7 +23,7 @@ class WelcomeScreen extends Component {
23 23
         <Button title="Push Options Screen" onPress={this.onClickPushOptionsScreen} />
24 24
         <Button title="Show Modal" onPress={this.onClickShowModal} />
25 25
         <Button title="Show Redbox" onPress={this.onClickShowRedbox} />
26
-        <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
26
+        <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
27 27
       </View>
28 28
     );
29 29
   }
@@ -102,13 +102,13 @@ class WelcomeScreen extends Component {
102 102
   }
103 103
 
104 104
   onClickPush() {
105
-    Navigation.push(this.props.id, {
105
+    Navigation.push(this.props.containerId, {
106 106
       name: 'navigation.playground.PushedScreen'
107 107
     });
108 108
   }
109 109
 
110 110
   onClickLifecycleScreen() {
111
-    Navigation.push(this.props.id, {
111
+    Navigation.push(this.props.containerId, {
112 112
       name: 'navigation.playground.LifecycleScreen'
113 113
     });
114 114
   }
@@ -126,7 +126,7 @@ class WelcomeScreen extends Component {
126 126
   }
127 127
 
128 128
   onClickPushOptionsScreen() {
129
-    Navigation.push(this.props.id, {
129
+    Navigation.push(this.props.containerId, {
130 130
       name: 'navigation.playground.OptionsScreen'
131 131
     });
132 132
   }