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,7 +156,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
156 156
 	}
157 157
 
158 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 160
             ViewGroup tab = tabs.get(i).getView();
161 161
             tab.setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
162 162
             Options options = resolveCurrentOptions();

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

@@ -125,7 +125,8 @@ public class BottomTabsControllerTest extends BaseTest {
125 125
     public void setTabs_firstChildIsVisibleOtherAreGone() {
126 126
         uut.onViewAppeared();
127 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