Browse Source

Fix crash when dismissAllModals is called before root is set

Guy Carmeli 4 years ago
parent
commit
52bcd5ba50

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

14
 import java.util.EmptyStackException;
14
 import java.util.EmptyStackException;
15
 import java.util.List;
15
 import java.util.List;
16
 
16
 
17
-import javax.annotation.Nullable;
18
-
17
+import androidx.annotation.Nullable;
19
 import androidx.annotation.RestrictTo;
18
 import androidx.annotation.RestrictTo;
20
 import androidx.coordinatorlayout.widget.CoordinatorLayout;
19
 import androidx.coordinatorlayout.widget.CoordinatorLayout;
21
 
20
 
21
+import static com.reactnativenavigation.utils.ObjectUtils.perform;
22
+
22
 public class ModalStack {
23
 public class ModalStack {
23
     private List<ViewController> modals = new ArrayList<>();
24
     private List<ViewController> modals = new ArrayList<>();
24
     private final ModalPresenter presenter;
25
     private final ModalPresenter presenter;
82
         }
83
         }
83
     }
84
     }
84
 
85
 
85
-    public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) {
86
+    public void dismissAllModals(@Nullable ViewController root, Options mergeOptions, CommandListener listener) {
86
         if (modals.isEmpty()) {
87
         if (modals.isEmpty()) {
87
-            listener.onSuccess(root.getId());
88
+            listener.onSuccess(perform(root, "", ViewController::getId));
88
             return;
89
             return;
89
         }
90
         }
90
         String topModalId = peek().getId();
91
         String topModalId = peek().getId();

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

173
         verifyZeroInteractions(listener);
173
         verifyZeroInteractions(listener);
174
     }
174
     }
175
 
175
 
176
+    @Test
177
+    public void dismissAllModal_resolvesPromiseSuccessfullyWhenCalledBeforeRootIsSet() {
178
+        CommandListenerAdapter spy = new CommandListenerAdapter();
179
+        uut.dismissAllModals(null, Options.EMPTY, spy);
180
+        verify(spy).onSuccess("");
181
+    }
182
+
176
     @Test
183
     @Test
177
     public void dismissAllModals_resolveSuccessfullyIfEmpty() {
184
     public void dismissAllModals_resolveSuccessfullyIfEmpty() {
178
         CommandListener spy = spy(new CommandListenerAdapter());
185
         CommandListener spy = spy(new CommandListenerAdapter());