Search in sources :

Example 6 with CommandListener

use of com.reactnativenavigation.react.CommandListener in project react-native-navigation by wix.

the class OverlayManagerTest method dismiss_rejectIfOverlayNotFound.

@Test
public void dismiss_rejectIfOverlayNotFound() {
    CommandListener listener = spy(new CommandListenerAdapter());
    uut.dismiss(overlayContainer, overlay1.getId(), listener);
    verify(listener, times(1)).onError(any());
}
Also used : CommandListener(com.reactnativenavigation.react.CommandListener) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 7 with CommandListener

use of com.reactnativenavigation.react.CommandListener in project react-native-navigation by wix.

the class StackController method setRoot.

public void setRoot(@Size(min = 1) List<ViewController<?>> children, CommandListener listener) {
    if (!isViewCreated()) {
        setChildren(children);
        return;
    }
    animator.cancelPushAnimations();
    final ViewController<?> toRemove = stack.peek();
    IdStack<?> stackToDestroy = stack;
    stack = new IdStack<>();
    ViewController<?> child = requireLast(children);
    if (children.size() == 1) {
        backButtonHelper.clear(child);
    } else {
        backButtonHelper.addToPushedChild(child);
    }
    child.setParentController(this);
    stack.push(child.getId(), child);
    Options resolvedOptions = resolveCurrentOptions(presenter.getDefaultOptions());
    addChildToStack(child, resolvedOptions);
    CommandListener listenerAdapter = new CommandListenerAdapter() {

        @Override
        public void onSuccess(String childId) {
            if (child.isViewShown())
                child.onViewDidAppear();
            destroyStack(stackToDestroy);
            if (children.size() > 1) {
                for (int i = 0; i < children.size() - 1; i++) {
                    stack.set(children.get(i).getId(), children.get(i), i);
                    children.get(i).setParentController(StackController.this);
                    if (i == 0) {
                        backButtonHelper.clear(children.get(i));
                    } else {
                        backButtonHelper.addToPushedChild(children.get(i));
                    }
                }
                startChildrenBellowTopChild();
            }
            listener.onSuccess(childId);
        }
    };
    if (toRemove != null && resolvedOptions.animations.setStackRoot.enabled.isTrueOrUndefined()) {
        if (resolvedOptions.animations.setStackRoot.waitForRender.isTrue()) {
            child.getView().setAlpha(0);
            child.addOnAppearedListener(() -> animator.setRoot(child, toRemove, resolvedOptions, presenter.getAdditionalSetRootAnimations(this, child, resolvedOptions), () -> listenerAdapter.onSuccess(child.getId())));
        } else {
            animator.setRoot(child, toRemove, resolvedOptions, presenter.getAdditionalSetRootAnimations(this, child, resolvedOptions), () -> listenerAdapter.onSuccess(child.getId()));
        }
    } else {
        listenerAdapter.onSuccess(child.getId());
    }
}
Also used : ButtonOptions(com.reactnativenavigation.options.ButtonOptions) StackAnimationOptions(com.reactnativenavigation.options.StackAnimationOptions) Options(com.reactnativenavigation.options.Options) CommandListener(com.reactnativenavigation.react.CommandListener) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter)

Example 8 with CommandListener

use of com.reactnativenavigation.react.CommandListener in project react-native-navigation by wix.

the class ModalPresenterTest method showModal_noAnimation.

@Test
public void showModal_noAnimation() {
    disableShowModalAnimation(modal1);
    CommandListener listener = spy(new CommandListenerAdapter() {

        @Override
        public void onSuccess(String childId) {
            Shadows.shadowOf(Looper.getMainLooper()).idle();
            assertThat(modal1.getView().getParent()).isEqualTo(modalsLayout);
            verify(modal1).onViewWillAppear();
        }
    });
    uut.showModal(modal1, root, listener);
    verify(animator, never()).show(eq(modal1), eq(root), eq(modal1.options.animations.showModal), any());
    verify(listener).onSuccess(MODAL_ID_1);
}
Also used : CommandListener(com.reactnativenavigation.react.CommandListener) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 9 with CommandListener

use of com.reactnativenavigation.react.CommandListener in project react-native-navigation by wix.

the class ModalStackTest method dismissModal.

@Test
public void dismissModal() {
    uut.showModal(modal1, root, new CommandListenerAdapter());
    CommandListener listener = spy(new CommandListenerAdapter());
    uut.dismissModal(modal1.getId(), root, listener);
    assertThat(findModal(modal1.getId())).isNull();
    verify(presenter).dismissModal(eq(modal1), eq(root), eq(root), any());
    verify(listener).onSuccess(modal1.getId());
}
Also used : CommandListener(com.reactnativenavigation.react.CommandListener) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 10 with CommandListener

use of com.reactnativenavigation.react.CommandListener in project react-native-navigation by wix.

the class OverlayManagerTest method dismiss.

@Test
public void dismiss() {
    uut.show(overlayContainer, overlay1, new CommandListenerAdapter());
    assertThat(uut.size()).isOne();
    CommandListener listener = spy(new CommandListenerAdapter());
    uut.dismiss(overlayContainer, overlay1.getId(), listener);
    assertThat(uut.size()).isZero();
    verify(listener, times(1)).onSuccess(OVERLAY_ID_1);
    verify(overlay1, times(1)).destroy();
}
Also used : CommandListener(com.reactnativenavigation.react.CommandListener) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Aggregations

CommandListener (com.reactnativenavigation.react.CommandListener)16 BaseTest (com.reactnativenavigation.BaseTest)15 CommandListenerAdapter (com.reactnativenavigation.react.CommandListenerAdapter)15 Test (org.junit.Test)15 Options (com.reactnativenavigation.options.Options)3 TransitionAnimationOptions (com.reactnativenavigation.options.TransitionAnimationOptions)2 SimpleViewController (com.reactnativenavigation.mocks.SimpleViewController)1 ButtonOptions (com.reactnativenavigation.options.ButtonOptions)1 StackAnimationOptions (com.reactnativenavigation.options.StackAnimationOptions)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1