소스 검색

Apply BottomTabs options only when needed

AHBottomNavigation recreates all tabs when some style properties are set.
This commit works around this issue by setting the problematic style properties
only if they are different then current values.

Related to #3132
Guy Carmeli 6 년 전
부모
커밋
c700332d5b

+ 5
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java 파일 보기

@@ -134,9 +134,11 @@ public class BottomTabsController extends ParentController implements AHBottomNa
134 134
 
135 135
                 }
136 136
                 bottomTabs.addItems(tabs);
137
-                for (int i = 0; i < bottomTabOptionsList.size(); i++) {
138
-                    bottomTabs.setTabTag(i, bottomTabOptionsList.get(i).testId);
139
-                }
137
+                bottomTabs.post(() -> {
138
+                    for (int i = 0; i < bottomTabOptionsList.size(); i++) {
139
+                        bottomTabs.setTabTag(i, bottomTabOptionsList.get(i).testId);
140
+                    }
141
+                });
140 142
                 selectTab(0);
141 143
             }
142 144
 

+ 13
- 2
lib/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java 파일 보기

@@ -6,6 +6,7 @@ import android.support.annotation.IntRange;
6 6
 import android.view.View;
7 7
 
8 8
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
9
+import com.reactnativenavigation.BuildConfig;
9 10
 import com.reactnativenavigation.parse.params.Text;
10 11
 import com.reactnativenavigation.utils.CompatUtils;
11 12
 
@@ -18,10 +19,10 @@ public class BottomTabs extends AHBottomNavigation {
18 19
     }
19 20
 
20 21
     public void setTabTag(int index, Text testId) {
22
+        if (!testId.hasValue()) return;
21 23
         View view = getViewAtPosition(index);
22
-        if (!testId.hasValue() || view == null) return;
23 24
         view.setTag(testId.get());
24
-        view.setContentDescription(testId.get());
25
+        if (BuildConfig.DEBUG) view.setContentDescription(testId.get());
25 26
     }
26 27
 
27 28
     public void setBadge(int bottomTabIndex, Text badge) {
@@ -32,4 +33,14 @@ public class BottomTabs extends AHBottomNavigation {
32 33
     public void setCurrentItem(@IntRange(from = 0) int position) {
33 34
         super.setCurrentItem(position);
34 35
     }
36
+
37
+    @Override
38
+    public void setAccentColor(int accentColor) {
39
+        if (getAccentColor() != accentColor) super.setAccentColor(accentColor);
40
+    }
41
+
42
+    @Override
43
+    public void setInactiveColor(int inactiveColor) {
44
+        if (getInactiveColor() != inactiveColor) super.setInactiveColor(inactiveColor);
45
+    }
35 46
 }