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

[iOS][Alert] Jumps to next field or hides keyboard

When the return key in the keyboard is pressed, the following text field
will become first responder. If there is none, the current text field
resigns first responder to hide the keyboard.

Bug: 960420, 951300
Change-Id: I6497bc9e1930b06054ab2946665e4836de94d428
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602497
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658512}
parent b3bdf1b3
...@@ -66,7 +66,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -66,7 +66,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
} // namespace } // namespace
@interface AlertViewController () @interface AlertViewController () <UITextFieldDelegate>
// The actions for to this alert. |copy| for safety against mutable objects. // The actions for to this alert. |copy| for safety against mutable objects.
@property(nonatomic, copy) NSArray<AlertAction*>* actions; @property(nonatomic, copy) NSArray<AlertAction*>* actions;
...@@ -286,6 +286,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -286,6 +286,7 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
textField.accessibilityIdentifier = textField.accessibilityIdentifier =
textFieldConfiguration.accessibilityIdentifier; textFieldConfiguration.accessibilityIdentifier;
textField.translatesAutoresizingMaskIntoConstraints = NO; textField.translatesAutoresizingMaskIntoConstraints = NO;
textField.delegate = self;
[fieldStack addArrangedSubview:textField]; [fieldStack addArrangedSubview:textField];
ChromeDirectionalEdgeInsets fieldInsets = ChromeDirectionalEdgeInsetsMake( ChromeDirectionalEdgeInsets fieldInsets = ChromeDirectionalEdgeInsetsMake(
0.0, kTextfieldInset, 0.0, kTextfieldInset); 0.0, kTextfieldInset, 0.0, kTextfieldInset);
...@@ -377,6 +378,18 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7; ...@@ -377,6 +378,18 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
return results; return results;
} }
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField*)textField {
NSUInteger index = [self.textFields indexOfObject:textField];
if (index + 1 < self.textFields.count) {
[self.textFields[index + 1] becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return NO;
}
#pragma mark - Private #pragma mark - Private
- (void)handleKeyboardWillShow:(NSNotification*)notification { - (void)handleKeyboardWillShow:(NSNotification*)notification {
......
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