Fix disappearing omnibox on iPhone X.
The old-school layout logic in BVC was also re-inserting views on each
update, which is unnecessary, and in some cases causes views to show up
in the wrong z-order. Insert only needs to happen on initial layout,
so gating this in a flag should fix the issues.
Bug: 782373
Change-Id: I326f3b9199717c0ad014267fa0239581574a826d
Reviewed-on: https://chromium-review.googlesource.com/763711
Reviewed-by: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: Mark Cogan <marq@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515987}
diff --git a/ios/chrome/browser/ui/browser_view_controller.mm b/ios/chrome/browser/ui/browser_view_controller.mm
index 3133b2a6..c5bdd7f5 100644
--- a/ios/chrome/browser/ui/browser_view_controller.mm
+++ b/ios/chrome/browser/ui/browser_view_controller.mm
@@ -686,8 +686,9 @@
// Updates view-related functionality with the given tab model and browser
// state. The view must have been loaded. Uses |_browserState| and |_model|.
- (void)addUIFunctionalityForModelAndBrowserState;
-// Sets the correct frame and hierarchy for subviews and helper views.
-- (void)setUpViewLayout;
+// Sets the correct frame and hierarchy for subviews and helper views. Only
+// insert views on |initialLayout|.
+- (void)setUpViewLayout:(BOOL)initialLayout;
// Makes |tab| the currently visible tab, displaying its view. Calls
// -selectedTabChanged on the toolbar only if |newSelection| is YES.
- (void)displayTab:(Tab*)tab isNewSelection:(BOOL)newSelection;
@@ -1308,7 +1309,7 @@
// Install fake status bar for iPad iOS7
[self installFakeStatusBar];
[self buildToolbarAndTabStrip];
- [self setUpViewLayout];
+ [self setUpViewLayout:YES];
if (IsSafeAreaCompatibleToolbarEnabled()) {
[self addConstraintsToToolbar];
}
@@ -1331,7 +1332,7 @@
// Gate this behind iPhone X, since it's currently the only device that
// needs layout updates here after startup.
if (IsIPhoneX()) {
- [self setUpViewLayout];
+ [self setUpViewLayout:NO];
}
if (IsSafeAreaCompatibleToolbarEnabled()) {
// TODO(crbug.com/778236): Check if this call can be removed once the
@@ -2042,7 +2043,7 @@
}
// Set the frame for the various views. View must be loaded.
-- (void)setUpViewLayout {
+- (void)setUpViewLayout:(BOOL)initialLayout {
DCHECK([self isViewLoaded]);
CGFloat widthOfView = CGRectGetWidth([self view].bounds);
CGFloat minY = [self headerOffset];
@@ -2058,7 +2059,8 @@
// Position the toolbar next, either at the top of the browser view or
// directly under the tabstrip.
- [self addChildViewController:_toolbarCoordinator.toolbarViewController];
+ if (initialLayout)
+ [self addChildViewController:_toolbarCoordinator.toolbarViewController];
CGRect toolbarFrame = _toolbarCoordinator.toolbarViewController.view.frame;
toolbarFrame.origin = CGPointMake(0, minY);
toolbarFrame.size.width = widthOfView;
@@ -2068,14 +2070,17 @@
// Place the infobar container above the content area.
InfoBarContainerView* infoBarContainerView = _infoBarContainer->view();
- [self.view insertSubview:infoBarContainerView aboveSubview:_contentArea];
+ if (initialLayout)
+ [self.view insertSubview:infoBarContainerView aboveSubview:_contentArea];
// Place the toolbar controller above the infobar container.
- [[self view] insertSubview:_toolbarCoordinator.toolbarViewController.view
- aboveSubview:infoBarContainerView];
+ if (initialLayout)
+ [[self view] insertSubview:_toolbarCoordinator.toolbarViewController.view
+ aboveSubview:infoBarContainerView];
minY += CGRectGetHeight(toolbarFrame);
- [_toolbarCoordinator.toolbarViewController
- didMoveToParentViewController:self];
+ if (initialLayout)
+ [_toolbarCoordinator.toolbarViewController
+ didMoveToParentViewController:self];
// Account for the toolbar's drop shadow. The toolbar overlaps with the web
// content slightly.
@@ -2098,7 +2103,8 @@
// Attach the typing shield to the content area but have it hidden.
[_typingShield setFrame:[_contentArea frame]];
- [[self view] insertSubview:_typingShield aboveSubview:_contentArea];
+ if (initialLayout)
+ [[self view] insertSubview:_typingShield aboveSubview:_contentArea];
[_typingShield setHidden:YES];
_typingShield.accessibilityIdentifier = @"Typing Shield";
_typingShield.accessibilityLabel = l10n_util::GetNSString(IDS_CANCEL);