Преглед на файлове

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 години
родител
ревизия
a3f176d56e
No account linked to committer's email address
променени са 2 файла, в които са добавени 16 реда и са изтрити 4 реда
  1. 11
    3
      lib/ios/RNNTitleViewHelper.m
  2. 5
    1
      lib/ios/ReactNativeNavigation.m

+ 11
- 3
lib/ios/RNNTitleViewHelper.m Целия файл

@@ -6,6 +6,14 @@
6 6
 
7 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 18
 @end
11 19
 
@@ -54,7 +62,7 @@
54 62
 	
55 63
 	self.titleView = [[RNNTitleView alloc] initWithFrame:navigationBarBounds];
56 64
 	self.titleView.backgroundColor = [UIColor clearColor];
57
-	self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
65
+	self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
58 66
 	self.titleView.clipsToBounds = YES;
59 67
 	
60 68
 	if (self.subtitle) {
@@ -94,7 +102,7 @@
94 102
 	UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:subtitleFrame];
95 103
 	subtitleLabel.textAlignment = NSTextAlignmentCenter;
96 104
 	subtitleLabel.backgroundColor = [UIColor clearColor];
97
-	subtitleLabel.autoresizingMask = self.titleView.autoresizingMask;
105
+	subtitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
98 106
 	
99 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 108
 	[subtitleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.subtitle attributes:fontAttributes]];
@@ -126,7 +134,7 @@
126 134
 	titleLabel.textAlignment = NSTextAlignmentCenter;
127 135
 	titleLabel.backgroundColor = [UIColor clearColor];
128 136
 	
129
-	titleLabel.autoresizingMask = self.titleView.autoresizingMask;
137
+	titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
130 138
 	
131 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 140
 	[titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.title attributes:fontAttributes]];

+ 5
- 1
lib/ios/ReactNativeNavigation.m Целия файл

@@ -67,7 +67,11 @@
67 67
 
68 68
 - (UIWindow *)initializeKeyWindow {
69 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 75
 	UIApplication.sharedApplication.delegate.window = keyWindow;
72 76
 	
73 77
 	return keyWindow;