[go: nahoru, domu]

Skip to content

Commit

Permalink
[ios] Fix issue with Large Fakebox focus animation
Browse files Browse the repository at this point in the history
This change fixes several issues related to the omnibox focus animation
for Large Fakebox, on iPhone. Instead of entirely skipping the scroll-up
to pin the fakebox, a simpler animation is used. On focus, this simpler
animation happens simultaneous to the omnibox and popup (search
suggestions) appearing and isn't really visible unless there are no
search suggestions. On defocus, the scroll back down is visible but
happens quickly and it is a simpler animation then the previous scroll
down and happens at a normal FPS (unlike the previous CADisplayLink
driven animation).

Video of animations when there are no search suggestions:
http://screencast/cast/NDk5MDk3MTkxNjg0NTA1Nnw2ZjBkYmI0MS0zMg

Video of animations when there are search suggestions:
http://screencast/cast/NTA0MTgxMzQyNDQzOTI5NnxlNDZmNzNkNi01NA

Fixed: 1496805, 1496313
Change-Id: Ic74c84dc02b0a6b9427b860c65e8b97d9bdfc22b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4987950
Reviewed-by: Chris Lu <thegreenfrog@chromium.org>
Commit-Queue: Scott Yoder <scottyoder@google.com>
Cr-Commit-Position: refs/heads/main@{#1217362}
  • Loading branch information
Scott Yoder authored and Chromium LUCI CQ committed Oct 31, 2023
1 parent 52e5c85 commit e6ee450
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
1 change: 1 addition & 0 deletions ios/chrome/browser/ui/ntp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ source_set("ntp_internal") {
"//ios/chrome/browser/ui/toolbar/public:constants",
"//ios/chrome/browser/url_loading/model",
"//ios/chrome/common:button_config",
"//ios/chrome/common:timing",
"//ios/chrome/common/ui/colors",
"//ios/chrome/common/ui/elements",
"//ios/chrome/common/ui/favicon",
Expand Down
69 changes: 57 additions & 12 deletions ios/chrome/browser/ui/ntp/new_tab_page_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#import "ios/chrome/browser/ui/ntp/new_tab_page_mutator.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_utils.h"
#import "ios/chrome/common/material_timing.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/common/ui/elements/gradient_view.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h"
Expand Down Expand Up @@ -137,6 +138,9 @@ @interface NewTabPageViewController () <UICollectionViewDelegate,
// `YES` when notifications indicate the omnibox is focused.
@property(nonatomic, assign) BOOL omniboxFocused;

// When set to YES, the scroll position wont be updated.
@property(nonatomic, assign) BOOL inhibitScrollPositionUpdates;

@end

@implementation NewTabPageViewController {
Expand All @@ -158,6 +162,7 @@ - (instancetype)init {
_collectionShiftingOffset = 0;
_shouldAnimateHeader = YES;
_focusAccessibilityOmniboxWhenViewAppears = YES;
_inhibitScrollPositionUpdates = NO;
}
return self;
}
Expand Down Expand Up @@ -863,9 +868,33 @@ - (void)shiftTilesUpToFocusOmnibox {
animated:NO];
}

self.shouldAnimateHeader = YES;
CGFloat pinnedOffsetBeforeAnimation = [self pinnedOffsetY];
if (CGSizeEqualToSize(self.collectionView.contentSize, CGSizeZero)) {
[self.collectionView layoutIfNeeded];
}

if (!self.scrolledToMinimumHeight) {
// Save the scroll position prior to the animation to allow the user to
// return to it on defocus.
self.collectionShiftingOffset =
MAX(-[self heightAboveFeed], [self.headerViewController pinnedOffsetY] -
[self adjustedOffset].y);
}

// If the fake omnibox is already at the final position, just focus it and
// return early.
if ([self shouldSkipScrollToFocusOmnibox]) {
if (!self.scrolledToMinimumHeight) {
// Scroll up to pinned position if it is not pinned already, but don't
// wait for it to finish to focus the omnibox.
[UIView animateWithDuration:kMaterialDuration6
animations:^{
self.collectionView.contentOffset =
CGPoint(0, pinnedOffsetBeforeAnimation);
[self resetFakeOmniboxConstraints];
}];
}
self.shouldAnimateHeader = NO;
self.disableScrollAnimation = NO;
[self.NTPContentDelegate focusOmnibox];
Expand All @@ -875,18 +904,6 @@ - (void)shiftTilesUpToFocusOmnibox {
return;
}

self.shouldAnimateHeader = YES;
CGFloat pinnedOffsetBeforeAnimation = [self pinnedOffsetY];
if (CGSizeEqualToSize(self.collectionView.contentSize, CGSizeZero)) {
[self.collectionView layoutIfNeeded];
}

// Save the scroll position prior to the animation to allow the user to return
// to it on defocus.
self.collectionShiftingOffset =
MAX(-[self heightAboveFeed],
[self.headerViewController pinnedOffsetY] - [self adjustedOffset].y);

__weak __typeof(self) weakSelf = self;
ProceduralBlock shiftOmniboxToTop = ^{
__typeof(weakSelf) strongSelf = weakSelf;
Expand Down Expand Up @@ -1039,6 +1056,31 @@ - (void)shiftTilesDownForOmniboxDefocus {
return;
}

if (IsIOSLargeFakeboxEnabled()) {
// Skip the full CADisplayLink animation below, and use a simpler animation
// to scroll back into position.
CGFloat yOffset = MAX([self pinnedOffsetY] - self.collectionShiftingOffset,
-[self heightAboveFeed]);
self.headerViewController.view.alpha = 0;
__weak __typeof(self) weakSelf = self;
self.inhibitScrollPositionUpdates = YES;
[UIView animateWithDuration:kMaterialDuration6
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
weakSelf.headerViewController.view.alpha = 1;
weakSelf.collectionView.contentOffset = CGPoint(0, yOffset);
[weakSelf updateFakeOmniboxForScrollPosition];
}
completion:^(BOOL finished) {
weakSelf.inhibitScrollPositionUpdates = NO;
weakSelf.collectionShiftingOffset = 0;
weakSelf.collectionView.contentOffset = CGPoint(0, yOffset);
weakSelf.scrolledToMinimumHeight = NO;
}];
return;
}

self.scrolledToMinimumHeight = NO;

// CADisplayLink is used for this animation instead of the standard UIView
Expand Down Expand Up @@ -1491,6 +1533,9 @@ - (void)updateAccessibilityElements {
// Calculate the scroll position that should be saved in the NTP state and
// update the mutator.
- (void)updateScrollPositionToSave {
if (self.inhibitScrollPositionUpdates) {
return;
}
CGFloat scrollPositionToSave = [self scrollPosition];
if ([self.NTPContentDelegate isRecentTabTileVisible]) {
CGFloat tileSectionHeight =
Expand Down

0 comments on commit e6ee450

Please sign in to comment.