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

[iOS][Alert] Add swipe gesture recognizer

Adds a swipe gesture recognizer that dismiss the keyboard when the alert
is swipped down.

Bug: 960417
Change-Id: I1179a158f9860754278ce73f1ee068ccbbaf2d8d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602642
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659000}
parent a551212e
...@@ -95,6 +95,9 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -95,6 +95,9 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
// view. // view.
@property(nonatomic, strong) UITapGestureRecognizer* tapRecognizer; @property(nonatomic, strong) UITapGestureRecognizer* tapRecognizer;
// Recognizer used to dismiss the keyboard swipping down the alert.
@property(nonatomic, strong) UISwipeGestureRecognizer* swipeRecognizer;
// This is the last focused text field, the gestures to dismiss the keyboard // This is the last focused text field, the gestures to dismiss the keyboard
// will end up calling |resignFirstResponder| on this. // will end up calling |resignFirstResponder| on this.
@property(nonatomic, weak) UITextField* lastFocusedTextField; @property(nonatomic, weak) UITextField* lastFocusedTextField;
...@@ -128,6 +131,13 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -128,6 +131,13 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
self.contentView.translatesAutoresizingMaskIntoConstraints = NO; self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.contentView]; [self.view addSubview:self.contentView];
self.swipeRecognizer = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
self.swipeRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
self.swipeRecognizer.enabled = NO;
[self.contentView addGestureRecognizer:self.swipeRecognizer];
BOOL isAccessibilityContentSize = BOOL isAccessibilityContentSize =
UIContentSizeCategoryIsAccessibilityCategory( UIContentSizeCategoryIsAccessibilityCategory(
[UIApplication sharedApplication].preferredContentSizeCategory); [UIApplication sharedApplication].preferredContentSizeCategory);
...@@ -429,11 +439,13 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -429,11 +439,13 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
self.additionalSafeAreaInsets = self.additionalSafeAreaInsets =
UIEdgeInsetsMake(0, 0, keyboardFrame.size.height, 0); UIEdgeInsetsMake(0, 0, keyboardFrame.size.height, 0);
self.tapRecognizer.enabled = YES; self.tapRecognizer.enabled = YES;
self.swipeRecognizer.enabled = YES;
} }
- (void)handleKeyboardWillHide:(NSNotification*)notification { - (void)handleKeyboardWillHide:(NSNotification*)notification {
self.additionalSafeAreaInsets = UIEdgeInsetsZero; self.additionalSafeAreaInsets = UIEdgeInsetsZero;
self.tapRecognizer.enabled = NO; self.tapRecognizer.enabled = NO;
self.swipeRecognizer.enabled = NO;
} }
- (void)didSelectActionForButton:(UIButton*)button { - (void)didSelectActionForButton:(UIButton*)button {
......
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