Search in sources :

Example 1 with Options

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

the class OptionsApplyingTest method reappliesOptionsOnMerge.

@Test
public void reappliesOptionsOnMerge() {
    assertThat(stack.getTopBar().getTitle()).isEmpty();
    stack.push(uut, new CommandListenerAdapter());
    Options opts = new Options();
    opts.topBar.title.text = new Text("the new title");
    uut.mergeOptions(opts);
    assertThat(stack.getTopBar().getTitle()).isEqualTo("the new title");
}
Also used : Options(com.reactnativenavigation.options.Options) Text(com.reactnativenavigation.options.params.Text) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 2 with Options

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

the class OptionsApplyingTest method beforeEach.

@Override
public void beforeEach() {
    super.beforeEach();
    activity = newActivity();
    initialNavigationOptions = new Options();
    view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
    view.asView().setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    uut = new ComponentViewController(activity, new ChildControllersRegistry(), "componentId1", "componentName", (activity1, componentId, componentName) -> view, initialNavigationOptions, new Presenter(activity, new Options()), new ComponentPresenter(Options.EMPTY)) {

        @Override
        public boolean isViewShown() {
            return true;
        }
    };
    TopBarController topBarController = new TopBarController() {

        @Override
        protected TopBar createTopBar(Context context, StackLayout stackLayout) {
            topBar = spy(super.createTopBar(context, stackLayout));
            return topBar;
        }
    };
    stack = TestUtils.newStackController(activity).setTopBarController(topBarController).build();
    stack.ensureViewIsCreated();
    stack.getView().layout(0, 0, 1000, 1000);
    stack.getTopBar().layout(0, 0, 1000, 100);
    activity.setContentView(stack.getView());
    disablePushAnimation(uut);
}
Also used : StackController(com.reactnativenavigation.viewcontrollers.stack.StackController) TopBar(com.reactnativenavigation.views.stack.topbar.TopBar) Context(android.content.Context) Text(com.reactnativenavigation.options.params.Text) CommandListenerAdapter(com.reactnativenavigation.react.CommandListenerAdapter) StackLayout(com.reactnativenavigation.views.stack.StackLayout) Java6Assertions.assertThat(org.assertj.core.api.Java6Assertions.assertThat) IReactView(com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView) ColorDrawable(android.graphics.drawable.ColorDrawable) Colour(com.reactnativenavigation.options.params.Colour) Mockito.spy(org.mockito.Mockito.spy) ComponentViewController(com.reactnativenavigation.viewcontrollers.component.ComponentViewController) TopBarController(com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarController) View(android.view.View) Bool(com.reactnativenavigation.options.params.Bool) BaseTest(com.reactnativenavigation.BaseTest) MATCH_PARENT(android.view.ViewGroup.LayoutParams.MATCH_PARENT) Test(org.junit.Test) Presenter(com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter) Color(android.graphics.Color) ChildControllersRegistry(com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry) TestReactView(com.reactnativenavigation.mocks.TestReactView) ThemeColour(com.reactnativenavigation.options.params.ThemeColour) Options(com.reactnativenavigation.options.Options) Configuration(android.content.res.Configuration) ComponentPresenter(com.reactnativenavigation.viewcontrollers.component.ComponentPresenter) TestUtils(com.reactnativenavigation.TestUtils) RelativeLayout(android.widget.RelativeLayout) TestComponentLayout(com.reactnativenavigation.mocks.TestComponentLayout) Activity(android.app.Activity) Context(android.content.Context) Options(com.reactnativenavigation.options.Options) TestReactView(com.reactnativenavigation.mocks.TestReactView) ChildControllersRegistry(com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry) ComponentPresenter(com.reactnativenavigation.viewcontrollers.component.ComponentPresenter) Presenter(com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter) ComponentPresenter(com.reactnativenavigation.viewcontrollers.component.ComponentPresenter) TestComponentLayout(com.reactnativenavigation.mocks.TestComponentLayout) RelativeLayout(android.widget.RelativeLayout) StackLayout(com.reactnativenavigation.views.stack.StackLayout) ComponentViewController(com.reactnativenavigation.viewcontrollers.component.ComponentViewController) TopBarController(com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarController)

Example 3 with Options

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

the class OptionsApplyingTest method mergeNavigationOptionsUpdatesCurrentOptions.

@Test
public void mergeNavigationOptionsUpdatesCurrentOptions() {
    assertThat(uut.options.topBar.title.text.get("")).isEmpty();
    Options options = new Options();
    options.topBar.title.text = new Text("new title");
    uut.mergeOptions(options);
    assertThat(uut.options.topBar.title.text.get()).isEqualTo("new title");
}
Also used : Options(com.reactnativenavigation.options.Options) Text(com.reactnativenavigation.options.params.Text) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 4 with Options

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

the class StackController method push.

public void push(ViewController<?> child, CommandListener listener) {
    if (findController(child.getId()) != null) {
        listener.onError("A stack can't contain two children with the same id: " + child.getId());
        return;
    }
    final ViewController<?> toRemove = stack.peek();
    if (size() > 0)
        backButtonHelper.addToPushedChild(child);
    child.setParentController(this);
    stack.push(child.getId(), child);
    if (!isViewCreated())
        return;
    Options resolvedOptions = resolveCurrentOptions(presenter.getDefaultOptions());
    addChildToStack(child, resolvedOptions);
    if (toRemove != null) {
        StackAnimationOptions animation = resolvedOptions.animations.push;
        if (animation.enabled.isTrueOrUndefined()) {
            animator.push(child, toRemove, resolvedOptions, presenter.getAdditionalPushAnimations(this, child, resolvedOptions), () -> onPushAnimationComplete(child, toRemove, listener));
        } else {
            onPushAnimationComplete(child, toRemove, listener);
        }
    } else {
        listener.onSuccess(child.getId());
    }
}
Also used : ButtonOptions(com.reactnativenavigation.options.ButtonOptions) StackAnimationOptions(com.reactnativenavigation.options.StackAnimationOptions) Options(com.reactnativenavigation.options.Options) StackAnimationOptions(com.reactnativenavigation.options.StackAnimationOptions)

Example 5 with Options

use of com.reactnativenavigation.options.Options 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)

Aggregations

Options (com.reactnativenavigation.options.Options)110 BaseTest (com.reactnativenavigation.BaseTest)57 Test (org.junit.Test)57 SimpleViewController (com.reactnativenavigation.mocks.SimpleViewController)32 SideMenuOptions (com.reactnativenavigation.options.SideMenuOptions)19 CommandListenerAdapter (com.reactnativenavigation.react.CommandListenerAdapter)18 ChildControllersRegistry (com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry)16 Bool (com.reactnativenavigation.options.params.Bool)15 Text (com.reactnativenavigation.options.params.Text)15 OrientationOptions (com.reactnativenavigation.options.OrientationOptions)10 AnimationOptions (com.reactnativenavigation.options.AnimationOptions)9 ButtonOptions (com.reactnativenavigation.options.ButtonOptions)9 FrameLayout (android.widget.FrameLayout)8 SimpleComponentViewController (com.reactnativenavigation.mocks.SimpleComponentViewController)8 Presenter (com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter)8 ComponentOptions (com.reactnativenavigation.options.ComponentOptions)6 TopBarOptions (com.reactnativenavigation.options.TopBarOptions)6 TopTabOptions (com.reactnativenavigation.options.TopTabOptions)6 TopTabsOptions (com.reactnativenavigation.options.TopTabsOptions)6 Activity (android.app.Activity)5