Browse Source

Add badgeColor option to bottomTab (#3604)

SCadilhac 6 years ago
parent
commit
7e24aafd67

+ 1
- 0
docs/docs/styling.md View File

@@ -125,6 +125,7 @@ Navigation.mergeOptions(this.props.componentId, {
125 125
   bottomTab: {
126 126
     text: 'Tab 1',
127 127
     badge: '2',
128
+    badgeColor: 'red',
128 129
     testID: 'bottomTabTestID',
129 130
     icon: require('tab.png'),
130 131
     iconColor: 'red',

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabOptions.java View File

@@ -29,6 +29,7 @@ public class BottomTabOptions {
29 29
         options.iconColor = ColorParser.parse(json, "iconColor");
30 30
         options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
31 31
         options.badge = TextParser.parse(json, "badge");
32
+        options.badgeColor = ColorParser.parse(json, "badgeColor");
32 33
         options.testId = TextParser.parse(json, "testID");
33 34
         options.fontFamily = typefaceManager.getTypeFace(json.optString("fontFamily", ""));
34 35
         options.fontSize = NumberParser.parse(json, "fontSize");
@@ -44,6 +45,7 @@ public class BottomTabOptions {
44 45
     public Color selectedIconColor = new NullColor();
45 46
     public Text testId = new NullText();
46 47
     public Text badge = new NullText();
48
+    public Color badgeColor = new NullColor();
47 49
     public Number fontSize = new NullNumber();
48 50
     public Number selectedFontSize = new NullNumber();
49 51
     @Nullable public Typeface fontFamily;
@@ -57,6 +59,7 @@ public class BottomTabOptions {
57 59
         if (other.iconColor.hasValue()) iconColor = other.iconColor;
58 60
         if (other.selectedIconColor.hasValue()) selectedIconColor = other.selectedIconColor;
59 61
         if (other.badge.hasValue()) badge = other.badge;
62
+        if (other.badgeColor.hasValue()) badgeColor = other.badgeColor;
60 63
         if (other.testId.hasValue()) testId = other.testId;
61 64
         if (other.fontSize.hasValue()) fontSize = other.fontSize;
62 65
         if (other.selectedFontSize.hasValue()) selectedFontSize = other.selectedFontSize;
@@ -71,6 +74,7 @@ public class BottomTabOptions {
71 74
         if (!iconColor.hasValue()) iconColor = defaultOptions.iconColor;
72 75
         if (!selectedIconColor.hasValue()) selectedIconColor = defaultOptions.selectedIconColor;
73 76
         if (!badge.hasValue()) badge = defaultOptions.badge;
77
+        if (!badgeColor.hasValue()) badgeColor = defaultOptions.badgeColor;
74 78
         if (!fontSize.hasValue()) fontSize = defaultOptions.fontSize;
75 79
         if (!selectedFontSize.hasValue()) selectedFontSize = defaultOptions.selectedFontSize;
76 80
         if (fontFamily == null) fontFamily = defaultOptions.fontFamily;

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

@@ -41,6 +41,7 @@ public class BottomTabOptionsPresenter {
41 41
         for (int i = 0; i < tabs.size(); i++) {
42 42
             BottomTabOptions tab = tabs.get(i).options.copy().withDefaultOptions(defaultOptions).bottomTabOptions;
43 43
             bottomTabs.setBadge(i, tab.badge.get(""));
44
+            bottomTabs.setBadgeColor(tab.badgeColor.get(null));
44 45
             bottomTabs.setTitleTypeface(i, tab.fontFamily);
45 46
             bottomTabs.setIconActiveColor(i, tab.selectedIconColor.get(null));
46 47
             bottomTabs.setIconInactiveColor(i, tab.iconColor.get(null));
@@ -55,6 +56,7 @@ public class BottomTabOptionsPresenter {
55 56
         BottomTabOptions withDefaultOptions = options.withDefaultOptions(defaultOptions).bottomTabOptions;
56 57
         int index = bottomTabFinder.findByComponent(child);
57 58
         if (withDefaultOptions.badge.hasValue()) bottomTabs.setBadge(index, withDefaultOptions.badge.get());
59
+        if (withDefaultOptions.badgeColor.hasValue()) bottomTabs.setBadgeColor(withDefaultOptions.badgeColor.get());
58 60
         if (withDefaultOptions.fontFamily != null) bottomTabs.setTitleTypeface(index, withDefaultOptions.fontFamily);
59 61
         if (withDefaultOptions.selectedIconColor.hasValue()) bottomTabs.setIconActiveColor(index, withDefaultOptions.selectedIconColor.get());
60 62
         if (withDefaultOptions.iconColor.hasValue()) bottomTabs.setIconInactiveColor(index, withDefaultOptions.iconColor.get());

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

@@ -2,6 +2,7 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.annotation.SuppressLint;
4 4
 import android.content.Context;
5
+import android.support.annotation.ColorInt;
5 6
 import android.support.annotation.IntRange;
6 7
 import android.view.View;
7 8
 
@@ -29,6 +30,11 @@ public class BottomTabs extends AHBottomNavigation {
29 30
         setNotification(badge, bottomTabIndex);
30 31
     }
31 32
 
33
+    public void setBadgeColor(@ColorInt Integer color) {
34
+        if (color == null) return;
35
+        setNotificationBackgroundColor(color);
36
+    }
37
+
32 38
     @Override
33 39
     public void setCurrentItem(@IntRange(from = 0) int position) {
34 40
         super.setCurrentItem(position);

+ 1
- 0
lib/ios/RNNBottomTabOptions.h View File

@@ -5,6 +5,7 @@
5 5
 @property (nonatomic) NSUInteger tag;
6 6
 @property (nonatomic, strong) NSString* text;
7 7
 @property (nonatomic, strong) NSString* badge;
8
+@property (nonatomic, strong) NSDictionary* badgeColor;
8 9
 @property (nonatomic, strong) NSString* testID;
9 10
 @property (nonatomic, strong) NSNumber* visible;
10 11
 @property (nonatomic, strong) NSDictionary* icon;

+ 6
- 3
lib/ios/RNNBottomTabOptions.m View File

@@ -46,10 +46,13 @@
46 46
 		if (self.badge != nil && ![self.badge isEqual:[NSNull null]]) {
47 47
 			badge = [RCTConvert NSString:self.badge];
48 48
 		}
49
+		UITabBarItem *tabBarItem = viewController.tabBarItem;
49 50
 		if (viewController.navigationController) {
50
-			viewController.navigationController.tabBarItem.badgeValue = badge;
51
-		} else {
52
-			viewController.tabBarItem.badgeValue = badge;
51
+			tabBarItem = viewController.navigationController.tabBarItem;
52
+		}
53
+		tabBarItem.badgeValue = badge;
54
+		if (self.badgeColor) {
55
+			tabBarItem.badgeColor = [RCTConvert UIColor:self.badgeColor];
53 56
 		}
54 57
 	}
55 58