Browse Source

Stop rejecting on dismissAllModals if no modals are displayed (#5991)

This commit adds parity with iOS which does not reject the promise if dismissAllModals is called while no modals are displayed.
Guy Carmeli 4 years ago
parent
commit
30b0b47b71
No account linked to committer's email address

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

84
 
84
 
85
     public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) {
85
     public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) {
86
         if (modals.isEmpty()) {
86
         if (modals.isEmpty()) {
87
-            listener.onError("Nothing to dismiss");
88
             return;
87
             return;
89
         }
88
         }
90
-
91
         String topModalId = peek().getId();
89
         String topModalId = peek().getId();
92
         String topModalName = peek().getCurrentComponentName();
90
         String topModalName = peek().getCurrentComponentName();
93
         int modalsDismissed = size();
91
         int modalsDismissed = size();

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

1
 package com.reactnativenavigation.viewcontrollers.modal;
1
 package com.reactnativenavigation.viewcontrollers.modal;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
5
 import android.view.ViewGroup;
4
 import android.view.ViewGroup;
6
 import android.widget.FrameLayout;
5
 import android.widget.FrameLayout;
7
 
6
 
8
-import com.reactnativenavigation.*;
7
+import com.reactnativenavigation.BaseTest;
8
+import com.reactnativenavigation.TestUtils;
9
 import com.reactnativenavigation.anim.ModalAnimator;
9
 import com.reactnativenavigation.anim.ModalAnimator;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.utils.CommandListenerAdapter;
14
 import com.reactnativenavigation.utils.CommandListenerAdapter;
15
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
15
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
16
 import com.reactnativenavigation.viewcontrollers.ViewController;
16
 import com.reactnativenavigation.viewcontrollers.ViewController;
17
-import com.reactnativenavigation.viewcontrollers.stack.*;
17
+import com.reactnativenavigation.viewcontrollers.stack.StackController;
18
 
18
 
19
 import org.junit.Test;
19
 import org.junit.Test;
20
 import org.mockito.Mockito;
20
 import org.mockito.Mockito;
21
 
21
 
22
 import java.util.EmptyStackException;
22
 import java.util.EmptyStackException;
23
 
23
 
24
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
25
+
24
 import static org.assertj.core.api.Java6Assertions.assertThat;
26
 import static org.assertj.core.api.Java6Assertions.assertThat;
25
 import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
27
 import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
26
 import static org.mockito.ArgumentMatchers.any;
28
 import static org.mockito.ArgumentMatchers.any;
171
         verifyZeroInteractions(listener);
173
         verifyZeroInteractions(listener);
172
     }
174
     }
173
 
175
 
174
-    @Test
175
-    public void dismissAllModals_rejectIfEmpty() {
176
-        CommandListener spy = spy(new CommandListenerAdapter());
177
-        uut.dismissAllModals(root, Options.EMPTY, spy);
178
-        verify(spy, times(1)).onError(any());
179
-    }
180
-
181
     @Test
176
     @Test
182
     public void dismissAllModals_optionsAreMergedOnTopModal() {
177
     public void dismissAllModals_optionsAreMergedOnTopModal() {
183
         uut.showModal(modal1, root, new CommandListenerAdapter());
178
         uut.showModal(modal1, root, new CommandListenerAdapter());