Browse Source

Set BottomTab colours only if needed (#1414)

Fixes #1411
Each time a color attribute is set in AHBottomNavigation, all items in
the BottomTabs are recreated. If a badge is set, it is animated each
time items are recreated. This behaviour can even be seen in the gifs
in the repo https://github.com/aurelhubert/ahbottomnavigation
Guy Carmeli 7 years ago
parent
commit
0d6b895b1b

+ 10
- 4
android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java View File

@@ -43,10 +43,14 @@ public class BottomTabs extends AHBottomNavigation {
43 43
             setBackgroundColor(params.bottomTabsColor);
44 44
         }
45 45
         if (params.bottomTabsButtonColor.hasColor()) {
46
-            setInactiveColor(params.bottomTabsButtonColor.getColor());
46
+            if (getInactiveColor() != params.bottomTabsButtonColor.getColor()) {
47
+                setInactiveColor(params.bottomTabsButtonColor.getColor());
48
+            }
47 49
         }
48 50
         if (params.selectedBottomTabsButtonColor.hasColor()) {
49
-            setAccentColor(params.selectedBottomTabsButtonColor.getColor());
51
+            if (getAccentColor() != params.selectedBottomTabsButtonColor.getColor()) {
52
+                setAccentColor(params.selectedBottomTabsButtonColor.getColor());
53
+            }
50 54
         }
51 55
 
52 56
         setVisibility(params.bottomTabsHidden, true);
@@ -90,8 +94,10 @@ public class BottomTabs extends AHBottomNavigation {
90 94
 
91 95
     private void setBackgroundColor(StyleParams.Color bottomTabsColor) {
92 96
         if (bottomTabsColor.hasColor()) {
93
-            setDefaultBackgroundColor(bottomTabsColor.getColor());
94
-        } else {
97
+            if (bottomTabsColor.getColor() != getDefaultBackgroundColor()) {
98
+                setDefaultBackgroundColor(bottomTabsColor.getColor());
99
+            }
100
+        } else if (Color.WHITE != getDefaultBackgroundColor()){
95 101
             setDefaultBackgroundColor(Color.WHITE);
96 102
         }
97 103
     }