Quellcode durchsuchen

Dont merge null colors

When updating a tab icon, if null was used as color - it would get applied.
Guy Carmeli vor 5 Jahren
Ursprung
Commit
c48ed747a1

+ 7
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabPresenter.java Datei anzeigen

@@ -7,6 +7,7 @@ import com.aurelhubert.ahbottomnavigation.notification.AHNotification;
7 7
 import com.reactnativenavigation.parse.BottomTabOptions;
8 8
 import com.reactnativenavigation.parse.DotIndicatorOptions;
9 9
 import com.reactnativenavigation.parse.Options;
10
+import com.reactnativenavigation.parse.params.Param;
10 11
 import com.reactnativenavigation.utils.ImageLoader;
11 12
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
12 13
 import com.reactnativenavigation.utils.LateInit;
@@ -78,8 +79,8 @@ public class BottomTabPresenter {
78 79
             if (index >= 0) {
79 80
                 BottomTabOptions tab = options.bottomTabOptions;
80 81
                 if (tab.fontFamily != null) bottomTabs.setTitleTypeface(index, tab.fontFamily);
81
-                if (tab.selectedIconColor.hasValue()) bottomTabs.setIconActiveColor(index, tab.selectedIconColor.get());
82
-                if (tab.iconColor.hasValue()) bottomTabs.setIconInactiveColor(index, tab.iconColor.get());
82
+                if (canMerge(tab.selectedIconColor)) bottomTabs.setIconActiveColor(index, tab.selectedIconColor.get());
83
+                if (canMerge(tab.iconColor)) bottomTabs.setIconInactiveColor(index, tab.iconColor.get());
83 84
                 if (tab.selectedTextColor.hasValue()) bottomTabs.setTitleActiveColor(index, tab.selectedTextColor.get());
84 85
                 if (tab.textColor.hasValue()) bottomTabs.setTitleInactiveColor(index, tab.textColor.get());
85 86
                 if (tab.text.hasValue()) bottomTabs.setText(index, tab.text.get());
@@ -143,4 +144,8 @@ public class BottomTabPresenter {
143 144
     private boolean shouldApplyDot(BottomTabOptions tab) {
144 145
         return tab.dotIndicator.visible.hasValue() && !tab.badge.hasValue();
145 146
     }
147
+
148
+    private boolean canMerge(Param p) {
149
+        return p.hasValue() && p.canApplyValue();
150
+    }
146 151
 }

+ 11
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabPresenterTest.java Datei anzeigen

@@ -9,6 +9,7 @@ import com.reactnativenavigation.mocks.ImageLoaderMock;
9 9
 import com.reactnativenavigation.mocks.SimpleViewController;
10 10
 import com.reactnativenavigation.parse.Options;
11 11
 import com.reactnativenavigation.parse.params.Colour;
12
+import com.reactnativenavigation.parse.params.DontApplyColour;
12 13
 import com.reactnativenavigation.parse.params.Text;
13 14
 import com.reactnativenavigation.presentation.BottomTabPresenter;
14 15
 import com.reactnativenavigation.views.BottomTabs;
@@ -100,6 +101,16 @@ public class BottomTabPresenterTest extends BaseTest {
100 101
         verifyNoMoreInteractions(bottomTabs);
101 102
     }
102 103
 
104
+    @Test
105
+    public void mergeChildOptions_nullColorsAreNotMerged() {
106
+        Options options = new Options();
107
+        options.bottomTabOptions.iconColor = new DontApplyColour();
108
+        options.bottomTabOptions.selectedIconColor = new DontApplyColour();
109
+        uut.mergeChildOptions(options, (Component) child3.getView());
110
+        verify(bottomTabs, times(0)).setIconActiveColor(anyInt(), anyInt());
111
+        verify(bottomTabs, times(0)).setIconInactiveColor(anyInt(), anyInt());
112
+    }
113
+
103 114
     private Options createTab1Options() {
104 115
         Options options = new Options();
105 116
         options.bottomTabOptions.badge = new Text("tab1badge");