浏览代码

Added backButton.color support

yogevbd 6 年前
父节点
当前提交
98ff69ec56
共有 4 个文件被更改,包括 25 次插入20 次删除
  1. 1
    0
      lib/ios/RNNBackButtonOptions.h
  2. 22
    11
      lib/ios/RNNBackButtonOptions.m
  3. 2
    2
      lib/ios/RNNTitleOptions.m
  4. 0
    7
      lib/ios/RNNTopBarOptions.m

+ 1
- 0
lib/ios/RNNBackButtonOptions.h 查看文件

@@ -7,5 +7,6 @@
7 7
 @property (nonatomic, strong) NSString* title;
8 8
 @property (nonatomic, strong) NSString* transition;
9 9
 @property (nonatomic, strong) NSNumber* showTitle;
10
+@property (nonatomic, strong) NSNumber* color;
10 11
 
11 12
 @end

+ 22
- 11
lib/ios/RNNBackButtonOptions.m 查看文件

@@ -1,12 +1,23 @@
1 1
 #import "RNNBackButtonOptions.h"
2
+#import "UIImage+tint.h"
2 3
 
3 4
 @implementation RNNBackButtonOptions
4 5
 
5 6
 - (void)applyOn:(UIViewController *)viewController {
6 7
 	if (self.icon) {
7
-		UIImage *image = self.icon ? [RCTConvert UIImage:self.icon] : nil;
8
-		[viewController.navigationController.navigationBar setBackIndicatorImage:image];
9
-		[viewController.navigationController.navigationBar setBackIndicatorTransitionMaskImage:image];
8
+		UIImage *image = self.tintedIcon;
9
+		[viewController.navigationController.navigationBar setBackIndicatorImage:[UIImage new]];
10
+		[viewController.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];
11
+		
12
+		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:nil action:nil];
13
+		viewController.navigationItem.backBarButtonItem = backItem;
14
+	} else if (self.title) {
15
+		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:self.title
16
+																	 style:UIBarButtonItemStylePlain
17
+																	target:nil
18
+																	action:nil];
19
+		
20
+		viewController.navigationItem.backBarButtonItem = backItem;
10 21
 	}
11 22
 	
12 23
 	if (self.visible) {
@@ -16,15 +27,15 @@
16 27
 	if (self.showTitle && ![self.showTitle boolValue]) {
17 28
 		self.title = @"";
18 29
 	}
19
-	
20
-	if (self.title) {
21
-		UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:self.title
22
-																	 style:UIBarButtonItemStylePlain
23
-																	target:nil
24
-																	action:nil];
25
-		
26
-		viewController.navigationItem.backBarButtonItem = backItem;
30
+}
31
+
32
+- (UIImage *)tintedIcon {
33
+	UIImage *image = self.icon ? [RCTConvert UIImage:self.icon] : nil;
34
+	if (self.color) {
35
+		return [[image withTintColor:[RCTConvert UIColor:self.color]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
27 36
 	}
37
+	
38
+	return image;
28 39
 }
29 40
 
30 41
 @end

+ 2
- 2
lib/ios/RNNTitleOptions.m 查看文件

@@ -10,7 +10,7 @@
10 10
 	}
11 11
 	
12 12
 	NSDictionary* fontAttributes = [self fontAttributes];
13
-	
13
+
14 14
 	if (fontAttributes.allKeys.count > 0) {
15 15
 		viewController.navigationController.navigationBar.titleTextAttributes = fontAttributes;
16 16
 	}
@@ -31,7 +31,7 @@
31 31
 			if (self.fontSize) {
32 32
 				navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:[self.fontSize floatValue]];
33 33
 			} else {
34
-				navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:20];
34
+				navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:self.fontFamily size:17];
35 35
 			}
36 36
 		} else if (self.fontSize) {
37 37
 			navigationBarTitleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:[self.fontSize floatValue]];

+ 0
- 7
lib/ios/RNNTopBarOptions.m 查看文件

@@ -64,13 +64,6 @@ extern const NSInteger BLUR_TOPBAR_TAG;
64 64
 		viewController.navigationController.hidesBarsOnSwipe = NO;
65 65
 	}
66 66
 	
67
-	if (self.buttonColor) {
68
-		UIColor* buttonColor = [RCTConvert UIColor:self.buttonColor];
69
-		viewController.navigationController.navigationBar.tintColor = buttonColor;
70
-	} else {
71
-		viewController.navigationController.navigationBar.tintColor = nil;
72
-	}
73
-	
74 67
 	if ([self.blur boolValue]) {
75 68
 		if (![viewController.navigationController.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) {
76 69