Commit e8638a1a authored by Peter K. Lee's avatar Peter K. Lee Committed by Commit Bot

Use -traitCollectionDidChange: to detect size class changes

This is simpler than -viewWillTransitionToSize:withTransitionCoordinator:
because all the logic is in one place, ContentSuggestionsHeaderView.

Bug: 965964
Change-Id: Id990d4b91e07282f7ff985f529c5ad27856f0199
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626302Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Peter Lee <pkl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662621}
parent 8c74d38f
......@@ -41,13 +41,6 @@
// Can only be added once.
- (void)addToolbarView:(UIView*)toolbarView;
// Adjusts the autolayout constraints for |identityDiscView| when
// UIViewController changes size. When an iPhone is rotated from portrait
// (no top toolbar) to landscape (with top toolbar), the placement of Identity
// Disc has to be shifted down below the top toolbar. Otherwise, the Identity
// Disc may be obscured by the top toolbar in landscape mode.
- (void)adjustIdentityDiscConstraints;
// Returns the progress of the search field position along
// |ntp_header::kAnimationDistance| as the offset changes.
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset
......
......@@ -54,8 +54,8 @@ CGFloat ToolbarHeight() {
// Returns the amount of vertical space to allow for the existence of a top
// toolbar when iPhone is in landscape orientation.
CGFloat IdentityDiscToolbarOffset() {
return IsCompactHeight() ? ToolbarHeight() : 0;
CGFloat IdentityDiscToolbarOffset(id<UITraitEnvironment> environment) {
return IsCompactHeight(environment) ? ToolbarHeight() : 0;
}
} // namespace
......@@ -114,7 +114,7 @@ CGFloat IdentityDiscToolbarOffset() {
id<LayoutGuideProvider> layoutGuide = self.safeAreaLayoutGuide;
self.identityDiscTopConstraint = [self.identityDiscView.topAnchor
constraintEqualToAnchor:layoutGuide.topAnchor
constant:IdentityDiscToolbarOffset()];
constant:IdentityDiscToolbarOffset(self)];
CGFloat dimension =
ntp_home::kIdentityAvatarDimension + 2 * ntp_home::kIdentityAvatarMargin;
[NSLayoutConstraint activateConstraints:@[
......@@ -126,15 +126,6 @@ CGFloat IdentityDiscToolbarOffset() {
]];
}
- (void)adjustIdentityDiscConstraints {
// identityDiscView may not be set.
if (!self.identityDiscView)
return;
DCHECK(IsIdentityDiscFeatureEnabled());
self.identityDiscTopConstraint.constant = IdentityDiscToolbarOffset();
}
- (void)addViewsToSearchField:(UIView*)searchField {
// Fake Toolbar.
ToolbarButtonFactory* buttonFactory =
......@@ -405,6 +396,27 @@ CGFloat IdentityDiscToolbarOffset() {
completion:nil];
}
#pragma mark - UITraitEnvironment
// Adjusts the autolayout constraints for |identityDiscView| when view changes
// size. When an iPhone is rotated from portrait (no top toolbar) to landscape
// (with top toolbar), the placement of Identity Disc has to be shifted down
// below the top toolbar. Otherwise, the Identity Disc may be obscured by the
// top toolbar in landscape mode.
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
// identityDiscView may not be set if feature is not enabled.
if (!self.identityDiscView)
return;
DCHECK(IsIdentityDiscFeatureEnabled());
if ((self.traitCollection.verticalSizeClass !=
previousTraitCollection.verticalSizeClass) ||
(self.traitCollection.horizontalSizeClass !=
previousTraitCollection.horizontalSizeClass)) {
self.identityDiscTopConstraint.constant = IdentityDiscToolbarOffset(self);
}
}
#pragma mark - Property accessors
- (UIView*)fakeLocationBar {
......
......@@ -265,20 +265,6 @@ using base::UserMetricsAction;
return self.headerView;
}
#pragma mark - UIViewController
- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:
(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
[coordinator
animateAlongsideTransition:^(
id<UIViewControllerTransitionCoordinatorContext> context) {
[self.headerView adjustIdentityDiscConstraints];
}
completion:nil];
}
#pragma mark - Private
// Initialize and add a search field tap target and a voice search button.
......
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