Commit dc5325de authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Alert] Animate layout when keyboard (dis)appears

Animates the move of the alert with the new safe areas when the keyboard
appears. This animations has the same curve and duration of the keyboard
one.

R=kkhorimoto@chromium.org

Bug: 959737, 951300
Change-Id: Ie447fc5a76744f954fe57c4aa176edb4be0e07fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1611820Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Auto-Submit: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666193}
parent 6706df3f
...@@ -64,6 +64,10 @@ constexpr int kButtonTextDefaultColor = 0x0579ff; ...@@ -64,6 +64,10 @@ constexpr int kButtonTextDefaultColor = 0x0579ff;
constexpr int kButtonTextDestructiveColor = 0xdf322f; constexpr int kButtonTextDestructiveColor = 0xdf322f;
constexpr int kTextfieldBackgroundColor = 0xf7f7f7; constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
// This is how many bits UIViewAnimationCurve needs to be shifted to be in
// UIViewAnimationOptions format. Must match the one in UIView.h.
constexpr NSUInteger kUIViewAnimationCurveToOptionsShift = 16;
} // namespace } // namespace
@interface AlertViewController () <UITextFieldDelegate, @interface AlertViewController () <UITextFieldDelegate,
...@@ -464,6 +468,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -464,6 +468,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
if (additionalBottomInset > 0) { if (additionalBottomInset > 0) {
self.additionalSafeAreaInsets = self.additionalSafeAreaInsets =
UIEdgeInsetsMake(0, 0, additionalBottomInset, 0); UIEdgeInsetsMake(0, 0, additionalBottomInset, 0);
[self animateLayoutFromKeyboardNotification:notification];
} }
self.tapRecognizer.enabled = YES; self.tapRecognizer.enabled = YES;
...@@ -472,11 +477,31 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -472,11 +477,31 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
- (void)handleKeyboardWillHide:(NSNotification*)notification { - (void)handleKeyboardWillHide:(NSNotification*)notification {
self.additionalSafeAreaInsets = UIEdgeInsetsZero; self.additionalSafeAreaInsets = UIEdgeInsetsZero;
[self animateLayoutFromKeyboardNotification:notification];
self.tapRecognizer.enabled = NO; self.tapRecognizer.enabled = NO;
self.swipeRecognizer.enabled = NO; self.swipeRecognizer.enabled = NO;
} }
- (void)animateLayoutFromKeyboardNotification:(NSNotification*)notification {
double duration =
[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey]
doubleValue];
UIViewAnimationCurve animationCurve = static_cast<UIViewAnimationCurve>(
[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey]
integerValue]);
UIViewAnimationOptions options = animationCurve
<< kUIViewAnimationCurveToOptionsShift;
[UIView animateWithDuration:duration
delay:0
options:options
animations:^{
[self.view layoutIfNeeded];
}
completion:nil];
}
- (void)didSelectActionForButton:(UIButton*)button { - (void)didSelectActionForButton:(UIButton*)button {
AlertAction* action = self.buttonAlertActionsDictionary[@(button.tag)]; AlertAction* action = self.buttonAlertActionsDictionary[@(button.tag)];
if (action.handler) { if (action.handler) {
......
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