Search in sources :

Example 6 with ViewController

use of com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController in project react-native-navigation by wix.

the class LayoutFactory method createBottomTabs.

private ViewController<?> createBottomTabs(LayoutNode node) {
    List<ViewController<?>> tabs = map(node.children, this::create);
    BottomTabsPresenter bottomTabsPresenter = new BottomTabsPresenter(tabs, defaultOptions, new BottomTabsAnimator());
    return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, new ImageLoader(), node.id, parseOptions(node.getOptions()), new Presenter(activity, defaultOptions), new BottomTabsAttacher(tabs, bottomTabsPresenter, defaultOptions), bottomTabsPresenter, new BottomTabPresenter(activity, tabs, new ImageLoader(), new TypefaceLoader(activity), defaultOptions));
}
Also used : BottomTabsController(com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController) BottomTabPresenter(com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabPresenter) ComponentViewController(com.reactnativenavigation.viewcontrollers.component.ComponentViewController) ViewController(com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController) ExternalComponentViewController(com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController) StackPresenter(com.reactnativenavigation.viewcontrollers.stack.StackPresenter) BottomTabPresenter(com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabPresenter) BottomTabsPresenter(com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter) SideMenuPresenter(com.reactnativenavigation.viewcontrollers.sidemenu.SideMenuPresenter) Presenter(com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter) ExternalComponentPresenter(com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentPresenter) ComponentPresenter(com.reactnativenavigation.viewcontrollers.component.ComponentPresenter) TypefaceLoader(com.reactnativenavigation.options.parsers.TypefaceLoader) BottomTabsPresenter(com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter) BottomTabsAttacher(com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.BottomTabsAttacher) ImageLoader(com.reactnativenavigation.utils.ImageLoader) BottomTabsAnimator(com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsAnimator)

Example 7 with ViewController

use of com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController in project react-native-navigation by wix.

the class ParentControllerTest method beforeEach.

@Override
public void beforeEach() {
    super.beforeEach();
    activity = newActivity();
    childRegistry = new ChildControllersRegistry();
    children = new ArrayList<>();
    Options initialOptions = new Options();
    initialOptions.topBar.title.text = new Text(INITIAL_TITLE);
    presenter = spy(new Presenter(activity, new Options()));
    uut = spy(new ParentController<ViewGroup>(activity, childRegistry, "uut", presenter, initialOptions) {

        @Override
        public ViewController<?> getCurrentChild() {
            return children.get(0);
        }

        @NonNull
        @Override
        public ViewGroup createView() {
            FrameLayout layout = new FrameLayout(activity);
            for (ViewController<?> child : children) {
                child.setParentController(this);
                layout.addView(child.getView());
            }
            return layout;
        }

        @Override
        public void sendOnNavigationButtonPressed(String buttonId) {
        }

        @NonNull
        @Override
        public Collection<ViewController<?>> getChildControllers() {
            return children;
        }
    });
}
Also used : Options(com.reactnativenavigation.options.Options) SimpleViewController(com.reactnativenavigation.mocks.SimpleViewController) ViewController(com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController) Presenter(com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter) FrameLayout(android.widget.FrameLayout) ChildControllersRegistry(com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry) Text(com.reactnativenavigation.options.params.Text)

Example 8 with ViewController

use of com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController 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 9 with ViewController

use of com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController 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)

Example 10 with ViewController

use of com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController in project react-native-navigation by wix.

the class NavigationModuleTest method setRoot_delegatesToNavigator.

@Test
public void setRoot_delegatesToNavigator() throws JSONException {
    when(reactApplicationContext.getCurrentActivity()).thenReturn(activity);
    ReadableMap root = mock(ReadableMap.class);
    when(jsonParser.parse(root)).thenReturn(rootJson());
    ViewController rootViewController = mock(ViewController.class);
    when(layoutFactory.create(any(LayoutNode.class))).thenReturn(rootViewController);
    uut.setRoot("1", root, mock(Promise.class));
    ShadowLooper.idleMainLooper();
    verify(navigator).setRoot(eq(rootViewController), any(), any());
}
Also used : LayoutNode(com.reactnativenavigation.options.LayoutNode) Promise(com.facebook.react.bridge.Promise) ViewController(com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController) ReadableMap(com.facebook.react.bridge.ReadableMap) BaseTest(com.reactnativenavigation.BaseTest) Test(org.junit.Test)

Aggregations

ViewController (com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController)10 Options (com.reactnativenavigation.options.Options)4 Presenter (com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter)4 BaseTest (com.reactnativenavigation.BaseTest)3 SimpleViewController (com.reactnativenavigation.mocks.SimpleViewController)3 ComponentPresenter (com.reactnativenavigation.viewcontrollers.component.ComponentPresenter)3 ComponentViewController (com.reactnativenavigation.viewcontrollers.component.ComponentViewController)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FrameLayout (android.widget.FrameLayout)2 LayoutNode (com.reactnativenavigation.options.LayoutNode)2 BottomTabPresenter (com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabPresenter)2 BottomTabsPresenter (com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsPresenter)2 BottomTabsAttacher (com.reactnativenavigation.viewcontrollers.bottomtabs.attacher.BottomTabsAttacher)2 ExternalComponentPresenter (com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentPresenter)2 ExternalComponentViewController (com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController)2 SideMenuPresenter (com.reactnativenavigation.viewcontrollers.sidemenu.SideMenuPresenter)2 StackPresenter (com.reactnativenavigation.viewcontrollers.stack.StackPresenter)2 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1