diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/parse/BackButton.java b/lib/android/app/src/main/java/com/reactnativenavigation/parse/BackButton.java index 6b1a4f99b0e..1cdee510af3 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/parse/BackButton.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/parse/BackButton.java @@ -65,4 +65,9 @@ public void setVisible() { visible = new Bool(true); hasValue = true; } + + public void setHidden() { + visible = new Bool(false); + hasValue = true; + } } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java b/lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java index 26b77b44f20..eb3cf3f7631 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java @@ -20,6 +20,7 @@ import com.reactnativenavigation.viewcontrollers.ViewController; import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsAttacher; import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController; +import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver; import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator; import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController; import com.reactnativenavigation.viewcontrollers.sidemenu.SideMenuController; @@ -186,7 +187,7 @@ private ViewController createStack(LayoutNode node) { new TitleBarReactViewCreator(reactInstanceManager), new TopBarBackgroundViewCreator(reactInstanceManager), new TitleBarButtonCreator(reactInstanceManager), - new ImageLoader(), + new NavigationIconResolver(activity, new ImageLoader()), new RenderChecker(), defaultOptions )) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java b/lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java index 8147225adad..7bdeb4c2760 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackPresenter.java @@ -21,7 +21,6 @@ import com.reactnativenavigation.parse.params.Colour; import com.reactnativenavigation.utils.ButtonPresenter; import com.reactnativenavigation.utils.CollectionUtils; -import com.reactnativenavigation.utils.ImageLoader; import com.reactnativenavigation.utils.ObjectUtils; import com.reactnativenavigation.utils.StatusBarUtils; import com.reactnativenavigation.utils.UiUtils; @@ -65,7 +64,6 @@ public class StackPresenter { private TopBarController topBarController; private final TitleBarReactViewCreator titleViewCreator; private TitleBarButtonController.OnClickListener onClickListener; - private final ImageLoader imageLoader; private final RenderChecker renderChecker; private final TopBarBackgroundViewCreator topBarBackgroundViewCreator; private final ReactViewCreator buttonCreator; @@ -76,19 +74,20 @@ public class StackPresenter { private Map backgroundControllers = new HashMap(); private Map> componentRightButtons = new HashMap(); private Map> componentLeftButtons = new HashMap(); + private NavigationIconResolver iconResolver; public StackPresenter(Activity activity, TitleBarReactViewCreator titleViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, ReactViewCreator buttonCreator, - ImageLoader imageLoader, + NavigationIconResolver iconResolver, RenderChecker renderChecker, Options defaultOptions) { this.activity = activity; this.titleViewCreator = titleViewCreator; this.topBarBackgroundViewCreator = topBarBackgroundViewCreator; this.buttonCreator = buttonCreator; - this.imageLoader = imageLoader; + this.iconResolver = iconResolver; this.renderChecker = renderChecker; this.defaultOptions = defaultOptions; defaultTitleFontSize = UiUtils.dpToSp(activity, 18); @@ -311,8 +310,7 @@ private List getOrCreateButtonControllers(@Nullable Ma private TitleBarButtonController createButtonController(Button button) { TitleBarButtonController controller = new TitleBarButtonController(activity, - new NavigationIconResolver(activity, imageLoader), - imageLoader, + iconResolver, new ButtonPresenter(topBar.getTitleBar(), button), button, buttonCreator, @@ -379,7 +377,13 @@ private void mergeButtons(TopBarOptions options, TopBarButtons buttons, View chi } } if (buttons.left != null) topBar.setLeftButtons(leftButtonControllers); - if (buttons.back.hasValue()) topBar.setBackButton(createButtonController(buttons.back)); + if (buttons.back.hasValue()) { + if (buttons.back.visible.isFalse()) { + topBar.clearLeftButtons(); + } else { + topBar.setBackButton(createButtonController(buttons.back)); + } + } if (options.rightButtonColor.hasValue()) topBar.setOverflowButtonColor(options.rightButtonColor.get()); } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java b/lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java index ff9317218f4..f42e5d9a98a 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java @@ -1,5 +1,6 @@ package com.reactnativenavigation.utils; +import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -7,9 +8,11 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.StrictMode; +import android.view.View; import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper; import com.reactnativenavigation.NavigationApplication; +import com.reactnativenavigation.R; import java.io.FileNotFoundException; import java.io.IOException; @@ -20,6 +23,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; public class ImageLoader { @@ -33,6 +37,11 @@ public interface ImagesLoadingListener { private static final String FILE_SCHEME = "file"; + public Drawable getBackButtonIcon(Activity context) { + boolean isRTL = context.getWindow().getDecorView().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + return ContextCompat.getDrawable(context, isRTL ? R.drawable.ic_arrow_back_black_rtl_24dp : R.drawable.ic_arrow_back_black_24dp); + } + @Nullable public Drawable loadIcon(Context context, @Nullable String uri) { if (uri == null) return null; diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java index d4e47e1749d..38e3581b176 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TitleBarButtonController.java @@ -22,7 +22,6 @@ import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver; import com.reactnativenavigation.views.titlebar.TitleBarReactButtonView; -import java.util.Collections; import java.util.List; import androidx.annotation.NonNull; @@ -36,7 +35,6 @@ public interface OnClickListener { } private final NavigationIconResolver navigationIconResolver; - private final ImageLoader imageLoader; private ButtonPresenter optionsPresenter; private final Button button; private final ReactViewCreator viewCreator; @@ -54,14 +52,12 @@ public String getButtonInstanceId() { public TitleBarButtonController(Activity activity, NavigationIconResolver navigationIconResolver, - ImageLoader imageLoader, ButtonPresenter optionsPresenter, Button button, ReactViewCreator viewCreator, OnClickListener onClickListener) { super(activity, button.id, new YellowBoxDelegate(), new Options()); this.navigationIconResolver = navigationIconResolver; - this.imageLoader = imageLoader; this.optionsPresenter = optionsPresenter; this.button = button; this.viewCreator = viewCreator; @@ -104,8 +100,7 @@ public boolean onMenuItemClick(MenuItem item) { } public void applyNavigationIcon(Toolbar toolbar) { - Integer direction = getActivity().getWindow().getDecorView().getLayoutDirection(); - navigationIconResolver.resolve(button, direction, icon -> { + navigationIconResolver.resolve(button, icon -> { setIconColor(icon); toolbar.setNavigationOnClickListener(view -> onPressListener.onPress(button.id)); toolbar.setNavigationIcon(icon); @@ -134,8 +129,7 @@ public void addToMenu(Toolbar toolbar, int position) { if (button.hasIcon()) { loadIcon(new ImageLoadingListenerAdapter() { @Override - public void onComplete(@NonNull List icons) { - Drawable icon = icons.get(0); + public void onComplete(@NonNull Drawable icon) { TitleBarButtonController.this.icon = icon; setIconColor(icon); menuItem.setIcon(icon); @@ -151,7 +145,7 @@ public void onComplete(@NonNull List icons) { } private void loadIcon(ImageLoader.ImagesLoadingListener callback) { - imageLoader.loadIcons(getActivity(), Collections.singletonList(button.icon.get()), callback); + navigationIconResolver.resolve(button, callback::onComplete); } private void setIconColor(Drawable icon) { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolver.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolver.java index c4edda9be83..c6d77048161 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolver.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolver.java @@ -1,31 +1,29 @@ package com.reactnativenavigation.viewcontrollers.button; -import android.content.Context; +import android.app.Activity; import android.graphics.drawable.Drawable; -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; import android.util.Log; -import android.view.View; -import com.reactnativenavigation.R; import com.reactnativenavigation.parse.params.Button; import com.reactnativenavigation.react.Constants; import com.reactnativenavigation.utils.Functions.Func1; import com.reactnativenavigation.utils.ImageLoader; import com.reactnativenavigation.utils.ImageLoadingListenerAdapter; +import androidx.annotation.NonNull; + public class NavigationIconResolver { - private Context context; + private Activity context; private ImageLoader imageLoader; - public NavigationIconResolver(Context context, ImageLoader imageLoader) { + public NavigationIconResolver(Activity context, ImageLoader imageLoader) { this.context = context; this.imageLoader = imageLoader; } - public void resolve(Button button, Integer direction, Func1 onSuccess) { - if (button.icon.hasValue()) { + public void resolve(Button button, Func1 onSuccess) { + if (button.hasIcon()) { imageLoader.loadIcon(context, button.icon.get(), new ImageLoadingListenerAdapter() { @Override public void onComplete(@NonNull Drawable icon) { @@ -38,8 +36,7 @@ public void onError(Throwable error) { } }); } else if (Constants.BACK_BUTTON_ID.equals(button.id)) { - Boolean isRTL = direction == View.LAYOUT_DIRECTION_RTL; - onSuccess.run(ContextCompat.getDrawable(context, isRTL ? R.drawable.ic_arrow_back_black_rtl_24dp : R.drawable.ic_arrow_back_black_24dp)); + onSuccess.run(imageLoader.getBackButtonIcon(context)); } else { Log.w("RNN", "Left button needs to have an icon"); } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java b/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java index b729185f2d0..766b5df48fd 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java @@ -17,6 +17,7 @@ import com.reactnativenavigation.utils.UiUtils; import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry; import com.reactnativenavigation.viewcontrollers.ViewController; +import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver; import com.reactnativenavigation.viewcontrollers.stack.StackControllerBuilder; import com.reactnativenavigation.viewcontrollers.topbar.TopBarController; import com.reactnativenavigation.views.StackLayout; @@ -38,7 +39,7 @@ protected TopBar createTopBar(Context context, StackLayout stackLayout) { .setId("stack") .setChildRegistry(new ChildControllersRegistry()) .setTopBarController(topBarController) - .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), new ImageLoader(), new RenderChecker(), new Options())) + .setStackPresenter(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), new NavigationIconResolver(activity, new ImageLoader()), new RenderChecker(), new Options())) .setInitialOptions(new Options()); } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/mocks/BackDrawable.java b/lib/android/app/src/test/java/com/reactnativenavigation/mocks/BackDrawable.java new file mode 100644 index 00000000000..c4314a6cd6c --- /dev/null +++ b/lib/android/app/src/test/java/com/reactnativenavigation/mocks/BackDrawable.java @@ -0,0 +1,30 @@ +package com.reactnativenavigation.mocks; + +import android.graphics.Canvas; +import android.graphics.ColorFilter; +import android.graphics.drawable.Drawable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +public class BackDrawable extends Drawable { + @Override + public void draw(@NonNull Canvas canvas) { + + } + + @Override + public void setAlpha(int alpha) { + + } + + @Override + public void setColorFilter(@Nullable ColorFilter colorFilter) { + + } + + @Override + public int getOpacity() { + return 0; + } +} diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/mocks/ImageLoaderMock.java b/lib/android/app/src/test/java/com/reactnativenavigation/mocks/ImageLoaderMock.java index f7d93718b91..f6c770bcc47 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/mocks/ImageLoaderMock.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/mocks/ImageLoaderMock.java @@ -3,7 +3,6 @@ import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.drawable.Drawable; -import androidx.annotation.NonNull; import com.reactnativenavigation.utils.ImageLoader; @@ -13,6 +12,8 @@ import java.util.Collections; import java.util.List; +import androidx.annotation.NonNull; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; @@ -39,22 +40,23 @@ public int getOpacity() { } }; + private static Drawable backIcon = new BackDrawable(); + public static ImageLoader mock() { ImageLoader imageLoader = Mockito.mock(ImageLoader.class); - doAnswer( - invocation -> { + doAnswer(invocation -> { int urlCount = ((Collection) invocation.getArguments()[1]).size(); List drawables = Collections.nCopies(urlCount, mockDrawable); ((ImageLoader.ImagesLoadingListener) invocation.getArguments()[2]).onComplete(drawables); return null; } ).when(imageLoader).loadIcons(any(), any(), any()); - doAnswer( - invocation -> { + doAnswer(invocation -> { ((ImageLoader.ImagesLoadingListener) invocation.getArguments()[2]).onComplete(mockDrawable); return null; } ).when(imageLoader).loadIcon(any(), any(), any()); + doAnswer(invocation -> backIcon).when(imageLoader).getBackButtonIcon(any()); return imageLoader; } } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleBarHelper.java b/lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleBarHelper.java index 2f4cafe11ce..999049f7976 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleBarHelper.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/utils/TitleBarHelper.java @@ -1,8 +1,6 @@ package com.reactnativenavigation.utils; import android.app.Activity; -import androidx.appcompat.view.menu.ActionMenuItemView; -import androidx.appcompat.widget.Toolbar; import com.reactnativenavigation.mocks.ImageLoaderMock; import com.reactnativenavigation.mocks.TopBarButtonCreatorMock; @@ -13,6 +11,9 @@ import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver; import com.reactnativenavigation.views.titlebar.TitleBar; +import androidx.appcompat.view.menu.ActionMenuItemView; +import androidx.appcompat.widget.Toolbar; + public class TitleBarHelper { public static ActionMenuItemView getRightButton(Toolbar toolbar, int index) { return (ActionMenuItemView) ViewUtils.findChildrenByClassRecursive(toolbar, ActionMenuItemView.class).get(toolbar.getMenu().size() - index - 1); @@ -45,7 +46,6 @@ public static Button iconButton(String id, String icon) { public static TitleBarButtonController createButtonController(Activity activity, TitleBar titleBar, Button button) { return new TitleBarButtonController(activity, new NavigationIconResolver(activity, ImageLoaderMock.mock()), - ImageLoaderMock.mock(), new ButtonPresenter(titleBar, button), button, new TopBarButtonCreatorMock(), diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackPresenterTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackPresenterTest.java index e21731e3630..413d437267a 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackPresenterTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackPresenterTest.java @@ -5,10 +5,10 @@ import android.graphics.Typeface; import android.view.Gravity; import android.view.View; -import android.view.ViewGroup; import com.reactnativenavigation.BaseTest; import com.reactnativenavigation.TestUtils; +import com.reactnativenavigation.mocks.BackDrawable; import com.reactnativenavigation.mocks.ImageLoaderMock; import com.reactnativenavigation.mocks.Mocks; import com.reactnativenavigation.mocks.SimpleViewController; @@ -29,7 +29,10 @@ import com.reactnativenavigation.parse.params.Text; import com.reactnativenavigation.presentation.RenderChecker; import com.reactnativenavigation.presentation.StackPresenter; +import com.reactnativenavigation.utils.CommandListenerAdapter; import com.reactnativenavigation.utils.TitleBarHelper; +import com.reactnativenavigation.utils.UiUtils; +import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver; import com.reactnativenavigation.viewcontrollers.stack.StackController; import com.reactnativenavigation.viewcontrollers.topbar.TopBarController; import com.reactnativenavigation.views.StackLayout; @@ -39,6 +42,8 @@ import org.json.JSONObject; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.robolectric.annotation.LooperMode; +import org.robolectric.shadows.ShadowLooper; import java.util.ArrayList; import java.util.Collection; @@ -47,6 +52,7 @@ import androidx.appcompat.widget.ActionMenuView; import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; @@ -62,6 +68,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +@LooperMode(LooperMode.Mode.PAUSED) public class StackPresenterTest extends BaseTest { private static final Options EMPTY_OPTIONS = new Options(); @@ -78,6 +85,8 @@ public class StackPresenterTest extends BaseTest { private Button componentBtn1 = TitleBarHelper.reactViewButton("btn1_"); private Button componentBtn2 = TitleBarHelper.reactViewButton("btn2_"); private TopBarController topBarController; + private ChildControllersRegistry childRegistry; + private NavigationIconResolver iconResolver; @Override public void beforeEach() { @@ -89,24 +98,19 @@ public TitleBarReactView create(Activity activity, String componentId, String co } }; renderChecker = spy(new RenderChecker()); - uut = spy(new StackPresenter(activity, titleViewCreator, new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), ImageLoaderMock.mock(), renderChecker, new Options())); - topBar = mockTopBar(); - topBarController = spy(new TopBarController() { - @Override - protected TopBar createTopBar(Context context, StackLayout stackLayout) { - return topBar; - } - }); + iconResolver = new NavigationIconResolver(activity, ImageLoaderMock.mock()); + uut = spy(new StackPresenter(activity, titleViewCreator, new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), iconResolver, renderChecker, new Options())); + createTopBarController(); parent = TestUtils.newStackController(activity) .setTopBarController(topBarController) .setStackPresenter(uut) .build(); - parent.ensureViewIsCreated(); - ChildControllersRegistry childRegistry = new ChildControllersRegistry(); + childRegistry = new ChildControllersRegistry(); child = spy(new SimpleViewController(activity, childRegistry, "child1", Options.EMPTY)); otherChild = spy(new SimpleViewController(activity, childRegistry, "child1", Options.EMPTY)); + activity.setContentView(parent.getView()); } @Test @@ -114,13 +118,13 @@ public void isRendered() { Options o1 = new Options(); o1.topBar.title.component = component(Alignment.Default); o1.topBar.background.component = component(Alignment.Default); - o1.topBar.buttons.right = new ArrayList(Collections.singletonList(componentBtn1)); + o1.topBar.buttons.right = new ArrayList<>(Collections.singletonList(componentBtn1)); uut.applyChildOptions(o1, parent, child); uut.isRendered(child.getView()); ArgumentCaptor> controllers = ArgumentCaptor.forClass(Collection.class); verify(renderChecker).areRendered(controllers.capture()); - ArrayList items = new ArrayList(controllers.getValue()); + ArrayList items = new ArrayList<>(controllers.getValue()); assertThat(items.contains(uut.getComponentButtons(child.getView()).get(0))).isTrue(); assertThat(items.contains(uut.getTitleComponents().get(child.getView()))).isTrue(); assertThat(items.contains(uut.getBackgroundComponents().get(child.getView()))).isTrue(); @@ -250,6 +254,27 @@ public void mergeButtons_mergingLeftButtonsOnlyDestroysLeftButtons() { assertThat(initialButtons.get(1).isDestroyed()).isTrue(); } + @Test + public void mergeButtons_backButtonIsRemovedIfVisibleFalse() { + ViewController pushedChild = spy(new SimpleViewController(activity, childRegistry, "child2", new Options())); + disablePushAnimation(child, pushedChild); + parent.push(child, new CommandListenerAdapter()); + + assertThat(topBar.getTitleBar().getNavigationIcon()).isNull(); + + parent.push(pushedChild, new CommandListenerAdapter()); + ShadowLooper.idleMainLooper(); + verify(pushedChild).onViewAppeared(); + assertThat(topBar.getTitleBar().getNavigationIcon()).isInstanceOf(BackDrawable.class); + + Options backButtonHidden = new Options(); + backButtonHidden.topBar.buttons.back.setHidden(); + uut.mergeChildOptions(backButtonHidden, backButtonHidden, parent, child); + + ShadowLooper.idleMainLooper(); + assertThat(topBar.getTitleBar().getNavigationIcon()).isNull(); + } + @Test public void mergeTopBarOptions() { Options options = new Options(); @@ -302,20 +327,6 @@ public void mergeTopTabsOptions() { verify(topBar, times(1)).setTopTabsVisible(anyBoolean()); } - @Test - public void mergeTopTabOptions() { - Options options = new Options(); - uut.mergeChildOptions(options, EMPTY_OPTIONS, parent, child); - - verify(topBar, times(0)).setTopTabFontFamily(anyInt(), any()); - - options.topTabOptions.tabIndex = 1; - options.topTabOptions.fontFamily = Typeface.DEFAULT_BOLD; - uut.mergeChildOptions(options, EMPTY_OPTIONS, parent, child); - - verify(topBar, times(1)).setTopTabFontFamily(1, Typeface.DEFAULT_BOLD); - } - @Test public void applyInitialChildLayoutOptions() { Options options = new Options(); @@ -571,10 +582,22 @@ private TopBar mockTopBar() { toolbar.addView(new ActionMenuView(activity)); when(topBar.getTitleBar()).then(invocation -> toolbar); when(topBar.getContext()).then(invocation -> activity); - when(topBar.getLayoutParams()).thenReturn(new ViewGroup.MarginLayoutParams(MATCH_PARENT, WRAP_CONTENT)); + when(topBar.dispatchApplyWindowInsets(any())).then(invocation -> invocation.getArguments()[0]); + when(topBar.getLayoutParams()).thenReturn(new CoordinatorLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)); return topBar; } + private void createTopBarController() { + topBarController = spy(new TopBarController() { + @Override + protected TopBar createTopBar(Context context, StackLayout stackLayout) { + topBar = spy(super.createTopBar(context, stackLayout)); + topBar.layout(0, 0, 1000, UiUtils.getTopBarHeight(activity)); + return topBar; + } + }); + } + private Component component(Alignment alignment) { Component component = new Component(); component.name = new Text("myComp"); diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java index 30ebc6047b7..3589724ff97 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java @@ -51,7 +51,7 @@ public void beforeEach() { getTitleBar().layout(0, 0, 1080, 200); optionsPresenter = spy(new ButtonPresenter(getTitleBar(), button)); - uut = new TitleBarButtonController(activity, new NavigationIconResolver(activity, ImageLoaderMock.mock()), ImageLoaderMock.mock(), optionsPresenter, button, buttonCreatorMock, (buttonId) -> {}); + uut = new TitleBarButtonController(activity, new NavigationIconResolver(activity, ImageLoaderMock.mock()), optionsPresenter, button, buttonCreatorMock, (buttonId) -> {}); stackController.ensureViewIsCreated(); } @@ -87,7 +87,7 @@ public void setIconColor_disabledColor() { button.disabledColor = new Colour(Color.BLACK); uut.addToMenu(getTitleBar(), 0); - verify(optionsPresenter, times(1)).tint(any(), eq(Color.BLACK)); + verify(optionsPresenter).tint(any(), eq(Color.BLACK)); } @Test diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolverTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolverTest.java index 7f900ae80a8..9def6821129 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolverTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolverTest.java @@ -1,11 +1,11 @@ package com.reactnativenavigation.viewcontrollers.button; -import android.content.Context; +import android.app.Activity; import android.graphics.Color; import android.graphics.drawable.Drawable; -import android.view.View; import com.reactnativenavigation.BaseTest; +import com.reactnativenavigation.mocks.BackDrawable; import com.reactnativenavigation.mocks.ImageLoaderMock; import com.reactnativenavigation.parse.params.Button; import com.reactnativenavigation.parse.params.Colour; @@ -20,13 +20,12 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; public class NavigationIconResolverTest extends BaseTest { private static final String ICON_URI = "someIconUri"; private NavigationIconResolver uut; private ImageLoader imageLoader; - private Context context; + private Activity context; @Override public void beforeEach() { @@ -43,7 +42,7 @@ public void run(Drawable icon) { } }); - uut.resolve(iconButton(), View.LAYOUT_DIRECTION_LTR, onSuccess); + uut.resolve(iconButton(), onSuccess); verify(imageLoader).loadIcon(eq(context), eq(ICON_URI), any()); verify(onSuccess).run(any(Drawable.class)); } @@ -56,9 +55,8 @@ public void run(Drawable param) { } }); - uut.resolve(backButton(), View.LAYOUT_DIRECTION_LTR, onSuccess); - verifyZeroInteractions(imageLoader); - verify(onSuccess).run(any()); + uut.resolve(backButton(), onSuccess); + verify(onSuccess).run(any(BackDrawable.class)); } private Button iconButton() { diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java index 38d73d4ee1a..90e43d9c20a 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java @@ -32,6 +32,7 @@ import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry; import com.reactnativenavigation.viewcontrollers.ParentController; import com.reactnativenavigation.viewcontrollers.ViewController; +import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver; import com.reactnativenavigation.viewcontrollers.topbar.TopBarController; import com.reactnativenavigation.views.StackLayout; import com.reactnativenavigation.views.element.ElementTransitionManager; @@ -95,7 +96,7 @@ public void beforeEach() { StatusBarUtils.saveStatusBarHeight(63); animator = spy(new NavigationAnimator(activity, Mockito.mock(ElementTransitionManager.class))); childRegistry = new ChildControllersRegistry(); - presenter = spy(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), ImageLoaderMock.mock(), new RenderChecker(), new Options())); + presenter = spy(new StackPresenter(activity, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarButtonCreatorMock(), new NavigationIconResolver(activity, ImageLoaderMock.mock()), new RenderChecker(), new Options())); child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options())); child1a = spy(new SimpleViewController(activity, childRegistry, "child1", new Options())); child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));