Commit b3170c39 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Short term solution to iPhone X top layout issues for BVC.

The proper solution is to either way for ios/clean or refactor BVC to use
topLayoutGuide.  Unfortunately, this change will require more than just
replacing usinag of StatusBarHeight, it will also require refactoring various
portions of BVC so layout happens within -viewSeAreaInsetsDidChange.

Instead, take advantage of the fact that, for now, the status bar frame can be
used to fake the topLayoutGuide, and can be used at anytime.

Bug: 
Change-Id: I7b05ce78a0104884fb77d21be512c641b1da0e95
Reviewed-on: https://chromium-review.googlesource.com/669484Reviewed-by: default avatarRohit Rao (ping after 24h) <rohitrao@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarJean-François Geyelin <jif@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502756}
parent 4a224e7b
......@@ -556,6 +556,9 @@ bool IsURLAllowedInIncognito(const GURL& url) {
// Coordinator for displaying Repost Form dialog.
RepostFormCoordinator* _repostFormCoordinator;
// Fake status bar view used to blend the toolbar into the status bar.
UIView* _fakeStatusBarView;
}
// The browser's side swipe controller. Lazily instantiated on the first call.
......@@ -1288,6 +1291,14 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
[_contentArea addGestureRecognizer:tapRecognizer];
}
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
// Gate this behind iPhone X, since it's currently the only device that
// needs layout updates here after startup.
if (IsIPhoneX())
[self setUpViewLayout];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.viewVisible = YES;
......@@ -1796,26 +1807,20 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
}
- (void)installFakeStatusBar {
CGFloat statusBarHeight = StatusBarHeight();
CGRect statusBarFrame =
CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight);
_fakeStatusBarView = [[UIView alloc] initWithFrame:statusBarFrame];
[_fakeStatusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
if (IsIPadIdiom()) {
CGFloat statusBarHeight = StatusBarHeight();
CGRect statusBarFrame =
CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight);
UIView* statusBarView = [[UIView alloc] initWithFrame:statusBarFrame];
[statusBarView setBackgroundColor:StatusBarBackgroundColor()];
[statusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[statusBarView layer].zPosition = 99;
[[self view] addSubview:statusBarView];
}
// Add a white bar on phone so that the status bar on the NTP is white.
if (!IsIPadIdiom()) {
CGFloat statusBarHeight = StatusBarHeight();
CGRect statusBarFrame =
CGRectMake(0, 0, [[self view] frame].size.width, statusBarHeight);
UIView* statusBarView = [[UIView alloc] initWithFrame:statusBarFrame];
[statusBarView setBackgroundColor:[UIColor whiteColor]];
[statusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view insertSubview:statusBarView atIndex:0];
[_fakeStatusBarView setBackgroundColor:StatusBarBackgroundColor()];
[_fakeStatusBarView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[_fakeStatusBarView layer].zPosition = 99;
[[self view] addSubview:_fakeStatusBarView];
} else {
// Add a white bar on phone so that the status bar on the NTP is white.
[_fakeStatusBarView setBackgroundColor:[UIColor whiteColor]];
[self.view insertSubview:_fakeStatusBarView atIndex:0];
}
}
......@@ -1938,6 +1943,11 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
CGFloat widthOfView = CGRectGetWidth([self view].bounds);
CGFloat minY = [self headerOffset];
// Update the fake toolbar background height.
CGRect fakeStatusBarFrame = _fakeStatusBarView.frame;
fakeStatusBarFrame.size.height = StatusBarHeight();
_fakeStatusBarView.frame = fakeStatusBarFrame;
if (self.tabStripView) {
minY += CGRectGetHeight([self.tabStripView frame]);
}
......@@ -1966,9 +1976,8 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
// the toolbar is not fullscreen.
CGRect contentFrame = [_contentArea frame];
CGFloat marginWithHeader = StatusBarHeight();
CGFloat overlap = [self headerHeight] != 0 ? marginWithHeader : minY;
contentFrame.size.height = CGRectGetMaxY(contentFrame) - overlap;
contentFrame.origin.y = overlap;
contentFrame.size.height = CGRectGetMaxY(contentFrame) - marginWithHeader;
contentFrame.origin.y = marginWithHeader;
[_contentArea setFrame:contentFrame];
// Adjust the infobar container to be either at the bottom of the screen
......
......@@ -36,6 +36,9 @@ CGFloat CurrentScreenHeight();
// Returns the width of the screen in the current orientation.
CGFloat CurrentScreenWidth();
// Returns true if the device is an iPhone X.
bool IsIPhoneX();
// Returns the height of the status bar, accounting for orientation.
CGFloat StatusBarHeight();
......
......@@ -52,7 +52,24 @@ CGFloat CurrentScreenWidth() {
return [UIScreen mainScreen].bounds.size.width;
}
bool IsIPhoneX() {
UIUserInterfaceIdiom idiom = [[UIDevice currentDevice] userInterfaceIdiom];
return (idiom == UIUserInterfaceIdiomPhone &&
CGRectGetHeight([[UIScreen mainScreen] nativeBounds]) == 2436);
}
CGFloat StatusBarHeight() {
// This is a temporary solution until usage of StatusBarHeight has been
// replaced with topLayoutGuide.
// iPhone X doesn't have the same statusBarFrame issues as previous phones
// (see below), so it's possible to use this here, rather than a static
// value like below.
if (IsIPhoneX()) {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
return CGRectGetHeight(statusBarFrame);
}
// Checking [UIApplication sharedApplication].statusBarFrame will return the
// wrong offset when the application is started while in a phone call, so
// simply return 20 here.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment