瀏覽代碼

V2 add additional ios options for tabbar icons (#3296)

* add option to disable tabbar icon tints and add custom selected icons

*  update docs for disabling tabbar icon tint and selectedIcon

* move new options to ios-specific section in docs

* delete trailing comma in docs
cshen4 6 年之前
父節點
當前提交
1b8bbbeded
共有 3 個檔案被更改,包括 27 行新增2 行删除
  1. 4
    1
      docs/docs/styling.md
  2. 3
    0
      lib/ios/RNNBottomTabOptions.h
  3. 20
    1
      lib/ios/RNNBottomTabOptions.m

+ 4
- 1
docs/docs/styling.md 查看文件

@@ -188,7 +188,10 @@ Navigation.mergeOptions(this.props.componentId, {
188 188
     hideShadow: false
189 189
   },
190 190
   bottomTab: {
191
-    iconInsets: { top: 0, left: 0, bottom: 0, right: 0 }
191
+    iconInsets: { top: 0, left: 0, bottom: 0, right: 0 },
192
+    selectedIcon: require('selectedTab.png'),
193
+    disableIconTint: true, //set true if you want to disable the icon tinting
194
+    disableSelectedIconTint: true
192 195
   }
193 196
 }
194 197
 ```

+ 3
- 0
lib/ios/RNNBottomTabOptions.h 查看文件

@@ -8,6 +8,9 @@
8 8
 @property (nonatomic, strong) NSString* testID;
9 9
 @property (nonatomic, strong) NSNumber* visible;
10 10
 @property (nonatomic, strong) NSDictionary* icon;
11
+@property (nonatomic, strong) NSDictionary* selectedIcon;
12
+@property (nonatomic, strong) NSDictionary* disableIconTint;
13
+@property (nonatomic, strong) NSDictionary* disableSelectedIconTint;
11 14
 @property (nonatomic, strong) NSDictionary* iconInsets;
12 15
 
13 16
 @end

+ 20
- 1
lib/ios/RNNBottomTabOptions.m 查看文件

@@ -13,7 +13,13 @@
13 13
 
14 14
 - (void)applyOn:(UIViewController *)viewController {
15 15
 	if (self.title || self.icon) {
16
-		UITabBarItem* tabItem = [[UITabBarItem alloc] initWithTitle:self.title image:[RCTConvert UIImage:self.icon] tag:self.tag];
16
+		UIImage *iconImage = nil;
17
+		if (self.disableIconTint) {
18
+			iconImage = [[RCTConvert UIImage:self.icon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
19
+		} else {
20
+			iconImage = [RCTConvert UIImage:self.icon];
21
+		}
22
+		UITabBarItem* tabItem = [[UITabBarItem alloc] initWithTitle:self.title image:iconImage tag:self.tag];
17 23
 		tabItem.accessibilityIdentifier = self.testID;
18 24
 		
19 25
 		if (self.iconInsets && ![self.iconInsets isKindOfClass:[NSNull class]]) {
@@ -32,6 +38,19 @@
32 38
 		
33 39
 		[viewController.navigationController setTabBarItem:tabItem];
34 40
 	}
41
+	if (self.selectedIcon) {
42
+		UIImage *selectedIconImage = nil;
43
+		if (self.disableSelectedIconTint) {
44
+			selectedIconImage = [[RCTConvert UIImage:self.selectedIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
45
+		} else {
46
+			selectedIconImage = [RCTConvert UIImage:self.selectedIcon];
47
+		}
48
+		if (viewController.navigationController) {
49
+			viewController.navigationController.tabBarItem.selectedImage = selectedIconImage;
50
+		} else {
51
+			viewController.tabBarItem.selectedImage = selectedIconImage;
52
+		}	
53
+	}
35 54
 	
36 55
 	if (self.badge) {
37 56
 		NSString *badge = nil;