Browse Source

screen background fix on iOS (#3332)

* Screen background option fixed in iOS

* fix unit tests
Yogev B 6 years ago
parent
commit
7fee4b8de5
No account linked to committer's email address

+ 1
- 1
lib/ios/RNNLayoutOptions.h View File

2
 
2
 
3
 @interface RNNLayoutOptions : RNNOptions
3
 @interface RNNLayoutOptions : RNNOptions
4
 
4
 
5
-@property (nonatomic, strong) NSNumber* screenBackgroundColor;
5
+@property (nonatomic, strong) NSNumber* backgroundColor;
6
 @property (nonatomic, strong) id orientation;
6
 @property (nonatomic, strong) id orientation;
7
 
7
 
8
 - (UIInterfaceOrientationMask)supportedOrientations;
8
 - (UIInterfaceOrientationMask)supportedOrientations;

+ 3
- 3
lib/ios/RNNLayoutOptions.m View File

4
 @implementation RNNLayoutOptions
4
 @implementation RNNLayoutOptions
5
 
5
 
6
 - (void)applyOn:(UIViewController *)viewController {
6
 - (void)applyOn:(UIViewController *)viewController {
7
-	if (self.screenBackgroundColor) {
8
-		UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
7
+	if (self.backgroundColor) {
8
+		UIColor* screenColor = [RCTConvert UIColor:self.backgroundColor];
9
 		viewController.view.backgroundColor = screenColor;
9
 		viewController.view.backgroundColor = screenColor;
10
 	}
10
 	}
11
 }
11
 }
32
 			}
32
 			}
33
 		}
33
 		}
34
 	}
34
 	}
35
-	
35
+
36
 	return supportedOrientationsMask;
36
 	return supportedOrientationsMask;
37
 }
37
 }
38
 
38
 

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

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];
54
-	
54
+
55
 	XCTAssertTrue([self.uut.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
55
 	XCTAssertTrue([self.uut.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
56
 }
56
 }
57
 
57
 
58
 -(void)testTopBarBackgroundColorWithoutNavigationController{
58
 -(void)testTopBarBackgroundColorWithoutNavigationController{
59
 	NSNumber* inputColor = @(0xFFFF0000);
59
 	NSNumber* inputColor = @(0xFFFF0000);
60
 	self.options.topBar.background.color = inputColor;
60
 	self.options.topBar.background.color = inputColor;
61
-	
61
+
62
 	XCTAssertNoThrow([self.uut viewWillAppear:false]);
62
 	XCTAssertNoThrow([self.uut viewWillAppear:false]);
63
 }
63
 }
64
 
64
 
65
 - (void)testStatusBarHidden_default {
65
 - (void)testStatusBarHidden_default {
66
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
66
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
67
 	[self.uut viewWillAppear:false];
67
 	[self.uut viewWillAppear:false];
68
-	
68
+
69
 	XCTAssertFalse([self.uut prefersStatusBarHidden]);
69
 	XCTAssertFalse([self.uut prefersStatusBarHidden]);
70
 }
70
 }
71
 
71
 
73
 	self.options.statusBar.hidden = @(1);
73
 	self.options.statusBar.hidden = @(1);
74
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
74
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
75
 	[self.uut viewWillAppear:false];
75
 	[self.uut viewWillAppear:false];
76
-	
76
+
77
 	XCTAssertTrue([self.uut prefersStatusBarHidden]);
77
 	XCTAssertTrue([self.uut prefersStatusBarHidden]);
78
 }
78
 }
79
 
79
 
82
 	self.options.topBar.visible = @(0);
82
 	self.options.topBar.visible = @(0);
83
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
83
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
84
 	[self.uut viewWillAppear:false];
84
 	[self.uut viewWillAppear:false];
85
-	
85
+
86
 	XCTAssertFalse([self.uut prefersStatusBarHidden]);
86
 	XCTAssertFalse([self.uut prefersStatusBarHidden]);
87
 }
87
 }
88
 
88
 
100
 	self.options.statusBar.hidden = @(0);
100
 	self.options.statusBar.hidden = @(0);
101
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
101
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
102
 	[self.uut viewWillAppear:false];
102
 	[self.uut viewWillAppear:false];
103
-	
103
+
104
 	XCTAssertFalse([self.uut prefersStatusBarHidden]);
104
 	XCTAssertFalse([self.uut prefersStatusBarHidden]);
105
 }
105
 }
106
 
106
 
108
 	NSString* title =@"some title";
108
 	NSString* title =@"some title";
109
 	self.options.topBar.title.text = title;
109
 	self.options.topBar.title.text = title;
110
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
110
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
111
-	
111
+
112
 	[self.uut viewWillAppear:false];
112
 	[self.uut viewWillAppear:false];
113
 	XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
113
 	XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
114
 }
114
 }
115
 
115
 
116
 -(void)testTitle_default{
116
 -(void)testTitle_default{
117
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
117
 	__unused RNNNavigationController* nav = [[RNNNavigationController alloc] initWithRootViewController:self.uut];
118
-	
118
+
119
 	[self.uut viewWillAppear:false];
119
 	[self.uut viewWillAppear:false];
120
 	XCTAssertNil(self.uut.navigationItem.title);
120
 	XCTAssertNil(self.uut.navigationItem.title);
121
 }
121
 }
129
 	XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
129
 	XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
130
 }
130
 }
131
 
131
 
132
--(void)testScreenBackgroundColor_validColor{
132
+-(void)testbackgroundColor_validColor{
133
 	NSNumber* inputColor = @(0xFFFF0000);
133
 	NSNumber* inputColor = @(0xFFFF0000);
134
-	self.options.layout.screenBackgroundColor = inputColor;
134
+	self.options.layout.backgroundColor = inputColor;
135
 	[self.uut viewWillAppear:false];
135
 	[self.uut viewWillAppear:false];
136
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
136
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
137
 	XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
137
 	XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
198
 	[vc setViewControllers:controllers];
198
 	[vc setViewControllers:controllers];
199
 	[self.uut viewWillAppear:false];
199
 	[self.uut viewWillAppear:false];
200
 	XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
200
 	XCTAssertTrue([self.uut.tabBarItem.badgeValue isEqualToString:tabBadgeInput]);
201
-	
201
+
202
 }
202
 }
203
 
203
 
204
 -(void)testTopBarTransparent_BOOL_True {
204
 -(void)testTopBarTransparent_BOOL_True {
222
 
222
 
223
 
223
 
224
 -(void)testStoreOriginalTopBarImages {
224
 -(void)testStoreOriginalTopBarImages {
225
-	
225
+
226
 }
226
 }
227
 
227
 
228
 
228
 
404
 	self.options.layout.orientation = supportedOrientations;
404
 	self.options.layout.orientation = supportedOrientations;
405
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
405
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
406
 	NSMutableArray* controllers = [NSMutableArray new];
406
 	NSMutableArray* controllers = [NSMutableArray new];
407
-	
407
+
408
 	[controllers addObject:self.uut];
408
 	[controllers addObject:self.uut];
409
 	[vc setViewControllers:controllers];
409
 	[vc setViewControllers:controllers];
410
 	[self.uut viewWillAppear:false];
410
 	[self.uut viewWillAppear:false];
411
-	
411
+
412
 	UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
412
 	UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskPortrait;
413
 	XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
413
 	XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
414
 }
414
 }
418
 	self.options.layout.orientation = supportedOrientations;
418
 	self.options.layout.orientation = supportedOrientations;
419
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
419
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
420
 	NSMutableArray* controllers = [NSMutableArray new];
420
 	NSMutableArray* controllers = [NSMutableArray new];
421
-	
421
+
422
 	[controllers addObject:self.uut];
422
 	[controllers addObject:self.uut];
423
 	[vc setViewControllers:controllers];
423
 	[vc setViewControllers:controllers];
424
 	[self.uut viewWillAppear:false];
424
 	[self.uut viewWillAppear:false];
425
-	
425
+
426
 	UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
426
 	UIInterfaceOrientationMask expectedOrientation = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape);
427
 	XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
427
 	XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
428
 }
428
 }
432
 	self.options.layout.orientation = supportedOrientations;
432
 	self.options.layout.orientation = supportedOrientations;
433
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
433
 	__unused RNNTabBarController* vc = [[RNNTabBarController alloc] init];
434
 	NSMutableArray* controllers = [NSMutableArray new];
434
 	NSMutableArray* controllers = [NSMutableArray new];
435
-	
435
+
436
 	[controllers addObject:self.uut];
436
 	[controllers addObject:self.uut];
437
 	[vc setViewControllers:controllers];
437
 	[vc setViewControllers:controllers];
438
 	[self.uut viewWillAppear:false];
438
 	[self.uut viewWillAppear:false];
439
-	
439
+
440
 	UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
440
 	UIInterfaceOrientationMask expectedOrientation = UIInterfaceOrientationMaskAll;
441
 	XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
441
 	XCTAssertTrue(self.uut.tabBarController.supportedInterfaceOrientations == expectedOrientation);
442
 }
442
 }
445
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"title": @"test"}];
445
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"title": @"test"}];
446
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
446
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
447
 	[self.uut viewWillAppear:false];
447
 	[self.uut viewWillAppear:false];
448
-	
448
+
449
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
449
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
450
 	NSString* expectedButtonId = @"testId";
450
 	NSString* expectedButtonId = @"testId";
451
 	NSString* expectedTitle = @"test";
451
 	NSString* expectedTitle = @"test";
456
 
456
 
457
 -(void)testRightButtonsWithTitle_withStyle {
457
 -(void)testRightButtonsWithTitle_withStyle {
458
 	NSNumber* inputColor = @(0xFFFF0000);
458
 	NSNumber* inputColor = @(0xFFFF0000);
459
-	
459
+
460
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"title": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
460
 	self.options.topBar.rightButtons = @[@{@"id": @"testId", @"title": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
461
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
461
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
462
 	[self.uut viewWillAppear:false];
462
 	[self.uut viewWillAppear:false];
463
-	
463
+
464
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
464
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.rightBarButtonItems objectAtIndex:0];
465
 	NSString* expectedButtonId = @"testId";
465
 	NSString* expectedButtonId = @"testId";
466
 	NSString* expectedTitle = @"test";
466
 	NSString* expectedTitle = @"test";
467
 	XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
467
 	XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
468
 	XCTAssertTrue([button.title isEqualToString:expectedTitle]);
468
 	XCTAssertTrue([button.title isEqualToString:expectedTitle]);
469
 	XCTAssertFalse(button.enabled);
469
 	XCTAssertFalse(button.enabled);
470
-	
470
+
471
 	//TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
471
 	//TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
472
 }
472
 }
473
 
473
 
476
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"title": @"test"}];
476
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"title": @"test"}];
477
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
477
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
478
 	[self.uut viewWillAppear:false];
478
 	[self.uut viewWillAppear:false];
479
-	
479
+
480
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
480
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
481
 	NSString* expectedButtonId = @"testId";
481
 	NSString* expectedButtonId = @"testId";
482
 	NSString* expectedTitle = @"test";
482
 	NSString* expectedTitle = @"test";
487
 
487
 
488
 -(void)testLeftButtonsWithTitle_withStyle {
488
 -(void)testLeftButtonsWithTitle_withStyle {
489
 	NSNumber* inputColor = @(0xFFFF0000);
489
 	NSNumber* inputColor = @(0xFFFF0000);
490
-	
490
+
491
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"title": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
491
 	self.options.topBar.leftButtons = @[@{@"id": @"testId", @"title": @"test", @"enabled": @false, @"buttonColor": inputColor, @"buttonFontSize": @22, @"buttonFontWeight": @"800"}];
492
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
492
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
493
 	[self.uut viewWillAppear:false];
493
 	[self.uut viewWillAppear:false];
494
-	
494
+
495
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
495
 	RNNUIBarButtonItem* button = (RNNUIBarButtonItem*)[nav.topViewController.navigationItem.leftBarButtonItems objectAtIndex:0];
496
 	NSString* expectedButtonId = @"testId";
496
 	NSString* expectedButtonId = @"testId";
497
 	NSString* expectedTitle = @"test";
497
 	NSString* expectedTitle = @"test";
498
 	XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
498
 	XCTAssertTrue([button.buttonId isEqualToString:expectedButtonId]);
499
 	XCTAssertTrue([button.title isEqualToString:expectedTitle]);
499
 	XCTAssertTrue([button.title isEqualToString:expectedTitle]);
500
 	XCTAssertFalse(button.enabled);
500
 	XCTAssertFalse(button.enabled);
501
-	
501
+
502
 	//TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
502
 	//TODO: Determine how to tests buttonColor,buttonFontSize and buttonFontWeight?
503
 }
503
 }
504
 
504
 
585
 	self.options.backgroundImage = backgroundImage;
585
 	self.options.backgroundImage = backgroundImage;
586
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
586
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
587
 	[self.uut viewWillAppear:false];
587
 	[self.uut viewWillAppear:false];
588
-	
588
+
589
 	XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage]);
589
 	XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage]);
590
 }
590
 }
591
 
591
 
601
 	self.options.topBar.drawBehind = @(1);
601
 	self.options.topBar.drawBehind = @(1);
602
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
602
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
603
 	[self.uut viewWillAppear:false];
603
 	[self.uut viewWillAppear:false];
604
-	
604
+
605
 	XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
605
 	XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
606
 }
606
 }
607
 
607
 
609
 	self.options.topBar.drawBehind = @(0);
609
 	self.options.topBar.drawBehind = @(0);
610
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
610
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
611
 	[self.uut viewWillAppear:false];
611
 	[self.uut viewWillAppear:false];
612
-	
612
+
613
 	XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
613
 	XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
614
 }
614
 }
615
 
615
 
617
 	self.options.bottomTabs.drawBehind = @(1);
617
 	self.options.bottomTabs.drawBehind = @(1);
618
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
618
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
619
 	[self.uut viewWillAppear:false];
619
 	[self.uut viewWillAppear:false];
620
-	
620
+
621
 	XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
621
 	XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
622
 }
622
 }
623
 
623
 
625
 	self.options.bottomTabs.drawBehind = @(0);
625
 	self.options.bottomTabs.drawBehind = @(0);
626
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
626
 	__unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
627
 	[self.uut viewWillAppear:false];
627
 	[self.uut viewWillAppear:false];
628
-	
628
+
629
 	XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
629
 	XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
630
 }
630
 }
631
 
631