Skip to content

Commit

Permalink
Fix crash when dismissAllModals is called before root is set
Browse files Browse the repository at this point in the history
  • Loading branch information
guyca committed Mar 26, 2020
1 parent d2f7f6d commit 52bcd5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import java.util.EmptyStackException;
import java.util.List;

import javax.annotation.Nullable;

import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

import static com.reactnativenavigation.utils.ObjectUtils.perform;

public class ModalStack {
private List<ViewController> modals = new ArrayList<>();
private final ModalPresenter presenter;
Expand Down Expand Up @@ -82,9 +83,9 @@ public void onSuccess(String childId) {
}
}

public void dismissAllModals(ViewController root, Options mergeOptions, CommandListener listener) {
public void dismissAllModals(@Nullable ViewController root, Options mergeOptions, CommandListener listener) {
if (modals.isEmpty()) {
listener.onSuccess(root.getId());
listener.onSuccess(perform(root, "", ViewController::getId));
return;
}
String topModalId = peek().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ public void onSuccess(String childId) {
verifyZeroInteractions(listener);
}

@Test
public void dismissAllModal_resolvesPromiseSuccessfullyWhenCalledBeforeRootIsSet() {
CommandListenerAdapter spy = new CommandListenerAdapter();
uut.dismissAllModals(null, Options.EMPTY, spy);
verify(spy).onSuccess("");
}

@Test
public void dismissAllModals_resolveSuccessfullyIfEmpty() {
CommandListener spy = spy(new CommandListenerAdapter());
Expand Down

0 comments on commit 52bcd5b

Please sign in to comment.