Parcourir la source

screen background fix on iOS (#3332)

* Screen background option fixed in iOS

* fix unit tests
Yogev B il y a 6 ans
Parent
révision
7fee4b8de5
No account linked to committer's email address

+ 1
- 1
lib/ios/RNNLayoutOptions.h Voir le fichier

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

+ 3
- 3
lib/ios/RNNLayoutOptions.m Voir le fichier

@@ -4,8 +4,8 @@
4 4
 @implementation RNNLayoutOptions
5 5
 
6 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 9
 		viewController.view.backgroundColor = screenColor;
10 10
 	}
11 11
 }
@@ -32,7 +32,7 @@
32 32
 			}
33 33
 		}
34 34
 	}
35
-	
35
+
36 36
 	return supportedOrientationsMask;
37 37
 }
38 38
 

+ 31
- 31
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m Voir le fichier

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