Commit 01fca2bb authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

NTP focus animation tweaks

Tweaks the animation when focusing the fakebox in NTP.

Bug: 867455
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I44a7c799e6269a1fdf6806b2cd54cdcdfc46336f
Reviewed-on: https://chromium-review.googlesource.com/1156697
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579730}
parent ca70b72c
...@@ -50,7 +50,6 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing, ...@@ -50,7 +50,6 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing,
// added to |hintLabelContainer| with autoresizing. This is done due to the // added to |hintLabelContainer| with autoresizing. This is done due to the
// way searchHintLabel is later tranformed. // way searchHintLabel is later tranformed.
void configureSearchHintLabel(UILabel* searchHintLabel, void configureSearchHintLabel(UILabel* searchHintLabel,
UIView* hintLabelContainer,
UIButton* searchTapTarget); UIButton* searchTapTarget);
// Configure the |voiceSearchButton|, adding it to the |searchTapTarget| and // Configure the |voiceSearchButton|, adding it to the |searchTapTarget| and
// constraining it. // constraining it.
......
...@@ -204,28 +204,26 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing, ...@@ -204,28 +204,26 @@ CGFloat heightForLogoHeader(BOOL logoIsShowing,
} }
void configureSearchHintLabel(UILabel* searchHintLabel, void configureSearchHintLabel(UILabel* searchHintLabel,
UIView* hintLabelContainer,
UIButton* searchTapTarget) { UIButton* searchTapTarget) {
// searchHintLabel is intentionally not using autolayout because it will need [searchHintLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
// to use a CGAffineScale transform that will not work correctly with [searchTapTarget addSubview:searchHintLabel];
// autolayout. Instead, |hintLabelContainer| will use autolayout and will
// contain |searchHintLabel|.
searchHintLabel.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[hintLabelContainer setTranslatesAutoresizingMaskIntoConstraints:NO];
[searchTapTarget addSubview:hintLabelContainer];
[hintLabelContainer addSubview:searchHintLabel];
CGFloat centerYOffsetConstant = CGFloat centerYOffsetConstant =
IsUIRefreshPhase1Enabled() ? 0 : kSearchHintVerticalOffset; IsUIRefreshPhase1Enabled() ? 0 : kSearchHintVerticalOffset;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[hintLabelContainer.centerYAnchor [searchHintLabel.centerYAnchor
constraintEqualToAnchor:searchTapTarget.centerYAnchor constraintEqualToAnchor:searchTapTarget.centerYAnchor
constant:centerYOffsetConstant], constant:centerYOffsetConstant],
[hintLabelContainer.heightAnchor [searchHintLabel.heightAnchor
constraintEqualToConstant:kSearchFieldHeight - 2 * kSearchHintMargin], constraintEqualToConstant:kSearchFieldHeight - 2 * kSearchHintMargin],
]]; ]];
if (IsUIRefreshPhase1Enabled()) {
[searchHintLabel.centerXAnchor
constraintEqualToAnchor:searchTapTarget.centerXAnchor]
.active = YES;
}
[searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)]; [searchHintLabel setText:l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT)];
if (base::i18n::IsRTL()) { if (base::i18n::IsRTL()) {
[searchHintLabel setTextAlignment:NSTextAlignmentRight]; [searchHintLabel setTextAlignment:NSTextAlignmentRight];
......
...@@ -49,7 +49,6 @@ UIEdgeInsets SafeAreaInsetsForViewWithinNTP(UIView* view) { ...@@ -49,7 +49,6 @@ UIEdgeInsets SafeAreaInsetsForViewWithinNTP(UIView* view) {
@property(nonatomic, weak) id<ContentSuggestionsHeaderControlling> @property(nonatomic, weak) id<ContentSuggestionsHeaderControlling>
headerController; headerController;
@property(nonatomic, assign) CFTimeInterval shiftTileStartTime; @property(nonatomic, assign) CFTimeInterval shiftTileStartTime;
@property(nonatomic, strong) ProceduralBlock shiftUpCompletionBlock;
// Tap gesture recognizer when the omnibox is focused. // Tap gesture recognizer when the omnibox is focused.
@property(nonatomic, strong) UITapGestureRecognizer* tapGestureRecognizer; @property(nonatomic, strong) UITapGestureRecognizer* tapGestureRecognizer;
...@@ -63,7 +62,6 @@ UIEdgeInsets SafeAreaInsetsForViewWithinNTP(UIView* view) { ...@@ -63,7 +62,6 @@ UIEdgeInsets SafeAreaInsetsForViewWithinNTP(UIView* view) {
@synthesize shiftTileStartTime = _shiftTileStartTime; @synthesize shiftTileStartTime = _shiftTileStartTime;
@synthesize tapGestureRecognizer = _tapGestureRecognizer; @synthesize tapGestureRecognizer = _tapGestureRecognizer;
@synthesize collectionShiftingOffset = _collectionShiftingOffset; @synthesize collectionShiftingOffset = _collectionShiftingOffset;
@synthesize shiftUpCompletionBlock = _shiftUpCompletionBlock;
- (instancetype) - (instancetype)
initWithCollectionController: initWithCollectionController:
...@@ -143,19 +141,28 @@ initWithCollectionController: ...@@ -143,19 +141,28 @@ initWithCollectionController:
self.collectionController.scrolledToTop = YES; self.collectionController.scrolledToTop = YES;
self.shouldAnimateHeader = YES; self.shouldAnimateHeader = YES;
self.shiftUpCompletionBlock = completion;
// Layout the header for the constraints to be animated. [UIView animateWithDuration:kShiftTilesUpAnimationDuration
[self.headerController layoutHeader]; animations:^{
[self.collectionView.collectionViewLayout invalidateLayout]; if (self.collectionView.contentOffset.y < pinnedOffsetY) {
// Changing the contentOffset of the collection results in a scroll
// Similar to -shiftTilesDown, also use a CADisplayLink so each contentOffset // and a change in the constraints of the header.
// tick forces an update for the fake omnibox. Otherwise the fakebox and its self.collectionView.contentOffset = CGPointMake(0, pinnedOffsetY);
// label will be sized incorrectly when tapped. // Layout the header for the constraints to be animated.
CADisplayLink* link = [CADisplayLink [self.headerController layoutHeader];
displayLinkWithTarget:self [self.collectionView.collectionViewLayout invalidateLayout];
selector:@selector(shiftTilesUpAnimationDidFire:)]; }
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; }
completion:^(BOOL finished) {
// Check to see if the collection are still scrolled to the top -- it's
// possible (and difficult) to unfocus the omnibox and initiate a
// -shiftTilesDown before the animation here completes.
if (self.collectionController.scrolledToTop) {
self.shouldAnimateHeader = NO;
if (completion)
completion();
}
}];
} }
- (void)invalidateLayout { - (void)invalidateLayout {
...@@ -229,47 +236,6 @@ initWithCollectionController: ...@@ -229,47 +236,6 @@ initWithCollectionController:
return [self.collectionController collectionView]; return [self.collectionController collectionView];
} }
// Updates the collection view's scroll view offset for the next frame of the
// -shiftTilesUpWithCompletionBlock animation.
- (void)shiftTilesUpAnimationDidFire:(CADisplayLink*)link {
// If this is the first frame of the animation, store the starting timestamp
// and do nothing.
if (self.shiftTileStartTime == -1) {
self.shiftTileStartTime = link.timestamp;
return;
}
CFTimeInterval timeElapsed = link.timestamp - self.shiftTileStartTime;
double percentComplete = timeElapsed / kShiftTilesUpAnimationDuration;
// Ensure that the percentage cannot be above 1.0.
if (percentComplete > 1.0)
percentComplete = 1.0;
// Find how much the collection view should be scrolled up in the next frame.
CGFloat pinnedOffsetY = [self.headerController pinnedOffsetY];
CGFloat startingOffset = pinnedOffsetY - self.collectionShiftingOffset;
CGFloat yOffset =
startingOffset + percentComplete * (pinnedOffsetY - startingOffset);
self.collectionView.contentOffset = CGPointMake(0, yOffset);
if (percentComplete == 1.0) {
[link invalidate];
// Reset |shiftTileStartTime| to its sentinel value.
self.shiftTileStartTime = -1;
// Check to see if the collection are still scrolled to the top -- it's
// possible (and difficult) to initiate a -shiftTilesDown before the
// animation here completes.
if (self.collectionController.scrolledToTop) {
self.shouldAnimateHeader = NO;
if (self.shiftUpCompletionBlock) {
self.shiftUpCompletionBlock();
self.shiftUpCompletionBlock = nil;
}
}
}
}
// Updates the collection view's scroll view offset for the next frame of the // Updates the collection view's scroll view offset for the next frame of the
// shiftTilesDown animation. // shiftTilesDown animation.
- (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link { - (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link {
......
...@@ -235,8 +235,10 @@ const CGFloat kBackgroundLandscapeInset = 169; ...@@ -235,8 +235,10 @@ const CGFloat kBackgroundLandscapeInset = 169;
// Adjust the position of the search field's subviews by adjusting their // Adjust the position of the search field's subviews by adjusting their
// constraint constant value. // constraint constant value.
CGFloat constantDiff = percent * (ntp_header::kMaxHorizontalMarginDiff + CGFloat constantDiff = IsUIRefreshPhase1Enabled()
inset + safeAreaInsets.left); ? -maxXInset * percent
: percent * (ntp_header::kMaxHorizontalMarginDiff +
inset + safeAreaInsets.left);
for (NSLayoutConstraint* constraint in constraints) { for (NSLayoutConstraint* constraint in constraints) {
if (constraint.constant > 0) if (constraint.constant > 0)
constraint.constant = constantDiff + ntp_header::kHintLabelSidePadding; constraint.constant = constantDiff + ntp_header::kHintLabelSidePadding;
......
...@@ -303,24 +303,26 @@ const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3}; ...@@ -303,24 +303,26 @@ const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3};
ntp_home::FakeOmniboxAccessibilityID(); ntp_home::FakeOmniboxAccessibilityID();
// Set up fakebox hint label. // Set up fakebox hint label.
_searchHintLabel = [[UILabel alloc] init]; self.searchHintLabel = [[UILabel alloc] init];
UIView* hintLabelContainer = [[UIView alloc] init]; content_suggestions::configureSearchHintLabel(self.searchHintLabel,
content_suggestions::configureSearchHintLabel( self.fakeOmnibox);
_searchHintLabel, hintLabelContainer, self.fakeOmnibox);
if (IsUIRefreshPhase1Enabled()) {
self.hintLabelLeadingConstraint = [hintLabelContainer.leadingAnchor self.hintLabelLeadingConstraint = [self.searchHintLabel.leadingAnchor
constraintEqualToAnchor:[self.fakeOmnibox leadingAnchor] constraintGreaterThanOrEqualToAnchor:[self.fakeOmnibox leadingAnchor]
constant:ntp_header::kHintLabelSidePadding]; constant:ntp_header::kHintLabelSidePadding];
if (!IsUIRefreshPhase1Enabled()) } else {
self.hintLabelLeadingConstraint.constant = self.hintLabelLeadingConstraint = [self.searchHintLabel.leadingAnchor
ntp_header::kHintLabelSidePaddingLegacy; constraintEqualToAnchor:[self.fakeOmnibox leadingAnchor]
[self.hintLabelLeadingConstraint setActive:YES]; constant:ntp_header::kHintLabelSidePaddingLegacy];
}
self.hintLabelLeadingConstraint.active = YES;
// Set a button the same size as the fake omnibox as the accessibility // Set a button the same size as the fake omnibox as the accessibility
// element. If the hint is the only accessible element, when the fake omnibox // element. If the hint is the only accessible element, when the fake omnibox
// is taking the full width, there are few points that are not accessible and // is taking the full width, there are few points that are not accessible and
// allow to select the content below it. // allow to select the content below it.
_searchHintLabel.isAccessibilityElement = NO; self.searchHintLabel.isAccessibilityElement = NO;
UIButton* accessibilityButton = [[UIButton alloc] init]; UIButton* accessibilityButton = [[UIButton alloc] init];
[accessibilityButton addTarget:self [accessibilityButton addTarget:self
action:@selector(fakeOmniboxTapped:) action:@selector(fakeOmniboxTapped:)
...@@ -340,8 +342,8 @@ const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3}; ...@@ -340,8 +342,8 @@ const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3};
self.voiceTapTrailingConstraint = [voiceTapTarget.trailingAnchor self.voiceTapTrailingConstraint = [voiceTapTarget.trailingAnchor
constraintEqualToAnchor:[self.fakeOmnibox trailingAnchor]]; constraintEqualToAnchor:[self.fakeOmnibox trailingAnchor]];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[hintLabelContainer.trailingAnchor [self.searchHintLabel.trailingAnchor
constraintEqualToAnchor:voiceTapTarget.leadingAnchor], constraintLessThanOrEqualToAnchor:voiceTapTarget.leadingAnchor],
_voiceTapTrailingConstraint _voiceTapTrailingConstraint
]]; ]];
......
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