Browse Source

Fix status bar appearance and title view layouting on iOS 13 (#5604)

* Sets the window background color to the system's one for dark mode support

* Fix title layouting on iOS 13
Yogev Ben David 5 years ago
parent
commit
a3f176d56e
No account linked to committer's email address
2 changed files with 16 additions and 4 deletions
  1. 11
    3
      lib/ios/RNNTitleViewHelper.m
  2. 5
    1
      lib/ios/ReactNativeNavigation.m

+ 11
- 3
lib/ios/RNNTitleViewHelper.m View File

6
 
6
 
7
 @implementation RNNTitleView
7
 @implementation RNNTitleView
8
 
8
 
9
+- (void)layoutSubviews {
10
+	CGFloat heightSum = _titleLabel.frame.size.height + _subtitleLabel.frame.size.height;
11
+	CGFloat yOffset = (self.frame.size.height - heightSum) / 2;
12
+	
13
+	[_titleLabel setFrame:CGRectMake(0, yOffset, self.frame.size.width, _titleLabel.frame.size.height)];
14
+	[_subtitleLabel setFrame:CGRectMake(0, yOffset+_titleLabel.frame.size.height, self.frame.size
15
+										.width, _subtitleLabel.frame.size.height)];
16
+}
9
 
17
 
10
 @end
18
 @end
11
 
19
 
54
 	
62
 	
55
 	self.titleView = [[RNNTitleView alloc] initWithFrame:navigationBarBounds];
63
 	self.titleView = [[RNNTitleView alloc] initWithFrame:navigationBarBounds];
56
 	self.titleView.backgroundColor = [UIColor clearColor];
64
 	self.titleView.backgroundColor = [UIColor clearColor];
57
-	self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
65
+	self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
58
 	self.titleView.clipsToBounds = YES;
66
 	self.titleView.clipsToBounds = YES;
59
 	
67
 	
60
 	if (self.subtitle) {
68
 	if (self.subtitle) {
94
 	UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:subtitleFrame];
102
 	UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:subtitleFrame];
95
 	subtitleLabel.textAlignment = NSTextAlignmentCenter;
103
 	subtitleLabel.textAlignment = NSTextAlignmentCenter;
96
 	subtitleLabel.backgroundColor = [UIColor clearColor];
104
 	subtitleLabel.backgroundColor = [UIColor clearColor];
97
-	subtitleLabel.autoresizingMask = self.titleView.autoresizingMask;
105
+	subtitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
98
 	
106
 	
99
 	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_subtitleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_subtitleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_subtitleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
107
 	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_subtitleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_subtitleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_subtitleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
100
 	[subtitleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.subtitle attributes:fontAttributes]];
108
 	[subtitleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.subtitle attributes:fontAttributes]];
126
 	titleLabel.textAlignment = NSTextAlignmentCenter;
134
 	titleLabel.textAlignment = NSTextAlignmentCenter;
127
 	titleLabel.backgroundColor = [UIColor clearColor];
135
 	titleLabel.backgroundColor = [UIColor clearColor];
128
 	
136
 	
129
-	titleLabel.autoresizingMask = self.titleView.autoresizingMask;
137
+	titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
130
 	
138
 	
131
 	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_titleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_titleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_titleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
139
 	NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_titleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_titleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_titleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
132
 	[titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.title attributes:fontAttributes]];
140
 	[titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.title attributes:fontAttributes]];

+ 5
- 1
lib/ios/ReactNativeNavigation.m View File

67
 
67
 
68
 - (UIWindow *)initializeKeyWindow {
68
 - (UIWindow *)initializeKeyWindow {
69
 	UIWindow* keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
69
 	UIWindow* keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
70
-	keyWindow.backgroundColor = [UIColor whiteColor];
70
+	if (@available(iOS 13.0, *)) {
71
+		keyWindow.backgroundColor = [UIColor systemBackgroundColor];
72
+	} else {
73
+		keyWindow.backgroundColor = [UIColor whiteColor];
74
+	}
71
 	UIApplication.sharedApplication.delegate.window = keyWindow;
75
 	UIApplication.sharedApplication.delegate.window = keyWindow;
72
 	
76
 	
73
 	return keyWindow;
77
 	return keyWindow;