Browse Source

screen Background Color iOS (#1631)

bogobogo 7 years ago
parent
commit
f90a28146a

+ 0
- 1
lib/ios/RNNControllerFactory.m View File

118
 		UIViewController *vc = [self fromTree:child];
118
 		UIViewController *vc = [self fromTree:child];
119
 		[childrenVCs addObject:vc];
119
 		[childrenVCs addObject:vc];
120
 	}
120
 	}
121
-	
122
 	RNNSideMenuController *sideMenu = [[RNNSideMenuController alloc] initWithControllers:childrenVCs];
121
 	RNNSideMenuController *sideMenu = [[RNNSideMenuController alloc] initWithControllers:childrenVCs];
123
 	return sideMenu;
122
 	return sideMenu;
124
 }
123
 }

+ 1
- 0
lib/ios/RNNNavigationOptions.h View File

7
 @property (nonatomic, strong) NSNumber* topBarTextColor;
7
 @property (nonatomic, strong) NSNumber* topBarTextColor;
8
 @property (nonatomic, strong) NSNumber* statusBarHidden;
8
 @property (nonatomic, strong) NSNumber* statusBarHidden;
9
 @property (nonatomic, strong) NSString* title;
9
 @property (nonatomic, strong) NSString* title;
10
+@property (nonatomic, strong) NSNumber* screenBackgroundColor;
10
 @property (nonatomic, strong) NSString* setTabBadge;
11
 @property (nonatomic, strong) NSString* setTabBadge;
11
 
12
 
12
 -(instancetype)init;
13
 -(instancetype)init;

+ 15
- 10
lib/ios/RNNNavigationOptions.m View File

9
 }
9
 }
10
 
10
 
11
 -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
11
 -(instancetype)initWithDict:(NSDictionary *)navigationOptions {
12
-	if(self = [super init]) {
13
-		self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
14
-		self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
15
-		self.title = [navigationOptions objectForKey:@"title"];
16
-		self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
17
-		self.setTabBadge = [navigationOptions objectForKey:@"setTabBadge"];
18
-	}
12
+	self = [super init];
13
+	self.topBarBackgroundColor = [navigationOptions objectForKey:@"topBarBackgroundColor"];
14
+	self.statusBarHidden = [navigationOptions objectForKey:@"statusBarHidden"];
15
+	self.title = [navigationOptions objectForKey:@"title"];
16
+	self.topBarTextColor = [navigationOptions objectForKey:@"topBarTextColor"];
17
+	self.screenBackgroundColor = [navigationOptions objectForKey:@"screenBackgroundColor"];
18
+	self.setTabBadge = [navigationOptions objectForKey:@"setTabBadge"];
19
 	return self;
19
 	return self;
20
 }
20
 }
21
 
21
 
25
 	}
25
 	}
26
 }
26
 }
27
 
27
 
28
--(void)applyOn:(UIViewController*)viewController{
28
+-(void)applyOn:(UIViewController*)viewController {
29
 	if (self.topBarBackgroundColor) {
29
 	if (self.topBarBackgroundColor) {
30
 		UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
30
 		UIColor* backgroundColor = [RCTConvert UIColor:self.topBarBackgroundColor];
31
 		viewController.navigationController.navigationBar.barTintColor = backgroundColor;
31
 		viewController.navigationController.navigationBar.barTintColor = backgroundColor;
32
+	} else {
33
+		viewController.navigationController.navigationBar.barTintColor = nil;
32
 	}
34
 	}
33
 	if (self.title) {
35
 	if (self.title) {
34
 		viewController.navigationItem.title = self.title;
36
 		viewController.navigationItem.title = self.title;
37
 		UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
39
 		UIColor* textColor = [RCTConvert UIColor:self.topBarTextColor];
38
 		viewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:textColor};
40
 		viewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:textColor};
39
 	}
41
 	}
42
+	if (self.screenBackgroundColor) {
43
+		UIColor* screenColor = [RCTConvert UIColor:self.screenBackgroundColor];
44
+		viewController.view.backgroundColor = screenColor;
45
+  }
40
 	if (self.setTabBadge) {
46
 	if (self.setTabBadge) {
41
 		NSString *badge = [RCTConvert NSString:self.setTabBadge];
47
 		NSString *badge = [RCTConvert NSString:self.setTabBadge];
42
 		if (viewController.navigationController) {
48
 		if (viewController.navigationController) {
43
 			viewController.navigationController.tabBarItem.badgeValue = badge;
49
 			viewController.navigationController.tabBarItem.badgeValue = badge;
44
-		}
45
-		else {
50
+    } else {
46
 			viewController.tabBarItem.badgeValue = badge;
51
 			viewController.tabBarItem.badgeValue = badge;
47
 		}
52
 		}
48
 	}
53
 	}

+ 9
- 0
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

92
 	XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
92
 	XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
93
 }
93
 }
94
 
94
 
95
+-(void)testScreenBackgroundColor_validColor{
96
+	NSNumber* inputColor = @(0xFFFF0000);
97
+	self.options.screenBackgroundColor = inputColor;
98
+	[self.uut viewWillAppear:false];
99
+	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
100
+	XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
101
+}
102
+
103
+
95
 
104
 
96
 @end
105
 @end

+ 2
- 4
playground/src/containers/OptionsScreen.js View File

12
 class OptionsScreen extends Component {
12
 class OptionsScreen extends Component {
13
   static navigationOptions = {
13
   static navigationOptions = {
14
     title: 'Static Title',
14
     title: 'Static Title',
15
-    topBarBackgroundColor: "red",
16
-    statusBarHidden: true
15
+    topBarBackgroundColor: "red"
17
   }
16
   }
18
 
17
 
19
   constructor(props) {
18
   constructor(props) {
44
   root: {
43
   root: {
45
     flexGrow: 1,
44
     flexGrow: 1,
46
     justifyContent: 'center',
45
     justifyContent: 'center',
47
-    alignItems: 'center',
48
-    backgroundColor: '#f5fcff'
46
+    alignItems: 'center'
49
   },
47
   },
50
   h1: {
48
   h1: {
51
     fontSize: 24,
49
     fontSize: 24,

+ 1
- 2
playground/src/containers/WelcomeScreen.js View File

138
   root: {
138
   root: {
139
     flexGrow: 1,
139
     flexGrow: 1,
140
     justifyContent: 'center',
140
     justifyContent: 'center',
141
-    alignItems: 'center',
142
-    backgroundColor: '#f5fcff'
141
+    alignItems: 'center'
143
   },
142
   },
144
   h1: {
143
   h1: {
145
     fontSize: 24,
144
     fontSize: 24,