Browse Source

Dont merge null colors

When updating a tab icon, if null was used as color - it would get applied.
Guy Carmeli 5 years ago
parent
commit
c48ed747a1

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

7
 import com.reactnativenavigation.parse.BottomTabOptions;
7
 import com.reactnativenavigation.parse.BottomTabOptions;
8
 import com.reactnativenavigation.parse.DotIndicatorOptions;
8
 import com.reactnativenavigation.parse.DotIndicatorOptions;
9
 import com.reactnativenavigation.parse.Options;
9
 import com.reactnativenavigation.parse.Options;
10
+import com.reactnativenavigation.parse.params.Param;
10
 import com.reactnativenavigation.utils.ImageLoader;
11
 import com.reactnativenavigation.utils.ImageLoader;
11
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
12
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
12
 import com.reactnativenavigation.utils.LateInit;
13
 import com.reactnativenavigation.utils.LateInit;
78
             if (index >= 0) {
79
             if (index >= 0) {
79
                 BottomTabOptions tab = options.bottomTabOptions;
80
                 BottomTabOptions tab = options.bottomTabOptions;
80
                 if (tab.fontFamily != null) bottomTabs.setTitleTypeface(index, tab.fontFamily);
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
                 if (tab.selectedTextColor.hasValue()) bottomTabs.setTitleActiveColor(index, tab.selectedTextColor.get());
84
                 if (tab.selectedTextColor.hasValue()) bottomTabs.setTitleActiveColor(index, tab.selectedTextColor.get());
84
                 if (tab.textColor.hasValue()) bottomTabs.setTitleInactiveColor(index, tab.textColor.get());
85
                 if (tab.textColor.hasValue()) bottomTabs.setTitleInactiveColor(index, tab.textColor.get());
85
                 if (tab.text.hasValue()) bottomTabs.setText(index, tab.text.get());
86
                 if (tab.text.hasValue()) bottomTabs.setText(index, tab.text.get());
143
     private boolean shouldApplyDot(BottomTabOptions tab) {
144
     private boolean shouldApplyDot(BottomTabOptions tab) {
144
         return tab.dotIndicator.visible.hasValue() && !tab.badge.hasValue();
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 View File

9
 import com.reactnativenavigation.mocks.SimpleViewController;
9
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.params.Colour;
11
 import com.reactnativenavigation.parse.params.Colour;
12
+import com.reactnativenavigation.parse.params.DontApplyColour;
12
 import com.reactnativenavigation.parse.params.Text;
13
 import com.reactnativenavigation.parse.params.Text;
13
 import com.reactnativenavigation.presentation.BottomTabPresenter;
14
 import com.reactnativenavigation.presentation.BottomTabPresenter;
14
 import com.reactnativenavigation.views.BottomTabs;
15
 import com.reactnativenavigation.views.BottomTabs;
100
         verifyNoMoreInteractions(bottomTabs);
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
     private Options createTab1Options() {
114
     private Options createTab1Options() {
104
         Options options = new Options();
115
         Options options = new Options();
105
         options.bottomTabOptions.badge = new Text("tab1badge");
116
         options.bottomTabOptions.badge = new Text("tab1badge");