Skip to content

Commit

Permalink
[iOS][autofill-branding] Animate after keyboard sliding up completes
Browse files Browse the repository at this point in the history
Also fixes my previous rookie mistake of miscalculating 24/32 🤦‍♀️

Fixed: 1367236
Change-Id: If50418703a11fe02cbdcb040bb65d521d5041233
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3923474
Commit-Queue: Ginny Huang <ginnyhuang@chromium.org>
Auto-Submit: Ginny Huang <ginnyhuang@chromium.org>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1053027}
  • Loading branch information
ginnnnnnny authored and Chromium LUCI CQ committed Sep 29, 2022
1 parent 922c16e commit 2fdc67b
Showing 1 changed file with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
// The left margin of the branding logo, if visible.
constexpr CGFloat kLeadingInset = 10;
// The scale used by the "pop" animation.
constexpr CGFloat kAnimationScale = 1.25;
// Wait time after the branding is shown to perform pop animation.
constexpr CGFloat kAnimationScale = ((CGFloat)4) / 3;
// Wait time after the keyboard settles into placetwit to perform pop animation.
constexpr base::TimeDelta kAnimationWaitTime = base::Milliseconds(200);
// Time it takes the "pop" animation to perform.
constexpr base::TimeDelta kTimeToAnimate = base::Milliseconds(400);
Expand Down Expand Up @@ -73,21 +73,14 @@ - (void)loadView {
button.isAccessibilityElement = NO; // Prevents VoiceOver users from tap.
button.translatesAutoresizingMaskIntoConstraints = NO;
self.view = button;
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
DCHECK(self.delegate);
if (!self.shouldAnimate) {
return;
}
// The "pop" animation should start after a slight timeout.
__weak BrandingViewController* weakSelf = self;
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::BindOnce(^{
[weakSelf performPopAnimation];
}),
kAnimationWaitTime);
// Adds keyboard popup listener to show animation when keyboard is fully
// settled.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(onKeyboardAnimationComplete)
name:UIKeyboardDidShowNotification
object:nil];
}

#pragma mark - Accessors
Expand All @@ -113,6 +106,27 @@ - (void)setDelegate:(id<BrandingViewControllerDelegate>)delegate {

#pragma mark - Private

// Check if the branding icon is visible and should perform an animation, and do
// so if it should.
- (void)onKeyboardAnimationComplete {
// Branding is invisible.
if (self.view.window == nil || self.view.hidden) {
return;
}
// Branding is visible; animate if it should.
DCHECK(self.delegate);
if (!self.shouldAnimate) {
return;
}
// The "pop" animation should start after a slight timeout.
__weak BrandingViewController* weakSelf = self;
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::BindOnce(^{
[weakSelf performPopAnimation];
}),
kAnimationWaitTime);
}

// Performs the "pop" animation. This includes a quick enlarging of the icon
// and shrinking it back to the original size, and if finishes successfully,
// also notifies the delegate on completion.
Expand Down

0 comments on commit 2fdc67b

Please sign in to comment.