Search in sources :

Example 71 with Options

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

the class ParentControllerTest method resolveCurrentOptions_mergesWithCurrentChild.

@Test
public void resolveCurrentOptions_mergesWithCurrentChild() {
    ViewController child1 = Mockito.mock(ViewController.class);
    when(child1.getView()).thenReturn(new FrameLayout(activity));
    Options copiedChildOptions = spy(new Options());
    Options childOptions = spy(new Options() {

        @Override
        public Options copy() {
            return copiedChildOptions;
        }
    });
    when(child1.resolveCurrentOptions()).thenReturn(childOptions);
    children.add(child1);
    uut.ensureViewIsCreated();
    assertThat(uut.getCurrentChild()).isEqualTo(child1);
    uut.resolveCurrentOptions();
    verify(child1).resolveCurrentOptions();
    verify(copiedChildOptions).withDefaultOptions(uut.initialOptions);
}
Also used : Options(com.reactnativenavigation.options.Options) SimpleViewController(com.reactnativenavigation.mocks.SimpleViewController) ViewController(com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController) FrameLayout(android.widget.FrameLayout) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Example 72 with Options

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

the class StackController method pop.

public void pop(Options mergeOptions, CommandListener listener) {
    if (!canPop()) {
        listener.onError("Nothing to pop");
        return;
    }
    peek().mergeOptions(mergeOptions);
    Options disappearingOptions = resolveCurrentOptions(presenter.getDefaultOptions());
    final ViewController<?> disappearing = stack.pop();
    if (!isViewCreated())
        return;
    final ViewController<?> appearing = stack.peek();
    disappearing.onViewWillDisappear();
    ViewGroup appearingView = appearing.getView();
    if (appearingView.getLayoutParams() == null) {
        appearingView.setLayoutParams(matchParentWithBehaviour(new StackBehaviour(this)));
    }
    if (appearingView.getParent() == null) {
        getView().addView(appearingView, 0);
    }
    if (disappearingOptions.animations.pop.enabled.isTrueOrUndefined()) {
        Options appearingOptions = resolveChildOptions(appearing).withDefaultOptions(presenter.getDefaultOptions());
        animator.pop(appearing, disappearing, disappearingOptions, presenter.getAdditionalPopAnimations(appearingOptions, disappearingOptions), () -> finishPopping(appearing, disappearing, listener));
    } else {
        finishPopping(appearing, disappearing, listener);
    }
}
Also used : ButtonOptions(com.reactnativenavigation.options.ButtonOptions) StackAnimationOptions(com.reactnativenavigation.options.StackAnimationOptions) Options(com.reactnativenavigation.options.Options) StackBehaviour(com.reactnativenavigation.views.stack.StackBehaviour) ViewGroup(android.view.ViewGroup)

Example 73 with Options

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

the class StackPresenter method applyInitialChildLayoutOptions.

public void applyInitialChildLayoutOptions(Options options) {
    Options withDefault = options.copy().withDefaultOptions(defaultOptions);
    applyTopBarVisibility(withDefault.topBar);
}
Also used : TopTabOptions(com.reactnativenavigation.options.TopTabOptions) ComponentOptions(com.reactnativenavigation.options.ComponentOptions) ButtonOptions(com.reactnativenavigation.options.ButtonOptions) TopBarOptions(com.reactnativenavigation.options.TopBarOptions) AnimationOptions(com.reactnativenavigation.options.AnimationOptions) TopTabsOptions(com.reactnativenavigation.options.TopTabsOptions) OrientationOptions(com.reactnativenavigation.options.OrientationOptions) Options(com.reactnativenavigation.options.Options)

Example 74 with Options

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

the class StackPresenter method applyTopBarOptions.

private void applyTopBarOptions(Options options, StackController stack, ViewController<?> child) {
    final View component = child.getView();
    TopBarOptions topBarOptions = options.topBar;
    Options withDefault = stack.resolveChildOptions(child).withDefaultOptions(defaultOptions);
    topBar.setTestId(topBarOptions.testId.get(""));
    topBar.setLayoutDirection(options.layout.direction);
    applyStatusBarDrawBehindOptions(topBarOptions, withDefault);
    topBar.setElevation(topBarOptions.elevation.get(DEFAULT_ELEVATION));
    if (topBarOptions.topMargin.hasValue() && topBar.getLayoutParams() instanceof MarginLayoutParams) {
        ((MarginLayoutParams) topBar.getLayoutParams()).topMargin = UiUtils.dpToPx(activity, topBarOptions.topMargin.get(0));
    }
    topBar.setTitleHeight(topBarOptions.title.height.get(UiUtils.getTopBarHeightDp(activity)));
    topBar.setTitleTopMargin(topBarOptions.title.topMargin.get(0));
    if (topBarOptions.title.component.hasValue()) {
        if (titleControllers.containsKey(component)) {
            topBarController.setTitleComponent(Objects.requireNonNull(titleControllers.get(component)));
        } else {
            TitleBarReactViewController controller = new TitleBarReactViewController(activity, titleViewCreator, topBarOptions.title.component);
            controller.setWaitForRender(topBarOptions.title.component.waitForRender);
            titleControllers.put(component, controller);
            topBarController.setTitleComponent(controller);
        }
        topBarController.alignTitleComponent(topBarOptions.title.component.alignment);
    } else {
        topBar.applyTitleOptions(topBarOptions.title, typefaceLoader);
        topBar.applySubtitleOptions(topBarOptions.subtitle, typefaceLoader);
        topBarController.alignTitleComponent(topBarOptions.title.alignment);
    }
    topBar.setBorderHeight(topBarOptions.borderHeight.get(0d));
    topBar.setBorderColor(topBarOptions.borderColor.get(DEFAULT_BORDER_COLOR));
    topBar.setBackgroundColor(topBarOptions.background.color.get(Color.WHITE));
    if (topBarOptions.background.component.hasValue()) {
        View createdComponent = findBackgroundComponent(topBarOptions.background.component);
        if (createdComponent != null) {
            topBar.setBackgroundComponent(createdComponent);
        } else {
            TopBarBackgroundViewController controller = new TopBarBackgroundViewController(activity, topBarBackgroundViewCreator);
            controller.setWaitForRender(topBarOptions.background.waitForRender);
            backgroundControllers.put(component, controller);
            controller.setComponent(topBarOptions.background.component);
            controller.getView().setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
            topBar.setBackgroundComponent(controller.getView());
        }
    } else {
        topBar.clearBackgroundComponent();
    }
    applyTopBarVisibilityIfChildIsNotBeingAnimated(topBarOptions, stack, child);
    if (topBarOptions.hideOnScroll.isTrue()) {
        if (component instanceof IReactView) {
            topBar.enableCollapse(((IReactView) component).getScrollEventListener());
        }
    } else if (topBarOptions.hideOnScroll.isFalseOrUndefined()) {
        topBar.disableCollapse();
    }
}
Also used : IReactView(com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView) TopTabOptions(com.reactnativenavigation.options.TopTabOptions) ComponentOptions(com.reactnativenavigation.options.ComponentOptions) ButtonOptions(com.reactnativenavigation.options.ButtonOptions) TopBarOptions(com.reactnativenavigation.options.TopBarOptions) AnimationOptions(com.reactnativenavigation.options.AnimationOptions) TopTabsOptions(com.reactnativenavigation.options.TopTabsOptions) OrientationOptions(com.reactnativenavigation.options.OrientationOptions) Options(com.reactnativenavigation.options.Options) TopBarOptions(com.reactnativenavigation.options.TopBarOptions) TitleBarReactViewController(com.reactnativenavigation.viewcontrollers.stack.topbar.title.TitleBarReactViewController) RelativeLayout(android.widget.RelativeLayout) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) View(android.view.View) IReactView(com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView) TopBarBackgroundViewController(com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarBackgroundViewController)

Example 75 with Options

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

the class StackPresenter method mergeTopBarOptions.

private void mergeTopBarOptions(TopBarOptions resolveOptions, Options toMerge, StackController stack, ViewController<?> child) {
    TopBarOptions topBarOptions = toMerge.topBar;
    final View component = child.getView();
    if (toMerge.layout.direction.hasValue())
        topBar.setLayoutDirection(toMerge.layout.direction);
    if (topBarOptions.height.hasValue())
        topBar.setHeight(topBarOptions.height.get());
    if (topBarOptions.elevation.hasValue())
        topBar.setElevation(topBarOptions.elevation.get());
    if (topBarOptions.topMargin.hasValue() && topBar.getLayoutParams() instanceof MarginLayoutParams) {
        ((MarginLayoutParams) topBar.getLayoutParams()).topMargin = UiUtils.dpToPx(activity, topBarOptions.topMargin.get());
    }
    Options childOptions = stack.resolveChildOptions(child).mergeWith(toMerge).withDefaultOptions(defaultOptions);
    mergeStatusBarDrawBehindOptions(resolveOptions, childOptions);
    if (topBarOptions.title.height.hasValue())
        topBar.setTitleHeight(topBarOptions.title.height.get());
    if (topBarOptions.title.topMargin.hasValue())
        topBar.setTitleTopMargin(topBarOptions.title.topMargin.get());
    if (topBarOptions.animateLeftButtons.hasValue())
        topBar.animateLeftButtons(topBarOptions.animateLeftButtons.isTrue());
    if (topBarOptions.animateRightButtons.hasValue())
        topBar.animateRightButtons(topBarOptions.animateRightButtons.isTrue());
    if (topBarOptions.title.component.hasValue()) {
        TitleBarReactViewController controller = findTitleComponent(topBarOptions.title.component);
        if (controller == null) {
            controller = new TitleBarReactViewController(activity, titleViewCreator, topBarOptions.title.component);
            perform(titleControllers.put(component, controller), ViewController::destroy);
        }
        topBarController.setTitleComponent(controller);
        topBarController.alignTitleComponent(topBarOptions.title.component.alignment);
    } else if (topBarOptions.title.text.hasValue()) {
        perform(titleControllers.remove(component), ViewController::destroy);
        topBar.setTitle(topBarOptions.title.text.get());
        topBarController.alignTitleComponent(topBarOptions.title.alignment);
    }
    if (resolveOptions.title.alignment != Alignment.Default) {
        topBarController.alignTitleComponent(resolveOptions.title.alignment);
    }
    if (resolveOptions.title.color.hasValue())
        topBar.setTitleTextColor(resolveOptions.title.color.get());
    if (resolveOptions.title.fontSize.hasValue())
        topBar.setTitleFontSize(resolveOptions.title.fontSize.get());
    if (resolveOptions.title.font.hasValue())
        topBar.setTitleTypeface(typefaceLoader, resolveOptions.title.font);
    if (resolveOptions.subtitle.text.hasValue()) {
        topBar.setSubtitle(resolveOptions.subtitle.text.get());
        topBar.setSubtitleAlignment(resolveOptions.subtitle.alignment);
    }
    if (resolveOptions.subtitle.color.hasValue())
        topBar.setSubtitleColor(resolveOptions.subtitle.color.get());
    if (resolveOptions.subtitle.fontSize.hasValue()) {
        topBar.setSubtitleFontSize(resolveOptions.subtitle.fontSize.get());
    }
    if (resolveOptions.subtitle.font.hasValue()) {
        topBar.setSubtitleTypeface(typefaceLoader, resolveOptions.subtitle.font);
    }
    if (topBarOptions.background.color.hasValue())
        topBar.setBackgroundColor(topBarOptions.background.color.get());
    if (topBarOptions.background.component.hasValue()) {
        if (backgroundControllers.containsKey(component)) {
            topBar.setBackgroundComponent(Objects.requireNonNull(backgroundControllers.get(component)).getView());
        } else {
            TopBarBackgroundViewController controller = new TopBarBackgroundViewController(activity, topBarBackgroundViewCreator);
            backgroundControllers.put(component, controller);
            controller.setComponent(topBarOptions.background.component);
            controller.getView().setLayoutParams(new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
            topBar.setBackgroundComponent(controller.getView());
        }
    }
    if (topBarOptions.testId.hasValue())
        topBar.setTestId(topBarOptions.testId.get());
    if (topBarOptions.visible.isFalse()) {
        if (topBarOptions.animate.isTrueOrUndefined()) {
            topBarController.hideAnimate(new AnimationOptions(), getTopBarTranslationAnimationDelta(stack, child));
        } else {
            topBarController.hide();
        }
    }
    if (topBarOptions.visible.isTrue()) {
        if (topBarOptions.animate.isTrueOrUndefined()) {
            topBarController.showAnimate(new AnimationOptions(), getTopBarTranslationAnimationDelta(stack, child));
        } else {
            topBarController.show();
        }
    }
    if (topBarOptions.hideOnScroll.isTrue() && component instanceof IReactView) {
        topBar.enableCollapse(((IReactView) component).getScrollEventListener());
    }
    if (topBarOptions.hideOnScroll.isFalse()) {
        topBar.disableCollapse();
    }
}
Also used : IReactView(com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView) TopTabOptions(com.reactnativenavigation.options.TopTabOptions) ComponentOptions(com.reactnativenavigation.options.ComponentOptions) ButtonOptions(com.reactnativenavigation.options.ButtonOptions) TopBarOptions(com.reactnativenavigation.options.TopBarOptions) AnimationOptions(com.reactnativenavigation.options.AnimationOptions) TopTabsOptions(com.reactnativenavigation.options.TopTabsOptions) OrientationOptions(com.reactnativenavigation.options.OrientationOptions) Options(com.reactnativenavigation.options.Options) TopBarOptions(com.reactnativenavigation.options.TopBarOptions) TitleBarReactViewController(com.reactnativenavigation.viewcontrollers.stack.topbar.title.TitleBarReactViewController) TopBarBackgroundViewController(com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarBackgroundViewController) ViewController(com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController) AnimationOptions(com.reactnativenavigation.options.AnimationOptions) TitleBarReactViewController(com.reactnativenavigation.viewcontrollers.stack.topbar.title.TitleBarReactViewController) RelativeLayout(android.widget.RelativeLayout) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) View(android.view.View) IReactView(com.reactnativenavigation.viewcontrollers.viewcontroller.IReactView) TopBarBackgroundViewController(com.reactnativenavigation.viewcontrollers.stack.topbar.TopBarBackgroundViewController)

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