Browse Source

Add badgeColor option to bottomTab (#3604)

SCadilhac 6 years ago
parent
commit
7e24aafd67

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

125
   bottomTab: {
125
   bottomTab: {
126
     text: 'Tab 1',
126
     text: 'Tab 1',
127
     badge: '2',
127
     badge: '2',
128
+    badgeColor: 'red',
128
     testID: 'bottomTabTestID',
129
     testID: 'bottomTabTestID',
129
     icon: require('tab.png'),
130
     icon: require('tab.png'),
130
     iconColor: 'red',
131
     iconColor: 'red',

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

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

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

41
         for (int i = 0; i < tabs.size(); i++) {
41
         for (int i = 0; i < tabs.size(); i++) {
42
             BottomTabOptions tab = tabs.get(i).options.copy().withDefaultOptions(defaultOptions).bottomTabOptions;
42
             BottomTabOptions tab = tabs.get(i).options.copy().withDefaultOptions(defaultOptions).bottomTabOptions;
43
             bottomTabs.setBadge(i, tab.badge.get(""));
43
             bottomTabs.setBadge(i, tab.badge.get(""));
44
+            bottomTabs.setBadgeColor(tab.badgeColor.get(null));
44
             bottomTabs.setTitleTypeface(i, tab.fontFamily);
45
             bottomTabs.setTitleTypeface(i, tab.fontFamily);
45
             bottomTabs.setIconActiveColor(i, tab.selectedIconColor.get(null));
46
             bottomTabs.setIconActiveColor(i, tab.selectedIconColor.get(null));
46
             bottomTabs.setIconInactiveColor(i, tab.iconColor.get(null));
47
             bottomTabs.setIconInactiveColor(i, tab.iconColor.get(null));
55
         BottomTabOptions withDefaultOptions = options.withDefaultOptions(defaultOptions).bottomTabOptions;
56
         BottomTabOptions withDefaultOptions = options.withDefaultOptions(defaultOptions).bottomTabOptions;
56
         int index = bottomTabFinder.findByComponent(child);
57
         int index = bottomTabFinder.findByComponent(child);
57
         if (withDefaultOptions.badge.hasValue()) bottomTabs.setBadge(index, withDefaultOptions.badge.get());
58
         if (withDefaultOptions.badge.hasValue()) bottomTabs.setBadge(index, withDefaultOptions.badge.get());
59
+        if (withDefaultOptions.badgeColor.hasValue()) bottomTabs.setBadgeColor(withDefaultOptions.badgeColor.get());
58
         if (withDefaultOptions.fontFamily != null) bottomTabs.setTitleTypeface(index, withDefaultOptions.fontFamily);
60
         if (withDefaultOptions.fontFamily != null) bottomTabs.setTitleTypeface(index, withDefaultOptions.fontFamily);
59
         if (withDefaultOptions.selectedIconColor.hasValue()) bottomTabs.setIconActiveColor(index, withDefaultOptions.selectedIconColor.get());
61
         if (withDefaultOptions.selectedIconColor.hasValue()) bottomTabs.setIconActiveColor(index, withDefaultOptions.selectedIconColor.get());
60
         if (withDefaultOptions.iconColor.hasValue()) bottomTabs.setIconInactiveColor(index, withDefaultOptions.iconColor.get());
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
 
2
 
3
 import android.annotation.SuppressLint;
3
 import android.annotation.SuppressLint;
4
 import android.content.Context;
4
 import android.content.Context;
5
+import android.support.annotation.ColorInt;
5
 import android.support.annotation.IntRange;
6
 import android.support.annotation.IntRange;
6
 import android.view.View;
7
 import android.view.View;
7
 
8
 
29
         setNotification(badge, bottomTabIndex);
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
     @Override
38
     @Override
33
     public void setCurrentItem(@IntRange(from = 0) int position) {
39
     public void setCurrentItem(@IntRange(from = 0) int position) {
34
         super.setCurrentItem(position);
40
         super.setCurrentItem(position);

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

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

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

46
 		if (self.badge != nil && ![self.badge isEqual:[NSNull null]]) {
46
 		if (self.badge != nil && ![self.badge isEqual:[NSNull null]]) {
47
 			badge = [RCTConvert NSString:self.badge];
47
 			badge = [RCTConvert NSString:self.badge];
48
 		}
48
 		}
49
+		UITabBarItem *tabBarItem = viewController.tabBarItem;
49
 		if (viewController.navigationController) {
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