Explorar el Código

clean top bar background component

yogevbd hace 6 años
padre
commit
f7de6051b4

+ 7
- 0
lib/ios/RNNRootViewController.m Ver fichero

@@ -80,6 +80,8 @@
80 80
         reactView.backgroundColor = UIColor.clearColor;
81 81
 		titleView.backgroundColor = UIColor.clearColor;
82 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,6 +93,8 @@
91 93
 		reactView.backgroundColor = UIColor.clearColor;
92 94
 		titleView.backgroundColor = UIColor.clearColor;
93 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,6 +105,9 @@
101 105
 		RNNCustomTitleView *titleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:@"fill"];
102 106
 		[self.navigationController.navigationBar insertSubview:titleView atIndex:1];
103 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 Ver fichero

@@ -15,8 +15,8 @@ extern const NSInteger BLUR_TOPBAR_TAG;
15 15
 
16 16
 - (instancetype)initWithDict:(NSDictionary *)dict {
17 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 21
 	return self;
22 22
 }

+ 4
- 4
lib/ios/ReactNativeNavigationTests/RNNNavigationOptionsTest.m Ver fichero

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

+ 2
- 2
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m Ver fichero

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