Browse Source

Fixes backButton.color issue - #4150

yogevbd 6 years ago
parent
commit
91145214ea

+ 53
- 0
lib/ios/ReactNativeNavigationTests/UINavigationController+RNNOptionsTest.m View File

@@ -0,0 +1,53 @@
1
+#import <XCTest/XCTest.h>
2
+#import "UINavigationController+RNNOptions.h"
3
+
4
+@interface UINavigationController_RNNOptionsTest : XCTestCase
5
+
6
+@end
7
+
8
+@implementation UINavigationController_RNNOptionsTest
9
+
10
+- (void)setUp {
11
+    [super setUp];
12
+}
13
+
14
+- (void)testSetBackButtonIcon_withColor_shouldSetColor {
15
+	UIViewController* viewController = [UIViewController new];
16
+	UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:viewController];
17
+	UIColor* color = [UIColor blackColor];
18
+	
19
+	[nav rnn_setBackButtonIcon:nil withColor:color title:nil];
20
+	XCTAssertEqual(color, viewController.navigationItem.backBarButtonItem.tintColor);
21
+}
22
+
23
+- (void)testSetBackButtonIcon_withColor_shouldSetTitle {
24
+	UIViewController* viewController = [UIViewController new];
25
+	UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:viewController];
26
+	NSString* title = @"Title";
27
+	
28
+	[nav rnn_setBackButtonIcon:nil withColor:nil title:title];
29
+	XCTAssertEqual(title, viewController.navigationItem.backBarButtonItem.title);
30
+}
31
+
32
+- (void)testSetBackButtonIcon_withColor_shouldSetIcon {
33
+	UIViewController* viewController = [UIViewController new];
34
+	UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:viewController];
35
+	UIImage* icon = [UIImage new];
36
+	
37
+	[nav rnn_setBackButtonIcon:icon withColor:nil title:nil];
38
+	XCTAssertEqual(icon, viewController.navigationItem.backBarButtonItem.image);
39
+}
40
+
41
+- (void)testSetBackButtonIcon_shouldSetTitleOnPreviousViewControllerIfExists {
42
+	UIViewController* viewController = [UIViewController new];
43
+	UIViewController* viewController2 = [UIViewController new];
44
+	UINavigationController* nav = [[UINavigationController alloc] init];
45
+	[nav setViewControllers:@[viewController, viewController2]];
46
+	NSString* title = @"Title";
47
+
48
+	[nav rnn_setBackButtonIcon:nil withColor:nil title:title];
49
+	XCTAssertEqual(title, viewController.navigationItem.backBarButtonItem.title);
50
+}
51
+
52
+
53
+@end

+ 1
- 0
lib/ios/UINavigationController+RNNOptions.m View File

@@ -112,6 +112,7 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
112 112
 	UIViewController *lastViewControllerInStack = self.viewControllers.count > 1 ? [self.viewControllers objectAtIndex:self.viewControllers.count-2] : self.topViewController;
113 113
 	
114 114
 	backItem.title = title ? title : lastViewControllerInStack.navigationItem.title;
115
+	backItem.tintColor = color;
115 116
 	
116 117
 	lastViewControllerInStack.navigationItem.backBarButtonItem = backItem;
117 118
 }