Skip to content

Commit

Permalink
Fixed modalDismissed event being emitted with wrong id
Browse files Browse the repository at this point in the history
Event was emitted with parent id instead of the id provided by the user, which could be an id on one of the modals children.

fixes #4693
  • Loading branch information
guyca committed Feb 6, 2019
1 parent 77a861c commit aef7745
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public boolean dismissModal(String componentId, @Nullable ViewController root, C
CommandListenerAdapter onDismiss = new CommandListenerAdapter(listener) {
@Override
public void onSuccess(String childId) {
eventEmitter.emitModalDismissed(toDismiss.getId(), 1);
super.onSuccess(childId);
eventEmitter.emitModalDismissed(componentId, 1);
super.onSuccess(componentId);
}
};
if (isDismissingTopModal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
import com.reactnativenavigation.views.element.ElementTransitionManager;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

public class StackControllerBuilder {
private Activity activity;
Expand All @@ -32,6 +31,10 @@ public StackControllerBuilder(Activity activity) {
animator = new NavigationAnimator(activity, new ElementTransitionManager());
}

public StackControllerBuilder setChildren(ViewController... children) {
return setChildren(Arrays.asList(children));
}

public StackControllerBuilder setChildren(List<ViewController> children) {
this.children = children;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.*;
import com.reactnativenavigation.anim.ModalAnimator;
import com.reactnativenavigation.mocks.SimpleViewController;
import com.reactnativenavigation.parse.Options;
Expand All @@ -13,6 +13,7 @@
import com.reactnativenavigation.utils.CommandListenerAdapter;
import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
import com.reactnativenavigation.viewcontrollers.ViewController;
import com.reactnativenavigation.viewcontrollers.stack.*;

import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -34,16 +35,20 @@ public class ModalStackTest extends BaseTest {
private static final String MODAL_ID_1 = "modalId1";
private static final String MODAL_ID_2 = "modalId2";
private static final String MODAL_ID_3 = "modalId3";
private static final String MODAL_ID_4 = "modalId4";

private ModalStack uut;
private ViewController modal1;
private ViewController modal2;
private ViewController modal3;
private ViewController modal4;
private StackController stack;
private Activity activity;
private ChildControllersRegistry childRegistry;
private ModalPresenter presenter;
private ModalAnimator animator;
private ViewController root;
private EventEmitter emitter;

@Override
public void beforeEach() {
Expand All @@ -63,10 +68,15 @@ public void beforeEach() {
uut = new ModalStack(presenter);
uut.setModalsLayout(modalsLayout);
uut.setRootLayout(rootLayout);
uut.setEventEmitter(Mockito.mock(EventEmitter.class));
emitter = Mockito.mock(EventEmitter.class);
uut.setEventEmitter(emitter);
modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
modal3 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_3, new Options()));
modal4 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_4, new Options()));
stack = TestUtils.newStackController(activity)
.setChildren(modal4)
.build();
}

@Test
Expand Down Expand Up @@ -99,6 +109,15 @@ public void dismissModal() {
verify(listener).onSuccess(modal1.getId());
}

@Test
public void dismissModal_listenerAndEmitterAreInvokedWithGivenId() {
uut.showModal(stack, root, new CommandListenerAdapter());
CommandListener listener = spy(new CommandListenerAdapter());
uut.dismissModal(modal4.getId(), root, listener);
verify(listener).onSuccess(modal4.getId());
verify(emitter).emitModalDismissed(modal4.getId(), 1);
}

@SuppressWarnings("Convert2Lambda")
@Test
public void dismissModal_rejectIfModalNotFound() {
Expand Down

0 comments on commit aef7745

Please sign in to comment.