Browse Source

Render first tab first

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.
Guy Carmeli 5 years ago
parent
commit
e5a2efb0d9

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java View File

156
 	}
156
 	}
157
 
157
 
158
     private void attachTabs(RelativeLayout root) {
158
     private void attachTabs(RelativeLayout root) {
159
-        for (int i = (tabs.size() - 1); i >= 0; i--) {
159
+        for (int i = 0; i < tabs.size(); i++) {
160
             ViewGroup tab = tabs.get(i).getView();
160
             ViewGroup tab = tabs.get(i).getView();
161
             tab.setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
161
             tab.setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
162
             Options options = resolveCurrentOptions();
162
             Options options = resolveCurrentOptions();

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java View File

125
     public void setTabs_firstChildIsVisibleOtherAreGone() {
125
     public void setTabs_firstChildIsVisibleOtherAreGone() {
126
         uut.onViewAppeared();
126
         uut.onViewAppeared();
127
         for (int i = 0; i < uut.getChildControllers().size(); i++) {
127
         for (int i = 0; i < uut.getChildControllers().size(); i++) {
128
-            assertThat(uut.getView().getChildAt(i).getVisibility()).isEqualTo(i == 0 ? View.VISIBLE : View.INVISIBLE);
128
+            assertThat(uut.getView().getChildAt(i + 1)).isEqualTo(tabs.get(i).getView());
129
+            assertThat(uut.getView().getChildAt(i + 1).getVisibility()).isEqualTo(i == 0 ? View.VISIBLE : View.INVISIBLE);
129
         }
130
         }
130
     }
131
     }
131
 
132