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 @@ ...@@ -41,13 +41,6 @@
// Can only be added once. // Can only be added once.
- (void)addToolbarView:(UIView*)toolbarView; - (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 // Returns the progress of the search field position along
// |ntp_header::kAnimationDistance| as the offset changes. // |ntp_header::kAnimationDistance| as the offset changes.
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset - (CGFloat)searchFieldProgressForOffset:(CGFloat)offset
......
...@@ -54,8 +54,8 @@ CGFloat ToolbarHeight() { ...@@ -54,8 +54,8 @@ CGFloat ToolbarHeight() {
// Returns the amount of vertical space to allow for the existence of a top // Returns the amount of vertical space to allow for the existence of a top
// toolbar when iPhone is in landscape orientation. // toolbar when iPhone is in landscape orientation.
CGFloat IdentityDiscToolbarOffset() { CGFloat IdentityDiscToolbarOffset(id<UITraitEnvironment> environment) {
return IsCompactHeight() ? ToolbarHeight() : 0; return IsCompactHeight(environment) ? ToolbarHeight() : 0;
} }
} // namespace } // namespace
...@@ -114,7 +114,7 @@ CGFloat IdentityDiscToolbarOffset() { ...@@ -114,7 +114,7 @@ CGFloat IdentityDiscToolbarOffset() {
id<LayoutGuideProvider> layoutGuide = self.safeAreaLayoutGuide; id<LayoutGuideProvider> layoutGuide = self.safeAreaLayoutGuide;
self.identityDiscTopConstraint = [self.identityDiscView.topAnchor self.identityDiscTopConstraint = [self.identityDiscView.topAnchor
constraintEqualToAnchor:layoutGuide.topAnchor constraintEqualToAnchor:layoutGuide.topAnchor
constant:IdentityDiscToolbarOffset()]; constant:IdentityDiscToolbarOffset(self)];
CGFloat dimension = CGFloat dimension =
ntp_home::kIdentityAvatarDimension + 2 * ntp_home::kIdentityAvatarMargin; ntp_home::kIdentityAvatarDimension + 2 * ntp_home::kIdentityAvatarMargin;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
...@@ -126,15 +126,6 @@ CGFloat IdentityDiscToolbarOffset() { ...@@ -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 { - (void)addViewsToSearchField:(UIView*)searchField {
// Fake Toolbar. // Fake Toolbar.
ToolbarButtonFactory* buttonFactory = ToolbarButtonFactory* buttonFactory =
...@@ -405,6 +396,27 @@ CGFloat IdentityDiscToolbarOffset() { ...@@ -405,6 +396,27 @@ CGFloat IdentityDiscToolbarOffset() {
completion:nil]; 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 #pragma mark - Property accessors
- (UIView*)fakeLocationBar { - (UIView*)fakeLocationBar {
......
...@@ -265,20 +265,6 @@ using base::UserMetricsAction; ...@@ -265,20 +265,6 @@ using base::UserMetricsAction;
return self.headerView; 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 #pragma mark - Private
// Initialize and add a search field tap target and a voice search button. // 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