Bläddra i källkod

Merge options (#3055)

* migrate js and java to mergeOptions

* migrate ios to mergeOptions
Guy Carmeli 6 år sedan
förälder
incheckning
9caa47bf82
No account linked to committer's email address

+ 2
- 2
docs/docs/screen-api.md Visa fil

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

+ 2
- 2
docs/docs/styling.md Visa fil

@@ -42,10 +42,10 @@ Navigation.setDefaultOptions({
42 42
 ```
43 43
 
44 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 47
 ```js
48
-Navigation.setOptions(this.props.componentId, {
48
+Navigation.mergeOptions(this.props.componentId, {
49 49
   topBar: {
50 50
     visible: true
51 51
   }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Visa fil

@@ -55,9 +55,9 @@ public class NavigationModule extends ReactContextBaseJavaModule {
55 55
     }
56 56
 
57 57
 	@ReactMethod
58
-	public void setOptions(final String onComponentId, final ReadableMap options) {
58
+	public void mergeOptions(final String onComponentId, final ReadableMap options) {
59 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 63
 	@ReactMethod

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Visa fil

@@ -100,7 +100,7 @@ public class Navigator extends ParentController implements ModalListener {
100 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 104
         ViewController target = findControllerById(componentId);
105 105
         if (target instanceof NavigationOptionsListener) {
106 106
             ((NavigationOptionsListener) target).mergeOptions(options);

+ 4
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Visa fil

@@ -243,7 +243,7 @@ public class NavigatorTest extends BaseTest {
243 243
     }
244 244
 
245 245
     @Test
246
-    public void setOptions_CallsApplyNavigationOptions() {
246
+    public void mergeOptions_CallsApplyNavigationOptions() {
247 247
         ComponentViewController componentVc = new SimpleComponentViewController(activity, "theId", new Options());
248 248
         componentVc.setParentController(parentController);
249 249
         assertThat(componentVc.options.topBar.title.text.get("")).isEmpty();
@@ -252,13 +252,13 @@ public class NavigatorTest extends BaseTest {
252 252
         Options options = new Options();
253 253
         options.topBar.title.text = new Text("new title");
254 254
 
255
-        uut.setOptions("theId", options);
255
+        uut.mergeOptions("theId", options);
256 256
         assertThat(componentVc.options.topBar.title.text.get()).isEqualTo("new title");
257 257
     }
258 258
 
259 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 264
     @NonNull

+ 2
- 2
lib/ios/RNNBridgeModule.m Visa fil

@@ -24,8 +24,8 @@ RCT_EXPORT_METHOD(setRoot:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock
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 29
 		resolve(componentId);
30 30
 	}];
31 31
 }

+ 1
- 1
lib/ios/RNNCommandsHandler.h Visa fil

@@ -10,7 +10,7 @@
10 10
 
11 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 15
 -(void) setDefaultOptions:(NSDictionary*)options completion:(RNNTransitionCompletionBlock)completion;
16 16
 

+ 1
- 1
lib/ios/RNNCommandsHandler.m Visa fil

@@ -38,7 +38,7 @@
38 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 42
 	[self assertReady];
43 43
 	
44 44
 	UIViewController* vc = [_store findComponentForId:componentId];

+ 1
- 1
lib/ios/ReactNativeNavigationTests/RNNCommandsHandlerTest.m Visa fil

@@ -80,7 +80,7 @@
80 80
 	NSDictionary* dictFromJs = @{@"topBar": @{@"backgroundColor" :@(0xFFFF0000)}};
81 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 84
 		XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]);
85 85
 		XCTAssertTrue([nav.navigationBar.barTintColor isEqual:expectedColor]);
86 86
 	}];

+ 2
- 2
lib/src/Navigation.ts Visa fil

@@ -70,8 +70,8 @@ export class Navigation {
70 70
   /**
71 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 Visa fil

@@ -14,8 +14,8 @@ export class NativeCommandsSender {
14 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 21
   push(onComponentId: string, layout: object) {

+ 8
- 8
lib/src/commands/Commands.test.ts Visa fil

@@ -68,17 +68,17 @@ describe('Commands', () => {
68 68
     });
69 69
   });
70 70
 
71
-  describe('setOptions', () => {
71
+  describe('mergeOptions', () => {
72 72
     it('deep clones input to avoid mutation errors', () => {
73 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 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,7 +360,7 @@ describe('Commands', () => {
360 360
       const argsForMethodName = {
361 361
         setRoot: [{}],
362 362
         setDefaultOptions: [{}],
363
-        setOptions: ['id', {}],
363
+        mergeOptions: ['id', {}],
364 364
         showModal: [{}],
365 365
         dismissModal: ['id'],
366 366
         dismissAllModals: [],
@@ -375,7 +375,7 @@ describe('Commands', () => {
375 375
       const paramsForMethodName = {
376 376
         setRoot: { layout: 'parsed' },
377 377
         setDefaultOptions: { options: {} },
378
-        setOptions: { componentId: 'id', options: {} },
378
+        mergeOptions: { componentId: 'id', options: {} },
379 379
         showModal: { layout: 'parsed' },
380 380
         dismissModal: { componentId: 'id' },
381 381
         dismissAllModals: {},

+ 3
- 3
lib/src/commands/Commands.ts Visa fil

@@ -27,12 +27,12 @@ export class Commands {
27 27
     this.commandsObserver.notify('setDefaultOptions', { options });
28 28
   }
29 29
 
30
-  public setOptions(componentId, options) {
30
+  public mergeOptions(componentId, options) {
31 31
     const input = _.cloneDeep(options);
32 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 38
   public showModal(simpleApi) {

+ 10
- 11
playground/src/screens/OptionsScreen.js Visa fil

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

+ 1
- 1
playground/src/screens/OrientationDetectScreen.js Visa fil

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

+ 1
- 1
playground/src/screens/ScrollViewScreen.js Visa fil

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

+ 1
- 1
playground/src/screens/SideMenuScreen.js Visa fil

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

+ 5
- 5
playground/src/screens/TextScreen.js Visa fil

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

+ 1
- 1
playground/src/screens/TopTabOptionsScreen.js Visa fil

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

+ 1
- 1
playground/src/screens/WelcomeScreen.js Visa fil

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