Browse Source

clean top bar background component

yogevbd 6 years ago
parent
commit
f7de6051b4

+ 7
- 0
lib/ios/RNNRootViewController.m View File

80
         reactView.backgroundColor = UIColor.clearColor;
80
         reactView.backgroundColor = UIColor.clearColor;
81
 		titleView.backgroundColor = UIColor.clearColor;
81
 		titleView.backgroundColor = UIColor.clearColor;
82
 		self.navigationItem.titleView = titleView;
82
 		self.navigationItem.titleView = titleView;
83
+	} if ([self.navigationItem.title isKindOfClass:[RNNCustomTitleView class]]) {
84
+		self.navigationItem.title = nil;
83
 	}
85
 	}
84
 }
86
 }
85
 
87
 
91
 		reactView.backgroundColor = UIColor.clearColor;
93
 		reactView.backgroundColor = UIColor.clearColor;
92
 		titleView.backgroundColor = UIColor.clearColor;
94
 		titleView.backgroundColor = UIColor.clearColor;
93
 		[self.navigationController.navigationBar addSubview:titleView];
95
 		[self.navigationController.navigationBar addSubview:titleView];
96
+	} else if ([[self.navigationController.navigationBar.subviews lastObject] isKindOfClass:[RNNCustomTitleView class]]) {
97
+		[[self.navigationController.navigationBar.subviews lastObject] removeFromSuperview];
94
 	}
98
 	}
95
 }
99
 }
96
 
100
 
101
 		RNNCustomTitleView *titleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
105
 		RNNCustomTitleView *titleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
102
 		[self.navigationController.navigationBar insertSubview:titleView atIndex:1];
106
 		[self.navigationController.navigationBar insertSubview:titleView atIndex:1];
103
 		self.navigationController.navigationBar.clipsToBounds = YES;
107
 		self.navigationController.navigationBar.clipsToBounds = YES;
108
+	} else if ([[self.navigationController.navigationBar.subviews objectAtIndex:1] isKindOfClass:[RNNCustomTitleView class]]) {
109
+		[[self.navigationController.navigationBar.subviews objectAtIndex:1] removeFromSuperview];
110
+		self.navigationController.navigationBar.clipsToBounds = NO;
104
 	}
111
 	}
105
 }
112
 }
106
 
113
 

+ 2
- 2
lib/ios/RNNTopBarOptions.m View File

15
 
15
 
16
 - (instancetype)initWithDict:(NSDictionary *)dict {
16
 - (instancetype)initWithDict:(NSDictionary *)dict {
17
 	self = [super initWithDict:dict];
17
 	self = [super initWithDict:dict];
18
-	self.title = [RNNTitleOptions new];
19
-	self.background = [RNNBackgrounOptions new];
18
+	self.title = [[RNNTitleOptions alloc] initWithDict:dict[@"title"]];
19
+	self.background = [[RNNBackgrounOptions alloc] initWithDict:dict[@"background"]];
20
 	
20
 	
21
 	return self;
21
 	return self;
22
 }
22
 }

+ 4
- 4
lib/ios/ReactNativeNavigationTests/RNNNavigationOptionsTest.m View File

16
 	XCTAssertTrue([options isKindOfClass:[RNNNavigationOptions class]]);
16
 	XCTAssertTrue([options isKindOfClass:[RNNNavigationOptions class]]);
17
 }
17
 }
18
 - (void)testAddsStyleFromDictionaryWithInit {
18
 - (void)testAddsStyleFromDictionaryWithInit {
19
-	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"backgroundColor" : @(0xff0000ff)}}];
20
-	XCTAssertTrue(options.topBar.backgroundColor);
19
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
20
+	XCTAssertTrue(options.topBar.background.color);
21
 }
21
 }
22
 
22
 
23
 - (void)testChangeRNNNavigationOptionsDynamically {
23
 - (void)testChangeRNNNavigationOptionsDynamically {
24
-	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"backgroundColor" : @(0xff0000ff)}}];
24
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
25
 	NSDictionary* dynamicOptions = @{@"topBar": @{@"textColor" : @(0xffff00ff), @"title" : @{@"text": @"hello"}}};
25
 	NSDictionary* dynamicOptions = @{@"topBar": @{@"textColor" : @(0xffff00ff), @"title" : @{@"text": @"hello"}}};
26
 	[options mergeWith:dynamicOptions];
26
 	[options mergeWith:dynamicOptions];
27
 	XCTAssertTrue([options.topBar.title.text isEqual:@"hello"]);
27
 	XCTAssertTrue([options.topBar.title.text isEqual:@"hello"]);
28
 }
28
 }
29
 
29
 
30
 - (void)testChangeRNNNavigationOptionsWithInvalidProperties {
30
 - (void)testChangeRNNNavigationOptionsWithInvalidProperties {
31
-	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"backgroundColor" : @(0xff0000ff)}}];
31
+	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
32
 	NSDictionary* dynamicOptions = @{@"topBar": @{@"titleeeee" : @"hello"}};
32
 	NSDictionary* dynamicOptions = @{@"topBar": @{@"titleeeee" : @"hello"}};
33
 	XCTAssertNoThrow([options mergeWith:dynamicOptions]);
33
 	XCTAssertNoThrow([options mergeWith:dynamicOptions]);
34
 }
34
 }

+ 2
- 2
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

47
 
47
 
48
 -(void)testTopBarBackgroundColor_validColor{
48
 -(void)testTopBarBackgroundColor_validColor{
49
 	NSNumber* inputColor = @(0xFFFF0000);
49
 	NSNumber* inputColor = @(0xFFFF0000);
50
-	self.options.topBar.backgroundColor = inputColor;
50
+	self.options.topBar.background.color = inputColor;
51
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
51
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
52
 	[self.uut viewWillAppear:false];
52
 	[self.uut viewWillAppear:false];
53
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
53
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
57
 
57
 
58
 -(void)testTopBarBackgroundColorWithoutNavigationController{
58
 -(void)testTopBarBackgroundColorWithoutNavigationController{
59
 	NSNumber* inputColor = @(0xFFFF0000);
59
 	NSNumber* inputColor = @(0xFFFF0000);
60
-	self.options.topBar.backgroundColor = inputColor;
60
+	self.options.topBar.background.color = inputColor;
61
 	
61
 	
62
 	XCTAssertNoThrow([self.uut viewWillAppear:false]);
62
 	XCTAssertNoThrow([self.uut viewWillAppear:false]);
63
 }
63
 }