Commit d17e687e authored by adamta's avatar adamta Committed by Chromium LUCI CQ

[iOS] Refactored NTP scroll when tapping omnibox

Refactored NTP offset starts negative because of the way the content
suggestions header are added on top of the feed. Fixes header
synchronizer by using additional offset property to compensate for the
negative offset.

Bug: 1114792
Change-Id: I62d2be34444d705e8ad7fd862ded80e9e947b783
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2626830
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843128}
parent 3a80d96b
...@@ -122,8 +122,7 @@ initWithCollectionController: ...@@ -122,8 +122,7 @@ initWithCollectionController:
if (self.collectionView.decelerating) { if (self.collectionView.decelerating) {
// Stop the scrolling if the scroll view is decelerating to prevent the // Stop the scrolling if the scroll view is decelerating to prevent the
// focus to be immediately lost. // focus to be immediately lost.
[self.collectionView setContentOffset:self.collectionView.contentOffset [self.collectionView setContentOffset:[self adjustedOffset] animated:NO];
animated:NO];
} }
if (self.collectionController.scrolledToTop) { if (self.collectionController.scrolledToTop) {
...@@ -138,7 +137,7 @@ initWithCollectionController: ...@@ -138,7 +137,7 @@ initWithCollectionController:
CGFloat pinnedOffsetY = [self.headerController pinnedOffsetY]; CGFloat pinnedOffsetY = [self.headerController pinnedOffsetY];
self.collectionShiftingOffset = self.collectionShiftingOffset =
MAX(0, pinnedOffsetY - self.collectionView.contentOffset.y); MAX(0, pinnedOffsetY - [self adjustedOffset].y);
self.collectionController.scrolledToTop = YES; self.collectionController.scrolledToTop = YES;
self.shouldAnimateHeader = YES; self.shouldAnimateHeader = YES;
...@@ -153,13 +152,14 @@ initWithCollectionController: ...@@ -153,13 +152,14 @@ initWithCollectionController:
return; return;
__typeof(weakSelf) strongSelf = weakSelf; __typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf.collectionView.contentOffset.y < pinnedOffsetY) { if ((strongSelf.collectionView.contentOffset.y +
self.additionalOffset) < pinnedOffsetY) {
if (animations) if (animations)
animations(); animations();
// Changing the contentOffset of the collection results in a // Changing the contentOffset of the collection results in a
// scroll and a change in the constraints of the header. // scroll and a change in the constraints of the header.
strongSelf.collectionView.contentOffset = strongSelf.collectionView.contentOffset =
CGPointMake(0, pinnedOffsetY); CGPointMake(0, pinnedOffsetY - self.additionalOffset);
// Layout the header for the constraints to be animated. // Layout the header for the constraints to be animated.
[strongSelf.headerController layoutHeader]; [strongSelf.headerController layoutHeader];
[strongSelf.collectionView [strongSelf.collectionView
...@@ -211,10 +211,8 @@ initWithCollectionController: ...@@ -211,10 +211,8 @@ initWithCollectionController:
if (self.shouldAnimateHeader) { if (self.shouldAnimateHeader) {
UIEdgeInsets insets = self.collectionView.safeAreaInsets; UIEdgeInsets insets = self.collectionView.safeAreaInsets;
CGFloat totalOffset =
self.collectionView.contentOffset.y + self.additionalOffset;
[self.headerController [self.headerController
updateFakeOmniboxForOffset:totalOffset updateFakeOmniboxForOffset:[self adjustedOffset].y
screenWidth:self.collectionView.frame.size.width screenWidth:self.collectionView.frame.size.width
safeAreaInsets:insets]; safeAreaInsets:insets];
} }
...@@ -229,9 +227,7 @@ initWithCollectionController: ...@@ -229,9 +227,7 @@ initWithCollectionController:
// -viewDidLayoutSubviews. Since self.collectionView and it's superview // -viewDidLayoutSubviews. Since self.collectionView and it's superview
// should always have the same safeArea, this should be safe. // should always have the same safeArea, this should be safe.
UIEdgeInsets insets = self.collectionView.superview.safeAreaInsets; UIEdgeInsets insets = self.collectionView.superview.safeAreaInsets;
CGFloat totalOffset = [self.headerController updateFakeOmniboxForOffset:[self adjustedOffset].y
self.collectionView.contentOffset.y + self.additionalOffset;
[self.headerController updateFakeOmniboxForOffset:totalOffset
screenWidth:width screenWidth:width
safeAreaInsets:insets]; safeAreaInsets:insets];
} else { } else {
...@@ -267,6 +263,32 @@ initWithCollectionController: ...@@ -267,6 +263,32 @@ initWithCollectionController:
return self.headerController.isShowing; return self.headerController.isShowing;
} }
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
shouldReceiveTouch:(UITouch*)touch {
BOOL isMostVisitedCell =
content_suggestions::nearestAncestor(
touch.view, [ContentSuggestionsMostVisitedCell class]) != nil;
BOOL isMostVisitedActionCell =
content_suggestions::nearestAncestor(
touch.view, [ContentSuggestionsMostVisitedActionCell class]) != nil;
BOOL isSuggestionCell =
content_suggestions::nearestAncestor(
touch.view, [ContentSuggestionsCell class]) != nil;
return !isMostVisitedCell && !isMostVisitedActionCell && !isSuggestionCell;
}
- (UIView*)nearestAncestorOfView:(UIView*)view withClass:(Class)aClass {
if (!view) {
return nil;
}
if ([view isKindOfClass:aClass]) {
return view;
}
return [self nearestAncestorOfView:[view superview] withClass:aClass];
}
#pragma mark - Private #pragma mark - Private
// Convenience method to get the collection view of the suggestions. // Convenience method to get the collection view of the suggestions.
...@@ -306,30 +328,11 @@ initWithCollectionController: ...@@ -306,30 +328,11 @@ initWithCollectionController:
} }
} }
#pragma mark - UIGestureRecognizerDelegate // Returns y-offset compensated for any additionalOffset that might be set.
- (CGPoint)adjustedOffset {
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer CGPoint adjustedOffset = self.collectionView.contentOffset;
shouldReceiveTouch:(UITouch*)touch { adjustedOffset.y += self.additionalOffset;
BOOL isMostVisitedCell = return adjustedOffset;
content_suggestions::nearestAncestor(
touch.view, [ContentSuggestionsMostVisitedCell class]) != nil;
BOOL isMostVisitedActionCell =
content_suggestions::nearestAncestor(
touch.view, [ContentSuggestionsMostVisitedActionCell class]) != nil;
BOOL isSuggestionCell =
content_suggestions::nearestAncestor(
touch.view, [ContentSuggestionsCell class]) != nil;
return !isMostVisitedCell && !isMostVisitedActionCell && !isSuggestionCell;
}
- (UIView*)nearestAncestorOfView:(UIView*)view withClass:(Class)aClass {
if (!view) {
return nil;
}
if ([view isKindOfClass:aClass]) {
return view;
}
return [self nearestAncestorOfView:[view superview] withClass:aClass];
} }
@end @end
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