Browse Source

Merge options (#3055)

* migrate js and java to mergeOptions

* migrate ios to mergeOptions
Guy Carmeli 6 years ago
parent
commit
9caa47bf82
No account linked to committer's email address

+ 2
- 2
docs/docs/screen-api.md View File

128
   Navigation.handleDeepLink(...);
128
   Navigation.handleDeepLink(...);
129
 ``` -->
129
 ``` -->
130
 
130
 
131
-## setOptions(componentId, options = {})
131
+## mergeOptions(componentId, options = {})
132
 
132
 
133
 Set options dynamically for component.
133
 Set options dynamically for component.
134
 
134
 
135
 ```js
135
 ```js
136
-Navigation.setOptions(this.props.componentId, {
136
+Navigation.mergeOptions(this.props.componentId, {
137
   topBar: {
137
   topBar: {
138
     visible: true,
138
     visible: true,
139
     title: {
139
     title: {

+ 2
- 2
docs/docs/styling.md View File

42
 ```
42
 ```
43
 
43
 
44
 ## Setting styles dynamically
44
 ## Setting styles dynamically
45
-Use the `setOptions` method to change a screen's style dynamically.
45
+Use the `mergeOptions` method to change a screen's style dynamically.
46
 
46
 
47
 ```js
47
 ```js
48
-Navigation.setOptions(this.props.componentId, {
48
+Navigation.mergeOptions(this.props.componentId, {
49
   topBar: {
49
   topBar: {
50
     visible: true
50
     visible: true
51
   }
51
   }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

55
     }
55
     }
56
 
56
 
57
 	@ReactMethod
57
 	@ReactMethod
58
-	public void setOptions(final String onComponentId, final ReadableMap options) {
58
+	public void mergeOptions(final String onComponentId, final ReadableMap options) {
59
 		final Options navOptions = Options.parse(new TypefaceLoader(activity()), new JSONObject(options.toHashMap()));
59
 		final Options navOptions = Options.parse(new TypefaceLoader(activity()), new JSONObject(options.toHashMap()));
60
-		handle(() -> navigator().setOptions(onComponentId, navOptions));
60
+		handle(() -> navigator().mergeOptions(onComponentId, navOptions));
61
 	}
61
 	}
62
 
62
 
63
 	@ReactMethod
63
 	@ReactMethod

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

100
         return defaultOptions;
100
         return defaultOptions;
101
     }
101
     }
102
 
102
 
103
-    public void setOptions(final String componentId, Options options) {
103
+    public void mergeOptions(final String componentId, Options options) {
104
         ViewController target = findControllerById(componentId);
104
         ViewController target = findControllerById(componentId);
105
         if (target instanceof NavigationOptionsListener) {
105
         if (target instanceof NavigationOptionsListener) {
106
             ((NavigationOptionsListener) target).mergeOptions(options);
106
             ((NavigationOptionsListener) target).mergeOptions(options);

+ 4
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

243
     }
243
     }
244
 
244
 
245
     @Test
245
     @Test
246
-    public void setOptions_CallsApplyNavigationOptions() {
246
+    public void mergeOptions_CallsApplyNavigationOptions() {
247
         ComponentViewController componentVc = new SimpleComponentViewController(activity, "theId", new Options());
247
         ComponentViewController componentVc = new SimpleComponentViewController(activity, "theId", new Options());
248
         componentVc.setParentController(parentController);
248
         componentVc.setParentController(parentController);
249
         assertThat(componentVc.options.topBar.title.text.get("")).isEmpty();
249
         assertThat(componentVc.options.topBar.title.text.get("")).isEmpty();
252
         Options options = new Options();
252
         Options options = new Options();
253
         options.topBar.title.text = new Text("new title");
253
         options.topBar.title.text = new Text("new title");
254
 
254
 
255
-        uut.setOptions("theId", options);
255
+        uut.mergeOptions("theId", options);
256
         assertThat(componentVc.options.topBar.title.text.get()).isEqualTo("new title");
256
         assertThat(componentVc.options.topBar.title.text.get()).isEqualTo("new title");
257
     }
257
     }
258
 
258
 
259
     @Test
259
     @Test
260
-    public void setOptions_AffectsOnlyComponentViewControllers() {
261
-        uut.setOptions("some unknown child id", new Options());
260
+    public void mergeOptions_AffectsOnlyComponentViewControllers() {
261
+        uut.mergeOptions("some unknown child id", new Options());
262
     }
262
     }
263
 
263
 
264
     @NonNull
264
     @NonNull

+ 2
- 2
lib/ios/RNNBridgeModule.m View File

24
 	}];
24
 	}];
25
 }
25
 }
26
 
26
 
27
-RCT_EXPORT_METHOD(setOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
28
-	[_commandsHandler setOptions:componentId options:options completion:^{
27
+RCT_EXPORT_METHOD(mergeOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
28
+	[_commandsHandler mergeOptions:componentId options:options completion:^{
29
 		resolve(componentId);
29
 		resolve(componentId);
30
 	}];
30
 	}];
31
 }
31
 }

+ 1
- 1
lib/ios/RNNCommandsHandler.h View File

10
 
10
 
11
 -(void) setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
11
 -(void) setRoot:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion;
12
 
12
 
13
--(void) setOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
13
+-(void) mergeOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
14
 
14
 
15
 -(void) setDefaultOptions:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
15
 -(void) setDefaultOptions:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
16
 
16
 

+ 1
- 1
lib/ios/RNNCommandsHandler.m View File

38
 	completion();
38
 	completion();
39
 }
39
 }
40
 
40
 
41
--(void) setOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion {
41
+-(void) mergeOptions:(NSString*)componentId options:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion {
42
 	[self assertReady];
42
 	[self assertReady];
43
 	
43
 	
44
 	UIViewController* vc = [_store findComponentForId:componentId];
44
 	UIViewController* vc = [_store findComponentForId:componentId];

+ 1
- 1
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m View File

80
 	NSDictionary* dictFromJs = @{@"topBar": @{@"backgroundColor" :@(0xFFFF0000)}};
80
 	NSDictionary* dictFromJs = @{@"topBar": @{@"backgroundColor" :@(0xFFFF0000)}};
81
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
81
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
82
 
82
 
83
-	[self.uut setOptions:@"componentId" options:dictFromJs completion:^{
83
+	[self.uut mergeOptions:@"componentId" options:dictFromJs completion:^{
84
 		XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
84
 		XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
85
 		XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
85
 		XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
86
 	}];
86
 	}];

+ 2
- 2
lib/src/Navigation.ts View File

70
   /**
70
   /**
71
    * Change a component's navigation options
71
    * Change a component's navigation options
72
    */
72
    */
73
-  public setOptions(componentId: string, options): void {
74
-    this.commands.setOptions(componentId, options);
73
+  public mergeOptions(componentId: string, options): void {
74
+    this.commands.mergeOptions(componentId, options);
75
   }
75
   }
76
 
76
 
77
   /**
77
   /**

+ 2
- 2
lib/src/adapters/NativeCommandsSender.ts View File

14
     return this.nativeCommandsModule.setDefaultOptions(options);
14
     return this.nativeCommandsModule.setDefaultOptions(options);
15
   }
15
   }
16
 
16
 
17
-  setOptions(componentId: string, options: object) {
18
-    return this.nativeCommandsModule.setOptions(componentId, options);
17
+  mergeOptions(componentId: string, options: object) {
18
+    return this.nativeCommandsModule.mergeOptions(componentId, options);
19
   }
19
   }
20
 
20
 
21
   push(onComponentId: string, layout: object) {
21
   push(onComponentId: string, layout: object) {

+ 8
- 8
lib/src/commands/Commands.test.ts View File

68
     });
68
     });
69
   });
69
   });
70
 
70
 
71
-  describe('setOptions', () => {
71
+  describe('mergeOptions', () => {
72
     it('deep clones input to avoid mutation errors', () => {
72
     it('deep clones input to avoid mutation errors', () => {
73
       const obj = { title: 'test' };
73
       const obj = { title: 'test' };
74
-      uut.setOptions('theComponentId', obj);
75
-      expect(mockCommandsSender.setOptions.mock.calls[0][1]).not.toBe(obj);
74
+      uut.mergeOptions('theComponentId', obj);
75
+      expect(mockCommandsSender.mergeOptions.mock.calls[0][1]).not.toBe(obj);
76
     });
76
     });
77
 
77
 
78
     it('passes options for component', () => {
78
     it('passes options for component', () => {
79
-      uut.setOptions('theComponentId', { title: '1' });
80
-      expect(mockCommandsSender.setOptions).toHaveBeenCalledTimes(1);
81
-      expect(mockCommandsSender.setOptions).toHaveBeenCalledWith('theComponentId', { title: '1' });
79
+      uut.mergeOptions('theComponentId', { title: '1' });
80
+      expect(mockCommandsSender.mergeOptions).toHaveBeenCalledTimes(1);
81
+      expect(mockCommandsSender.mergeOptions).toHaveBeenCalledWith('theComponentId', { title: '1' });
82
     });
82
     });
83
   });
83
   });
84
 
84
 
360
       const argsForMethodName = {
360
       const argsForMethodName = {
361
         setRoot: [{}],
361
         setRoot: [{}],
362
         setDefaultOptions: [{}],
362
         setDefaultOptions: [{}],
363
-        setOptions: ['id', {}],
363
+        mergeOptions: ['id', {}],
364
         showModal: [{}],
364
         showModal: [{}],
365
         dismissModal: ['id'],
365
         dismissModal: ['id'],
366
         dismissAllModals: [],
366
         dismissAllModals: [],
375
       const paramsForMethodName = {
375
       const paramsForMethodName = {
376
         setRoot: { layout: 'parsed' },
376
         setRoot: { layout: 'parsed' },
377
         setDefaultOptions: { options: {} },
377
         setDefaultOptions: { options: {} },
378
-        setOptions: { componentId: 'id', options: {} },
378
+        mergeOptions: { componentId: 'id', options: {} },
379
         showModal: { layout: 'parsed' },
379
         showModal: { layout: 'parsed' },
380
         dismissModal: { componentId: 'id' },
380
         dismissModal: { componentId: 'id' },
381
         dismissAllModals: {},
381
         dismissAllModals: {},

+ 3
- 3
lib/src/commands/Commands.ts View File

27
     this.commandsObserver.notify('setDefaultOptions', { options });
27
     this.commandsObserver.notify('setDefaultOptions', { options });
28
   }
28
   }
29
 
29
 
30
-  public setOptions(componentId, options) {
30
+  public mergeOptions(componentId, options) {
31
     const input = _.cloneDeep(options);
31
     const input = _.cloneDeep(options);
32
     this.layoutTreeCrawler.processOptions(input);
32
     this.layoutTreeCrawler.processOptions(input);
33
 
33
 
34
-    this.nativeCommandsSender.setOptions(componentId, input);
35
-    this.commandsObserver.notify('setOptions', { componentId, options });
34
+    this.nativeCommandsSender.mergeOptions(componentId, input);
35
+    this.commandsObserver.notify('mergeOptions', { componentId, options });
36
   }
36
   }
37
 
37
 
38
   public showModal(simpleApi) {
38
   public showModal(simpleApi) {

+ 10
- 11
playground/src/screens/OptionsScreen.js View File

125
 
125
 
126
   onNavigationButtonPressed(id) {
126
   onNavigationButtonPressed(id) {
127
     if (id === BUTTON_ONE) {
127
     if (id === BUTTON_ONE) {
128
-      Navigation.setOptions(this.props.componentId, {
128
+      Navigation.mergeOptions(this.props.componentId, {
129
         topBar: {
129
         topBar: {
130
           rightButtons: [{
130
           rightButtons: [{
131
             id: BUTTON_TWO,
131
             id: BUTTON_TWO,
142
         }
142
         }
143
       });
143
       });
144
     } else if (id === BUTTON_TWO) {
144
     } else if (id === BUTTON_TWO) {
145
-      Navigation.setOptions(this.props.componentId, {
145
+      Navigation.mergeOptions(this.props.componentId, {
146
         topBar: {
146
         topBar: {
147
           rightButtons: [{
147
           rightButtons: [{
148
             id: BUTTON_ONE,
148
             id: BUTTON_ONE,
165
   }
165
   }
166
 
166
 
167
   onClickDynamicOptions = () => {
167
   onClickDynamicOptions = () => {
168
-    Navigation.setOptions(this.props.componentId, {
168
+    Navigation.mergeOptions(this.props.componentId, {
169
       topBar: {
169
       topBar: {
170
         title: {
170
         title: {
171
           text: 'Dynamic Title',
171
           text: 'Dynamic Title',
173
           largeTitle: false,
173
           largeTitle: false,
174
           fontSize: 20,
174
           fontSize: 20,
175
           fontFamily: 'HelveticaNeue-CondensedBold'
175
           fontFamily: 'HelveticaNeue-CondensedBold'
176
-        },
177
-        color: 'red',
176
+        }
178
       }
177
       }
179
     });
178
     });
180
   }
179
   }
196
   }
195
   }
197
 
196
 
198
   onClickTopBarTransparent = () => {
197
   onClickTopBarTransparent = () => {
199
-    Navigation.setOptions(this.props.componentId, {
198
+    Navigation.mergeOptions(this.props.componentId, {
200
       topBar: {
199
       topBar: {
201
         transparent: true
200
         transparent: true
202
       }
201
       }
204
   }
203
   }
205
 
204
 
206
   onClickTopBarOpaque = () => {
205
   onClickTopBarOpaque = () => {
207
-    Navigation.setOptions(this.props.componentId, {
206
+    Navigation.mergeOptions(this.props.componentId, {
208
       topBar: {
207
       topBar: {
209
         transparent: false
208
         transparent: false
210
       }
209
       }
212
   }
211
   }
213
 
212
 
214
   onClickShowTopBar = () => {
213
   onClickShowTopBar = () => {
215
-    Navigation.setOptions(this.props.componentId, {
214
+    Navigation.mergeOptions(this.props.componentId, {
216
       topBar: {
215
       topBar: {
217
         visible: true,
216
         visible: true,
218
         animate: true
217
         animate: true
221
   }
220
   }
222
 
221
 
223
   onClickHideTopBar = () => {
222
   onClickHideTopBar = () => {
224
-    Navigation.setOptions(this.props.componentId, {
223
+    Navigation.mergeOptions(this.props.componentId, {
225
       topBar: {
224
       topBar: {
226
         visible: false,
225
         visible: false,
227
         animate: true
226
         animate: true
230
   }
229
   }
231
 
230
 
232
   onClickFab = () => {
231
   onClickFab = () => {
233
-    Navigation.setOptions(this.props.componentId, {
232
+    Navigation.mergeOptions(this.props.componentId, {
234
       fab: {
233
       fab: {
235
         id: FAB,
234
         id: FAB,
236
         visible: false
235
         visible: false
268
   }
267
   }
269
 
268
 
270
   onShowTopBarReactView = () => {
269
   onShowTopBarReactView = () => {
271
-    Navigation.setOptions(this.props.componentId, {
270
+    Navigation.mergeOptions(this.props.componentId, {
272
       topBar: {
271
       topBar: {
273
         title: {
272
         title: {
274
           component: {
273
           component: {

+ 1
- 1
playground/src/screens/OrientationDetectScreen.js View File

12
 
12
 
13
     this.detectHorizontal = this.detectHorizontal.bind(this);
13
     this.detectHorizontal = this.detectHorizontal.bind(this);
14
     this.state = { horizontal: false };
14
     this.state = { horizontal: false };
15
-    Navigation.setOptions(this.props.componentId, {
15
+    Navigation.mergeOptions(this.props.componentId, {
16
       orientation: props.orientation
16
       orientation: props.orientation
17
     });
17
     });
18
   }
18
   }

+ 1
- 1
playground/src/screens/ScrollViewScreen.js View File

58
   }
58
   }
59
 
59
 
60
   componentDidUpdate() {
60
   componentDidUpdate() {
61
-    Navigation.setOptions(this.props.componentId, {
61
+    Navigation.mergeOptions(this.props.componentId, {
62
       topBar: {
62
       topBar: {
63
         hideOnScroll: this.state.topBarHideOnScroll
63
         hideOnScroll: this.state.topBarHideOnScroll
64
       },
64
       },

+ 1
- 1
playground/src/screens/SideMenuScreen.js View File

20
   }
20
   }
21
 
21
 
22
   hideSideMenu() {
22
   hideSideMenu() {
23
-    Navigation.setOptions(this.props.componentId, {
23
+    Navigation.mergeOptions(this.props.componentId, {
24
       sideMenu: {
24
       sideMenu: {
25
         [this.props.side]: {
25
         [this.props.side]: {
26
           visible: false
26
           visible: false

+ 5
- 5
playground/src/screens/TextScreen.js View File

58
   }
58
   }
59
 
59
 
60
   onButtonPress() {
60
   onButtonPress() {
61
-    Navigation.setOptions(this.props.componentId, {
61
+    Navigation.mergeOptions(this.props.componentId, {
62
       bottomTab: {
62
       bottomTab: {
63
         badge: `TeSt`
63
         badge: `TeSt`
64
       }
64
       }
66
   }
66
   }
67
 
67
 
68
   onClickSwitchToTab() {
68
   onClickSwitchToTab() {
69
-    Navigation.setOptions(this.props.componentId, {
69
+    Navigation.mergeOptions(this.props.componentId, {
70
       bottomTabs: {
70
       bottomTabs: {
71
         currentTabIndex: 1,
71
         currentTabIndex: 1,
72
         visible: false,
72
         visible: false,
78
   }
78
   }
79
 
79
 
80
   onClickSwitchToTabByComponentID() {
80
   onClickSwitchToTabByComponentID() {
81
-    Navigation.setOptions(this.props.componentId, {
81
+    Navigation.mergeOptions(this.props.componentId, {
82
       bottomTabs: {
82
       bottomTabs: {
83
         currentTabId: globalFirstComponentID
83
         currentTabId: globalFirstComponentID
84
       }
84
       }
86
   }
86
   }
87
 
87
 
88
   hideTabBar(visible) {
88
   hideTabBar(visible) {
89
-    Navigation.setOptions(this.props.componentId, {
89
+    Navigation.mergeOptions(this.props.componentId, {
90
       bottomTabs: {
90
       bottomTabs: {
91
         visible,
91
         visible,
92
         animate: true
92
         animate: true
95
   }
95
   }
96
 
96
 
97
   showSideMenu(side) {
97
   showSideMenu(side) {
98
-    Navigation.setOptions(this.props.componentId, {
98
+    Navigation.mergeOptions(this.props.componentId, {
99
       sideMenu: {
99
       sideMenu: {
100
         [side]: {
100
         [side]: {
101
           visible: true
101
           visible: true

+ 1
- 1
playground/src/screens/TopTabOptionsScreen.js View File

33
   }
33
   }
34
 
34
 
35
   onClickDynamicOptions() {
35
   onClickDynamicOptions() {
36
-    Navigation.setOptions(this.props.componentId, {
36
+    Navigation.mergeOptions(this.props.componentId, {
37
       topBar: {
37
       topBar: {
38
         title: {
38
         title: {
39
           text: 'Dynamic Title',
39
           text: 'Dynamic Title',

+ 1
- 1
playground/src/screens/WelcomeScreen.js View File

417
         ]
417
         ]
418
       }
418
       }
419
     });
419
     });
420
-    Navigation.setOptions('my unique id', {
420
+    Navigation.mergeOptions('my unique id', {
421
       topBar: {
421
       topBar: {
422
         title: {
422
         title: {
423
           text: 'User provided id'
423
           text: 'User provided id'