From e5a2efb0d9237cae82fbadb92c3a86d0f01c3b5f Mon Sep 17 00:00:00 2001 From: Guy Carmeli Date: Thu, 3 Jan 2019 11:41:55 +0200 Subject: [PATCH] Render first tab first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now tabs were added to screen in reverse order, meaning the last tab was attached to hierarchy first and the first tab was attached last. This caused the first tab, which usually should appear first, to be rendered last as the root view’s startReactApplication was called last. This commit changes render order so that the first tab is rendered first. Some apps will probably see an improvement in time to interaction as a result. --- .../viewcontrollers/bottomtabs/BottomTabsController.java | 2 +- .../viewcontrollers/BottomTabsControllerTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java index b0b37b5bff9..5f87be6d6ef 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java @@ -156,7 +156,7 @@ private List createTabs() { } private void attachTabs(RelativeLayout root) { - for (int i = (tabs.size() - 1); i >= 0; i--) { + for (int i = 0; i < tabs.size(); i++) { ViewGroup tab = tabs.get(i).getView(); tab.setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); Options options = resolveCurrentOptions(); diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java index b992bb8c800..f09348259d0 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java @@ -125,7 +125,8 @@ public void setTabs_allChildViewsAreAttachedToHierarchy() { public void setTabs_firstChildIsVisibleOtherAreGone() { uut.onViewAppeared(); for (int i = 0; i < uut.getChildControllers().size(); i++) { - assertThat(uut.getView().getChildAt(i).getVisibility()).isEqualTo(i == 0 ? View.VISIBLE : View.INVISIBLE); + assertThat(uut.getView().getChildAt(i + 1)).isEqualTo(tabs.get(i).getView()); + assertThat(uut.getView().getChildAt(i + 1).getVisibility()).isEqualTo(i == 0 ? View.VISIBLE : View.INVISIBLE); } }