Browse Source

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 years ago
parent
commit
c700332d5b

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

134
 
134
 
135
                 }
135
                 }
136
                 bottomTabs.addItems(tabs);
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
                 selectTab(0);
142
                 selectTab(0);
141
             }
143
             }
142
 
144
 

+ 13
- 2
lib/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

6
 import android.view.View;
6
 import android.view.View;
7
 
7
 
8
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
8
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
9
+import com.reactnativenavigation.BuildConfig;
9
 import com.reactnativenavigation.parse.params.Text;
10
 import com.reactnativenavigation.parse.params.Text;
10
 import com.reactnativenavigation.utils.CompatUtils;
11
 import com.reactnativenavigation.utils.CompatUtils;
11
 
12
 
18
     }
19
     }
19
 
20
 
20
     public void setTabTag(int index, Text testId) {
21
     public void setTabTag(int index, Text testId) {
22
+        if (!testId.hasValue()) return;
21
         View view = getViewAtPosition(index);
23
         View view = getViewAtPosition(index);
22
-        if (!testId.hasValue() || view == null) return;
23
         view.setTag(testId.get());
24
         view.setTag(testId.get());
24
-        view.setContentDescription(testId.get());
25
+        if (BuildConfig.DEBUG) view.setContentDescription(testId.get());
25
     }
26
     }
26
 
27
 
27
     public void setBadge(int bottomTabIndex, Text badge) {
28
     public void setBadge(int bottomTabIndex, Text badge) {
32
     public void setCurrentItem(@IntRange(from = 0) int position) {
33
     public void setCurrentItem(@IntRange(from = 0) int position) {
33
         super.setCurrentItem(position);
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
 }