提交 1b01211e 编写于 作者: C Chris Bracken 提交者: GitHub

Default return key behaviour to 'done' on iOS (#3655)

This change brings iOS return key behaviour in line with current behaviour on
Android.

* Implements TextInputClient.performAction for iOS Adds FlutterTextInputAction
* enum Defaults return key to 'Done' Ends editing and hides the keyboard if
* 'Done' is pressed

Future work is planned to support configurable return/action key behaviour.
See: #9573, #9210, #8028.
上级 bd2592bb
......@@ -7,9 +7,14 @@
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, FlutterTextInputAction) {
FlutterTextInputActionDone,
};
@protocol FlutterTextInputDelegate<NSObject>
- (void)updateEditingClient:(int)client withState:(NSDictionary*)state;
- (void)performAction:(FlutterTextInputAction)action withClient:(int)client;
@end
......
......@@ -141,7 +141,7 @@ static UIKeyboardType ToUIKeyboardType(NSString* inputType) {
_enablesReturnKeyAutomatically = NO;
_keyboardAppearance = UIKeyboardAppearanceDefault;
_keyboardType = UIKeyboardTypeDefault;
_returnKeyType = UIReturnKeyDefault;
_returnKeyType = UIReturnKeyDone;
_secureTextEntry = NO;
}
......@@ -244,6 +244,16 @@ static UIKeyboardType ToUIKeyboardType(NSString* inputType) {
[self updateEditingState];
}
- (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)text {
if (self.returnKeyType == UIReturnKeyDone && [text isEqualToString:@"\n"]) {
[self resignFirstResponder];
[self removeFromSuperview];
[_textInputDelegate performAction:FlutterTextInputActionDone withClient:_textInputClient];
return NO;
}
return YES;
}
- (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
NSRange selectedRange = _selectedTextRange.range;
NSRange markedTextRange = ((FlutterTextRange*)self.markedTextRange).range;
......
......@@ -415,6 +415,17 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(UITouc
arguments:@[ @(client), state ]];
}
- (void)performAction:(FlutterTextInputAction)action withClient:(int)client {
NSString* actionString;
switch (action) {
case FlutterTextInputActionDone:
actionString = @"TextInputAction.done";
break;
}
[_textInputChannel.get() invokeMethod:@"TextInputClient.performAction"
arguments:@[ @(client), actionString ]];
}
#pragma mark - Orientation updates
- (void)onOrientationPreferencesUpdated:(NSNotification*)notification {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册