Skip to content

Commit

Permalink
Fix status bar appearance and title view layouting on iOS 13 (#5604)
Browse files Browse the repository at this point in the history
* Sets the window background color to the system's one for dark mode support

* Fix title layouting on iOS 13
  • Loading branch information
yogevbd authored Oct 23, 2019
1 parent 47464d7 commit a3f176d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/ios/RNNTitleViewHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

@implementation RNNTitleView

- (void)layoutSubviews {
CGFloat heightSum = _titleLabel.frame.size.height + _subtitleLabel.frame.size.height;
CGFloat yOffset = (self.frame.size.height - heightSum) / 2;

[_titleLabel setFrame:CGRectMake(0, yOffset, self.frame.size.width, _titleLabel.frame.size.height)];
[_subtitleLabel setFrame:CGRectMake(0, yOffset+_titleLabel.frame.size.height, self.frame.size
.width, _subtitleLabel.frame.size.height)];
}

@end

Expand Down Expand Up @@ -54,7 +62,7 @@ -(void)setup {

self.titleView = [[RNNTitleView alloc] initWithFrame:navigationBarBounds];
self.titleView.backgroundColor = [UIColor clearColor];
self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
self.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
self.titleView.clipsToBounds = YES;

if (self.subtitle) {
Expand Down Expand Up @@ -94,7 +102,7 @@ -(UILabel*)setupSubtitle {
UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:subtitleFrame];
subtitleLabel.textAlignment = NSTextAlignmentCenter;
subtitleLabel.backgroundColor = [UIColor clearColor];
subtitleLabel.autoresizingMask = self.titleView.autoresizingMask;
subtitleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;

NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_subtitleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_subtitleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_subtitleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
[subtitleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.subtitle attributes:fontAttributes]];
Expand Down Expand Up @@ -126,7 +134,7 @@ -(UILabel*)setupTitle {
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.backgroundColor = [UIColor clearColor];

titleLabel.autoresizingMask = self.titleView.autoresizingMask;
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;

NSDictionary* fontAttributes = [RNNFontAttributesCreator createWithFontFamily:[_titleOptions.fontFamily getWithDefaultValue:nil] fontSize:[_titleOptions.fontSize getWithDefaultValue:nil] fontWeight:[_titleOptions.fontWeight getWithDefaultValue:nil] color:[_subtitleOptions.color getWithDefaultValue:nil]];
[titleLabel setAttributedText:[[NSAttributedString alloc] initWithString:self.title attributes:fontAttributes]];
Expand Down
6 changes: 5 additions & 1 deletion lib/ios/ReactNativeNavigation.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ -(void)bootstrap:(NSURL *)jsCodeLocation launchOptions:(NSDictionary *)launchOpt

- (UIWindow *)initializeKeyWindow {
UIWindow* keyWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
keyWindow.backgroundColor = [UIColor whiteColor];
if (@available(iOS 13.0, *)) {
keyWindow.backgroundColor = [UIColor systemBackgroundColor];
} else {
keyWindow.backgroundColor = [UIColor whiteColor];
}
UIApplication.sharedApplication.delegate.window = keyWindow;

return keyWindow;
Expand Down

0 comments on commit a3f176d

Please sign in to comment.