Browse Source

Support passing mergeOptions to pop and dismissModal commands

Guy Carmeli 5 years ago
parent
commit
aabd9e4248

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java View File

10
 import org.json.JSONObject;
10
 import org.json.JSONObject;
11
 
11
 
12
 public class Options {
12
 public class Options {
13
+    public static final Options EMPTY = new Options();
13
 
14
 
14
     @NonNull
15
     @NonNull
15
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {
16
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {

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

69
 
69
 
70
 	@ReactMethod
70
 	@ReactMethod
71
 	public void setDefaultOptions(ReadableMap options) {
71
 	public void setDefaultOptions(ReadableMap options) {
72
-        final Options defaultOptions = Options.parse(new TypefaceLoader(activity()), JSONParser.parse(options));
73
-        handle(() -> navigator().setDefaultOptions(defaultOptions));
72
+        handle(() -> navigator().setDefaultOptions(parse(options)));
74
     }
73
     }
75
 
74
 
76
 	@ReactMethod
75
 	@ReactMethod
77
 	public void mergeOptions(String onComponentId, ReadableMap options) {
76
 	public void mergeOptions(String onComponentId, ReadableMap options) {
78
-		final Options navOptions = Options.parse(new TypefaceLoader(activity()), JSONParser.parse(options));
79
-		handle(() -> navigator().mergeOptions(onComponentId, navOptions));
77
+		handle(() -> navigator().mergeOptions(onComponentId, parse(options)));
80
 	}
78
 	}
81
 
79
 
82
 	@ReactMethod
80
 	@ReactMethod
98
     }
96
     }
99
 
97
 
100
 	@ReactMethod
98
 	@ReactMethod
101
-	public void pop(String commandId, String componentId, ReadableMap options, Promise promise) {
102
-		handle(() -> navigator().pop(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now)));
99
+	public void pop(String commandId, String componentId, ReadableMap mergeOptions, Promise promise) {
100
+		handle(() -> navigator().pop(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
103
 	}
101
 	}
104
 
102
 
105
 	@ReactMethod
103
 	@ReactMethod
106
-	public void popTo(String commandId, String componentId, Promise promise) {
107
-		handle(() -> navigator().popTo(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now)));
104
+	public void popTo(String commandId, String componentId, ReadableMap mergeOptions, Promise promise) {
105
+		handle(() -> navigator().popTo(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
108
 	}
106
 	}
109
 
107
 
110
 	@ReactMethod
108
 	@ReactMethod
111
-	public void popToRoot(String commandId, String componentId, Promise promise) {
112
-		handle(() -> navigator().popToRoot(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now)));
109
+	public void popToRoot(String commandId, String componentId, ReadableMap mergeOptions, Promise promise) {
110
+		handle(() -> navigator().popToRoot(componentId, parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
113
 	}
111
 	}
114
 
112
 
115
 	@ReactMethod
113
 	@ReactMethod
122
 	}
120
 	}
123
 
121
 
124
 	@ReactMethod
122
 	@ReactMethod
125
-	public void dismissModal(String commandId, String componentId, Promise promise) {
126
-		handle(() -> navigator().dismissModal(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now)));
123
+	public void dismissModal(String commandId, String componentId, ReadableMap mergeOptions, Promise promise) {
124
+		handle(() -> {
125
+            navigator().mergeOptions(componentId, parse(mergeOptions));
126
+            navigator().dismissModal(componentId, new NativeCommandListener(commandId, promise, eventEmitter, now));
127
+        });
127
 	}
128
 	}
128
 
129
 
129
-	@ReactMethod
130
-	public void dismissAllModals(String commandId, Promise promise) {
131
-		handle(() -> navigator().dismissAllModals(new NativeCommandListener(commandId, promise, eventEmitter, now)));
130
+    @ReactMethod
131
+	public void dismissAllModals(String commandId, ReadableMap mergeOptions, Promise promise) {
132
+		handle(() -> navigator().dismissAllModals(parse(mergeOptions), new NativeCommandListener(commandId, promise, eventEmitter, now)));
132
 	}
133
 	}
133
 
134
 
134
 	@ReactMethod
135
 	@ReactMethod
160
         );
161
         );
161
 	}
162
 	}
162
 
163
 
164
+    private Options parse(ReadableMap mergeOptions) {
165
+        return Options.parse(new TypefaceLoader(activity()), JSONParser.parse(mergeOptions));
166
+    }
167
+
163
 	private Map<String, ExternalComponentCreator> externalComponentCreator() {
168
 	private Map<String, ExternalComponentCreator> externalComponentCreator() {
164
         return ((NavigationApplication) activity().getApplication()).getExternalComponents();
169
         return ((NavigationApplication) activity().getApplication()).getExternalComponents();
165
     }
170
     }

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

156
         applyOnStack(id, listener, stack -> stack.setRoot(viewController, listener));
156
         applyOnStack(id, listener, stack -> stack.setRoot(viewController, listener));
157
     }
157
     }
158
 
158
 
159
-    public void pop(String id, CommandListener listener) {
160
-        applyOnStack(id, listener, stack -> stack.pop(listener));
159
+    public void pop(String id, Options mergeOptions, CommandListener listener) {
160
+        applyOnStack(id, listener, stack -> {
161
+            stack.peek().mergeOptions(mergeOptions);
162
+            stack.pop(listener);
163
+        });
161
     }
164
     }
162
 
165
 
163
-    public void popToRoot(final String id, CommandListener listener) {
164
-        applyOnStack(id, listener, stack -> stack.popToRoot(listener));
166
+    public void popToRoot(final String id, Options mergeOptions, CommandListener listener) {
167
+        applyOnStack(id, listener, stack -> stack.popToRoot(mergeOptions, listener));
165
     }
168
     }
166
 
169
 
167
-    public void popTo(final String id, CommandListener listener) {
170
+    public void popTo(final String id, Options mergeOptions, CommandListener listener) {
168
         ViewController target = findControllerById(id);
171
         ViewController target = findControllerById(id);
169
         if (target != null) {
172
         if (target != null) {
170
-            target.performOnParentStack(stack -> ((StackController) stack).popTo(target, listener));
173
+            target.performOnParentStack(stack -> {
174
+                ((StackController) stack).popTo(target, mergeOptions, listener);
175
+            });
171
         } else {
176
         } else {
172
             listener.onError("Failed to execute stack command. Stack by " + id + " not found.");
177
             listener.onError("Failed to execute stack command. Stack by " + id + " not found.");
173
         }
178
         }
185
         modalStack.dismissModal(componentId, root, listener);
190
         modalStack.dismissModal(componentId, root, listener);
186
     }
191
     }
187
 
192
 
188
-    public void dismissAllModals(CommandListener listener) {
189
-        modalStack.dismissAllModals(listener, root);
193
+    public void dismissAllModals(Options mergeOptions, CommandListener listener) {
194
+        modalStack.dismissAllModals(root, mergeOptions, listener);
190
     }
195
     }
191
 
196
 
192
     public void showOverlay(ViewController overlay, CommandListener listener) {
197
     public void showOverlay(ViewController overlay, CommandListener listener) {

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

149
         return false;
149
         return false;
150
     }
150
     }
151
 
151
 
152
-    void performOnParentStack(Task accept, Runnable reject) {
152
+    void performOnParentStack(Task<StackController> accept, Runnable reject) {
153
         if (!performOnParentStack(accept)) {
153
         if (!performOnParentStack(accept)) {
154
             reject.run();
154
             reject.run();
155
         }
155
         }

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

78
         }
78
         }
79
     }
79
     }
80
 
80
 
81
-    public void dismissAllModals(CommandListener listener, ViewController root) {
81
+    public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) {
82
         if (modals.isEmpty()) {
82
         if (modals.isEmpty()) {
83
             listener.onError("Nothing to dismiss");
83
             listener.onError("Nothing to dismiss");
84
             return;
84
             return;
87
         String topModalId = peek().getId();
87
         String topModalId = peek().getId();
88
         int modalsDismissed = size();
88
         int modalsDismissed = size();
89
 
89
 
90
+        peek().mergeOptions(mergeOptions);
91
+
90
         while (!modals.isEmpty()) {
92
         while (!modals.isEmpty()) {
91
             if (modals.size() == 1) {
93
             if (modals.size() == 1) {
92
                 dismissModal(modals.get(0).getId(), root, new CommandListenerAdapter(listener) {
94
                 dismissModal(modals.get(0).getId(), root, new CommandListenerAdapter(listener) {

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java View File

221
         listener.onSuccess(disappearing.getId());
221
         listener.onSuccess(disappearing.getId());
222
     }
222
     }
223
 
223
 
224
-    public void popTo(final ViewController viewController, CommandListener listener) {
225
-        if (!stack.containsId(viewController.getId())) {
224
+    public void popTo(ViewController viewController, Options mergeOptions, CommandListener listener) {
225
+        if (!stack.containsId(viewController.getId()) || peek().equals(viewController)) {
226
             listener.onError("Nothing to pop");
226
             listener.onError("Nothing to pop");
227
             return;
227
             return;
228
         }
228
         }
229
 
229
 
230
+        peek().mergeOptions(mergeOptions);
231
+
230
         Iterator<String> iterator = stack.iterator();
232
         Iterator<String> iterator = stack.iterator();
231
         String currentControlId = iterator.next();
233
         String currentControlId = iterator.next();
232
         while (!viewController.getId().equals(currentControlId)) {
234
         while (!viewController.getId().equals(currentControlId)) {
241
         pop(listener);
243
         pop(listener);
242
     }
244
     }
243
 
245
 
244
-    public void popToRoot(CommandListener listener) {
246
+    public void popToRoot(Options mergeOptions, CommandListener listener) {
245
         if (!canPop()) {
247
         if (!canPop()) {
246
             listener.onError("Nothing to pop");
248
             listener.onError("Nothing to pop");
247
             return;
249
             return;
248
         }
250
         }
249
 
251
 
252
+        peek().mergeOptions(mergeOptions);
250
         Iterator<String> iterator = stack.iterator();
253
         Iterator<String> iterator = stack.iterator();
251
         while (stack.size() > 2) {
254
         while (stack.size() > 2) {
252
             ViewController controller = stack.get(iterator.next());
255
             ViewController controller = stack.get(iterator.next());

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

188
 
188
 
189
     @Test
189
     @Test
190
     public void pop_InvalidDoesNothing() {
190
     public void pop_InvalidDoesNothing() {
191
-        uut.pop("123", new CommandListenerAdapter());
191
+        uut.pop("123", Options.EMPTY, new CommandListenerAdapter());
192
         uut.setRoot(child1, new CommandListenerAdapter());
192
         uut.setRoot(child1, new CommandListenerAdapter());
193
-        uut.pop(child1.getId(), new CommandListenerAdapter());
193
+        uut.pop(child1.getId(), Options.EMPTY, new CommandListenerAdapter());
194
         assertThat(uut.getChildControllers()).hasSize(1);
194
         assertThat(uut.getChildControllers()).hasSize(1);
195
     }
195
     }
196
 
196
 
208
                 stack2.push(child4, new CommandListenerAdapter() {
208
                 stack2.push(child4, new CommandListenerAdapter() {
209
                             @Override
209
                             @Override
210
                             public void onSuccess(String childId) {
210
                             public void onSuccess(String childId) {
211
-                                uut.pop("child4", new CommandListenerAdapter());
211
+                                uut.pop("child4", Options.EMPTY, new CommandListenerAdapter());
212
                                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
212
                                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
213
                             }
213
                             }
214
                         }
214
                         }
226
         stack.push(child1, new CommandListenerAdapter());
226
         stack.push(child1, new CommandListenerAdapter());
227
         stack.push(child2, new CommandListenerAdapter());
227
         stack.push(child2, new CommandListenerAdapter());
228
 
228
 
229
-        uut.pop(stack.getId(), new CommandListenerAdapter());
229
+        uut.pop(stack.getId(), Options.EMPTY, new CommandListenerAdapter());
230
         assertThat(stack.getChildControllers()).containsOnly(child1);
230
         assertThat(stack.getChildControllers()).containsOnly(child1);
231
     }
231
     }
232
 
232
 
244
         stack2.push(child5, new CommandListenerAdapter() {
244
         stack2.push(child5, new CommandListenerAdapter() {
245
             @Override
245
             @Override
246
             public void onSuccess(String childId) {
246
             public void onSuccess(String childId) {
247
-                uut.popTo(child2.getId(), new CommandListenerAdapter());
247
+                uut.popTo(child2.getId(), Options.EMPTY, new CommandListenerAdapter());
248
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
248
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
249
             }
249
             }
250
         });
250
         });
264
         stack2.push(child5, new CommandListenerAdapter() {
264
         stack2.push(child5, new CommandListenerAdapter() {
265
             @Override
265
             @Override
266
             public void onSuccess(String childId) {
266
             public void onSuccess(String childId) {
267
-                uut.popToRoot(child3.getId(), new CommandListenerAdapter());
267
+                uut.popToRoot(child3.getId(), Options.EMPTY, new CommandListenerAdapter());
268
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
268
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
269
             }
269
             }
270
         });
270
         });
370
 
370
 
371
     @Test
371
     @Test
372
     public void pop_InvalidDoesNothing_Promise() {
372
     public void pop_InvalidDoesNothing_Promise() {
373
-        uut.pop("123", new CommandListenerAdapter());
373
+        uut.pop("123", Options.EMPTY, new CommandListenerAdapter());
374
         uut.setRoot(child1, new CommandListenerAdapter());
374
         uut.setRoot(child1, new CommandListenerAdapter());
375
-        uut.pop(child1.getId(), new CommandListenerAdapter() {
375
+        uut.pop(child1.getId(), Options.EMPTY, new CommandListenerAdapter() {
376
             @Override
376
             @Override
377
             public void onError(String reason) {
377
             public void onError(String reason) {
378
                 assertThat(uut.getChildControllers()).hasSize(1);
378
                 assertThat(uut.getChildControllers()).hasSize(1);
393
         stack2.push(child4, new CommandListenerAdapter() {
393
         stack2.push(child4, new CommandListenerAdapter() {
394
             @Override
394
             @Override
395
             public void onSuccess(String childId) {
395
             public void onSuccess(String childId) {
396
-                uut.pop("child4", new CommandListenerAdapter());
396
+                uut.pop("child4", Options.EMPTY, new CommandListenerAdapter());
397
                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
397
                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
398
             }
398
             }
399
         });
399
         });
431
                 assertThat(spy.getChildControllers().size()).isEqualTo(1);
431
                 assertThat(spy.getChildControllers().size()).isEqualTo(1);
432
             }
432
             }
433
         };
433
         };
434
-        uut.pop("child2", listener);
434
+        uut.pop("child2", Options.EMPTY, listener);
435
         verify(spy, times(1)).pop(listener);
435
         verify(spy, times(1)).pop(listener);
436
     }
436
     }
437
 
437
 
505
         disablePushAnimation(child2);
505
         disablePushAnimation(child2);
506
         disableShowModalAnimation(child1);
506
         disableShowModalAnimation(child1);
507
 
507
 
508
-        uut.dismissAllModals(new CommandListenerAdapter());
508
+        uut.dismissAllModals(Options.EMPTY, new CommandListenerAdapter());
509
         verify(parentVisibilityListener, times(0)).onViewAppeared(parentController.getView());
509
         verify(parentVisibilityListener, times(0)).onViewAppeared(parentController.getView());
510
 
510
 
511
         uut.setRoot(parentController, new CommandListenerAdapter());
511
         uut.setRoot(parentController, new CommandListenerAdapter());
513
 
513
 
514
         verify(parentVisibilityListener, times(1)).onViewAppeared(parentController.getView());
514
         verify(parentVisibilityListener, times(1)).onViewAppeared(parentController.getView());
515
         uut.showModal(child1, new CommandListenerAdapter());
515
         uut.showModal(child1, new CommandListenerAdapter());
516
-        uut.dismissAllModals(new CommandListenerAdapter());
516
+        uut.dismissAllModals(Options.EMPTY, new CommandListenerAdapter());
517
 
517
 
518
         verify(parentVisibilityListener, times(2)).onViewAppeared(parentController.getView());
518
         verify(parentVisibilityListener, times(2)).onViewAppeared(parentController.getView());
519
     }
519
     }

+ 18
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java View File

141
                 assertThat(uut.isEmpty()).isTrue();
141
                 assertThat(uut.isEmpty()).isTrue();
142
             }
142
             }
143
         });
143
         });
144
-        uut.dismissAllModals(listener, rootController);
144
+        uut.dismissAllModals(rootController, Options.EMPTY, listener);
145
         verify(listener, times(1)).onSuccess(anyString());
145
         verify(listener, times(1)).onSuccess(anyString());
146
         verifyZeroInteractions(listener);
146
         verifyZeroInteractions(listener);
147
     }
147
     }
149
     @Test
149
     @Test
150
     public void dismissAllModals_rejectIfEmpty() {
150
     public void dismissAllModals_rejectIfEmpty() {
151
         CommandListener spy = spy(new CommandListenerAdapter());
151
         CommandListener spy = spy(new CommandListenerAdapter());
152
-        uut.dismissAllModals(spy, rootController);
152
+        uut.dismissAllModals(rootController, Options.EMPTY, spy);
153
         verify(spy, times(1)).onError(any());
153
         verify(spy, times(1)).onError(any());
154
     }
154
     }
155
 
155
 
156
+    @Test
157
+    public void dismissAllModals_optionsAreMergedOnTopModal() {
158
+        uut.showModal(modal1, rootController, new CommandListenerAdapter());
159
+        uut.showModal(modal2, rootController, new CommandListenerAdapter());
160
+        uut.showModal(modal3, rootController, new CommandListenerAdapter());
161
+
162
+        Options mergeOptions = new Options();
163
+        uut.dismissAllModals(rootController, mergeOptions, new CommandListenerAdapter());
164
+        verify(modal3).mergeOptions(mergeOptions);
165
+        verify(modal1, times(0)).mergeOptions(mergeOptions);
166
+        verify(modal2, times(0)).mergeOptions(mergeOptions);
167
+    }
168
+
156
     @SuppressWarnings("Convert2Lambda")
169
     @SuppressWarnings("Convert2Lambda")
157
     @Test
170
     @Test
158
     public void dismissAllModals_onlyTopModalIsAnimated() {
171
     public void dismissAllModals_onlyTopModalIsAnimated() {
162
         ViewGroup view1 = modal1.getView();
175
         ViewGroup view1 = modal1.getView();
163
         ViewGroup view2 = modal2.getView();
176
         ViewGroup view2 = modal2.getView();
164
         CommandListener listener = spy(new CommandListenerAdapter());
177
         CommandListener listener = spy(new CommandListenerAdapter());
165
-        uut.dismissAllModals(listener, rootController);
178
+        uut.dismissAllModals(rootController, Options.EMPTY, listener);
166
         verify(presenter, times(1)).dismissTopModal(eq(modal2), eq(rootController), any());
179
         verify(presenter, times(1)).dismissTopModal(eq(modal2), eq(rootController), any());
167
         verify(listener).onSuccess(modal2.getId());
180
         verify(listener).onSuccess(modal2.getId());
168
         verify(animator, times(0)).dismiss(eq(view1), eq(modal1.options.animations.dismissModal), any());
181
         verify(animator, times(0)).dismiss(eq(view1), eq(modal1.options.animations.dismissModal), any());
175
         uut.showModal(modal1, rootController, new CommandListenerAdapter());
188
         uut.showModal(modal1, rootController, new CommandListenerAdapter());
176
         uut.showModal(modal2, rootController, new CommandListenerAdapter());
189
         uut.showModal(modal2, rootController, new CommandListenerAdapter());
177
 
190
 
178
-        uut.dismissAllModals(new CommandListenerAdapter(), rootController);
191
+        uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
179
 
192
 
180
         verify(modal1, times(1)).destroy();
193
         verify(modal1, times(1)).destroy();
181
         verify(modal1, times(1)).onViewDisappear();
194
         verify(modal1, times(1)).onViewDisappear();
187
         assertThat(uut.isEmpty()).isTrue();
200
         assertThat(uut.isEmpty()).isTrue();
188
         uut.showModal(modal1, rootController, new CommandListenerAdapter());
201
         uut.showModal(modal1, rootController, new CommandListenerAdapter());
189
         assertThat(uut.isEmpty()).isFalse();
202
         assertThat(uut.isEmpty()).isFalse();
190
-        uut.dismissAllModals(new CommandListenerAdapter(), rootController);
203
+        uut.dismissAllModals(rootController, Options.EMPTY, new CommandListenerAdapter());
191
         assertThat(uut.isEmpty()).isTrue();
204
         assertThat(uut.isEmpty()).isTrue();
192
     }
205
     }
193
 
206
 

+ 35
- 8
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java View File

453
                 assertThat(uut.size()).isEqualTo(3);
453
                 assertThat(uut.size()).isEqualTo(3);
454
                 assertThat(uut.peek()).isEqualTo(child3);
454
                 assertThat(uut.peek()).isEqualTo(child3);
455
 
455
 
456
-                uut.popTo(child1, new CommandListenerAdapter());
456
+                uut.popTo(child1, Options.EMPTY, new CommandListenerAdapter());
457
 
457
 
458
                 assertThat(uut.size()).isEqualTo(1);
458
                 assertThat(uut.size()).isEqualTo(1);
459
                 assertThat(uut.peek()).isEqualTo(child1);
459
                 assertThat(uut.peek()).isEqualTo(child1);
461
         });
461
         });
462
     }
462
     }
463
 
463
 
464
+    @Test
465
+    public void popTo_optionsAreMergedOnTopChild() {
466
+        disablePushAnimation(child1, child2);
467
+        uut.push(child1, new CommandListenerAdapter());
468
+
469
+        Options mergeOptions = new Options();
470
+        uut.popTo(child2, mergeOptions, new CommandListenerAdapter());
471
+        uut.popTo(child1, mergeOptions, new CommandListenerAdapter());
472
+        verify(child1, times(0)).mergeOptions(mergeOptions);
473
+
474
+        uut.push(child2, new CommandListenerAdapter());
475
+        uut.popTo(child1, mergeOptions, new CommandListenerAdapter());
476
+        verify(child2).mergeOptions(mergeOptions);
477
+    }
478
+
464
     @Test
479
     @Test
465
     public void popTo_NotAChildOfThisStack_DoesNothing() {
480
     public void popTo_NotAChildOfThisStack_DoesNothing() {
466
         uut.push(child1, new CommandListenerAdapter());
481
         uut.push(child1, new CommandListenerAdapter());
467
         uut.push(child3, new CommandListenerAdapter());
482
         uut.push(child3, new CommandListenerAdapter());
468
         assertThat(uut.size()).isEqualTo(2);
483
         assertThat(uut.size()).isEqualTo(2);
469
-        uut.popTo(child2, new CommandListenerAdapter());
484
+        uut.popTo(child2, Options.EMPTY, new CommandListenerAdapter());
470
         assertThat(uut.size()).isEqualTo(2);
485
         assertThat(uut.size()).isEqualTo(2);
471
     }
486
     }
472
 
487
 
478
         uut.push(child4, new CommandListenerAdapter() {
493
         uut.push(child4, new CommandListenerAdapter() {
479
             @Override
494
             @Override
480
             public void onSuccess(String childId) {
495
             public void onSuccess(String childId) {
481
-                uut.popTo(child2, new CommandListenerAdapter() {
496
+                uut.popTo(child2, Options.EMPTY, new CommandListenerAdapter() {
482
                     @Override
497
                     @Override
483
                     public void onSuccess(String childId) {
498
                     public void onSuccess(String childId) {
484
                         verify(animator, times(0)).pop(eq(child1.getView()), any(), any());
499
                         verify(animator, times(0)).pop(eq(child1.getView()), any(), any());
503
                 assertThat(uut.size()).isEqualTo(3);
518
                 assertThat(uut.size()).isEqualTo(3);
504
                 assertThat(uut.peek()).isEqualTo(child3);
519
                 assertThat(uut.peek()).isEqualTo(child3);
505
 
520
 
506
-                uut.popToRoot(new CommandListenerAdapter() {
521
+                uut.popToRoot(Options.EMPTY, new CommandListenerAdapter() {
507
                     @Override
522
                     @Override
508
                     public void onSuccess(String childId) {
523
                     public void onSuccess(String childId) {
509
                         assertThat(uut.size()).isEqualTo(1);
524
                         assertThat(uut.size()).isEqualTo(1);
524
         uut.push(child3, new CommandListenerAdapter() {
539
         uut.push(child3, new CommandListenerAdapter() {
525
             @Override
540
             @Override
526
             public void onSuccess(String childId) {
541
             public void onSuccess(String childId) {
527
-                uut.popToRoot(new CommandListenerAdapter() {
542
+                uut.popToRoot(Options.EMPTY, new CommandListenerAdapter() {
528
                     @Override
543
                     @Override
529
                     public void onSuccess(String childId) {
544
                     public void onSuccess(String childId) {
530
                         verify(animator, times(1)).pop(eq(child3.getView()), eq(child3.options.animations.pop), any());
545
                         verify(animator, times(1)).pop(eq(child3.getView()), eq(child3.options.animations.pop), any());
544
         uut.push(child2, new CommandListenerAdapter());
559
         uut.push(child2, new CommandListenerAdapter());
545
         uut.push(child3, new CommandListenerAdapter());
560
         uut.push(child3, new CommandListenerAdapter());
546
 
561
 
547
-        uut.popToRoot(new CommandListenerAdapter() {
562
+        uut.popToRoot(Options.EMPTY, new CommandListenerAdapter() {
548
             @Override
563
             @Override
549
             public void onSuccess(String childId) {
564
             public void onSuccess(String childId) {
550
                 verify(child1, times(0)).destroy();
565
                 verify(child1, times(0)).destroy();
558
     public void popToRoot_EmptyStackDoesNothing() {
573
     public void popToRoot_EmptyStackDoesNothing() {
559
         assertThat(uut.isEmpty()).isTrue();
574
         assertThat(uut.isEmpty()).isTrue();
560
         CommandListenerAdapter listener = spy(new CommandListenerAdapter());
575
         CommandListenerAdapter listener = spy(new CommandListenerAdapter());
561
-        uut.popToRoot(listener);
576
+        uut.popToRoot(Options.EMPTY, listener);
562
         assertThat(uut.isEmpty()).isTrue();
577
         assertThat(uut.isEmpty()).isTrue();
563
         verify(listener, times(1)).onError(any());
578
         verify(listener, times(1)).onError(any());
564
     }
579
     }
565
 
580
 
581
+    @Test
582
+    public void popToRoot_optionsAreMergedOnTopChild() {
583
+        disablePushAnimation(child1, child2);
584
+        uut.push(child1, new CommandListenerAdapter());
585
+        uut.push(child2, new CommandListenerAdapter());
586
+
587
+        Options mergeOptions = new Options();
588
+        uut.popToRoot(mergeOptions, new CommandListenerAdapter());
589
+        verify(child2).mergeOptions(mergeOptions);
590
+        verify(child1, times(0)).mergeOptions(mergeOptions);
591
+    }
592
+
566
     @Test
593
     @Test
567
     public void findControllerById_ReturnsSelfOrChildrenById() {
594
     public void findControllerById_ReturnsSelfOrChildrenById() {
568
         assertThat(uut.findControllerById("123")).isNull();
595
         assertThat(uut.findControllerById("123")).isNull();
673
                 verify(child2, times(0)).destroy();
700
                 verify(child2, times(0)).destroy();
674
                 verify(child3, times(0)).destroy();
701
                 verify(child3, times(0)).destroy();
675
 
702
 
676
-                uut.popTo(child1, new CommandListenerAdapter() {
703
+                uut.popTo(child1, Options.EMPTY, new CommandListenerAdapter() {
677
                     @Override
704
                     @Override
678
                     public void onSuccess(String childId) {
705
                     public void onSuccess(String childId) {
679
                         verify(child2, times(1)).destroy();
706
                         verify(child2, times(1)).destroy();

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

26
     return this.nativeCommandsModule.pop(commandId, componentId, options);
26
     return this.nativeCommandsModule.pop(commandId, componentId, options);
27
   }
27
   }
28
 
28
 
29
-  popTo(commandId: string, componentId: string) {
30
-    return this.nativeCommandsModule.popTo(commandId, componentId);
29
+  popTo(commandId: string, componentId: string, options: object) {
30
+    return this.nativeCommandsModule.popTo(commandId, componentId, options);
31
   }
31
   }
32
 
32
 
33
-  popToRoot(commandId: string, componentId: string) {
34
-    return this.nativeCommandsModule.popToRoot(commandId, componentId);
33
+  popToRoot(commandId: string, componentId: string, options: object) {
34
+    return this.nativeCommandsModule.popToRoot(commandId, componentId, options);
35
   }
35
   }
36
 
36
 
37
   setStackRoot(commandId: string, onComponentId: string, layout: object) {
37
   setStackRoot(commandId: string, onComponentId: string, layout: object) {
42
     return this.nativeCommandsModule.showModal(commandId, layout);
42
     return this.nativeCommandsModule.showModal(commandId, layout);
43
   }
43
   }
44
 
44
 
45
-  dismissModal(commandId: string, componentId: string) {
46
-    return this.nativeCommandsModule.dismissModal(commandId, componentId);
45
+  dismissModal(commandId: string, componentId: string, options: object) {
46
+    return this.nativeCommandsModule.dismissModal(commandId, componentId, options);
47
   }
47
   }
48
 
48
 
49
-  dismissAllModals(commandId: string) {
50
-    return this.nativeCommandsModule.dismissAllModals(commandId);
49
+  dismissAllModals(commandId: string, options: object) {
50
+    return this.nativeCommandsModule.dismissAllModals(commandId, options);
51
   }
51
   }
52
 
52
 
53
   showOverlay(commandId: string, layout: object) {
53
   showOverlay(commandId: string, layout: object) {

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

62
     return result;
62
     return result;
63
   }
63
   }
64
 
64
 
65
-  public dismissModal(componentId) {
65
+  public dismissModal(componentId, mergeOptions) {
66
     const commandId = this.uniqueIdProvider.generate('dismissModal');
66
     const commandId = this.uniqueIdProvider.generate('dismissModal');
67
-    const result = this.nativeCommandsSender.dismissModal(commandId, componentId);
68
-    this.commandsObserver.notify('dismissModal', { commandId, componentId });
67
+    const result = this.nativeCommandsSender.dismissModal(commandId, componentId, mergeOptions);
68
+    this.commandsObserver.notify('dismissModal', { commandId, componentId, mergeOptions});
69
     return result;
69
     return result;
70
   }
70
   }
71
 
71
 
72
-  public dismissAllModals() {
72
+  public dismissAllModals(mergeOptions) {
73
     const commandId = this.uniqueIdProvider.generate('dismissAllModals');
73
     const commandId = this.uniqueIdProvider.generate('dismissAllModals');
74
-    const result = this.nativeCommandsSender.dismissAllModals(commandId);
74
+    const result = this.nativeCommandsSender.dismissAllModals(commandId, mergeOptions);
75
     this.commandsObserver.notify('dismissAllModals', { commandId });
75
     this.commandsObserver.notify('dismissAllModals', { commandId });
76
     return result;
76
     return result;
77
   }
77
   }
88
     return result;
88
     return result;
89
   }
89
   }
90
 
90
 
91
-  public pop(componentId, options) {
91
+  public pop(componentId, mergeOptions) {
92
     const commandId = this.uniqueIdProvider.generate('pop');
92
     const commandId = this.uniqueIdProvider.generate('pop');
93
-    const result = this.nativeCommandsSender.pop(commandId, componentId, options);
94
-    this.commandsObserver.notify('pop', { commandId, componentId, options });
93
+    const result = this.nativeCommandsSender.pop(commandId, componentId, mergeOptions);
94
+    this.commandsObserver.notify('pop', { commandId, componentId, mergeOptions });
95
     return result;
95
     return result;
96
   }
96
   }
97
 
97
 
98
-  public popTo(componentId) {
98
+  public popTo(componentId, mergeOptions) {
99
     const commandId = this.uniqueIdProvider.generate('popTo');
99
     const commandId = this.uniqueIdProvider.generate('popTo');
100
-    const result = this.nativeCommandsSender.popTo(commandId, componentId);
101
-    this.commandsObserver.notify('popTo', { commandId, componentId });
100
+    const result = this.nativeCommandsSender.popTo(commandId, componentId, mergeOptions);
101
+    this.commandsObserver.notify('popTo', { commandId, componentId, mergeOptions });
102
     return result;
102
     return result;
103
   }
103
   }
104
 
104
 
105
-  public popToRoot(componentId) {
105
+  public popToRoot(componentId, mergeOptions) {
106
     const commandId = this.uniqueIdProvider.generate('popToRoot');
106
     const commandId = this.uniqueIdProvider.generate('popToRoot');
107
-    const result = this.nativeCommandsSender.popToRoot(commandId, componentId);
108
-    this.commandsObserver.notify('popToRoot', { commandId, componentId });
107
+    const result = this.nativeCommandsSender.popToRoot(commandId, componentId, mergeOptions);
108
+    this.commandsObserver.notify('popToRoot', { commandId, componentId, mergeOptions });
109
     return result;
109
     return result;
110
   }
110
   }
111
 
111