Browse Source

Always resolve dismissAllModals promise (#6054)

When no modals are displayed and dismissAllModals is called, resolve the promise successfully. This regression was introduced in #5991
Guy Carmeli 4 years ago
parent
commit
ec03383b0d
No account linked to committer's email address

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

@@ -84,6 +84,7 @@ public class ModalStack {
84 84
 
85 85
     public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) {
86 86
         if (modals.isEmpty()) {
87
+            listener.onSuccess(root.getId());
87 88
             return;
88 89
         }
89 90
         String topModalId = peek().getId();

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

@@ -173,6 +173,13 @@ public class ModalStackTest extends BaseTest {
173 173
         verifyZeroInteractions(listener);
174 174
     }
175 175
 
176
+    @Test
177
+    public void dismissAllModals_resolveSuccessfullyIfEmpty() {
178
+        CommandListener spy = spy(new CommandListenerAdapter());
179
+        uut.dismissAllModals(root, Options.EMPTY, spy);
180
+        verify(spy, times(1)).onSuccess(root.getId());
181
+    }
182
+
176 183
     @Test
177 184
     public void dismissAllModals_optionsAreMergedOnTopModal() {
178 185
         uut.showModal(modal1, root, new CommandListenerAdapter());

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

@@ -596,6 +596,7 @@ public class NavigatorTest extends BaseTest {
596 596
     public void dismissAllModals_onViewAppearedInvokedOnRoot() {
597 597
         disablePushAnimation(child2);
598 598
         disableShowModalAnimation(child1);
599
+        uut.setRoot(child3, new CommandListenerAdapter(), reactInstanceManager);
599 600
 
600 601
         uut.dismissAllModals(Options.EMPTY, new CommandListenerAdapter());
601 602
         verify(parentVisibilityListener, times(0)).onViewAppeared(parentController.getView());