|
|
|
|
@@ -88,6 +88,122 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
return UIReturnKeyDefault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static UITextContentType ToUITextContentType(NSArray<NSString*>* hints) {
|
|
|
|
|
if (hints == nil || hints.count == 0) {
|
|
|
|
|
return @"";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString* hint = hints[0];
|
|
|
|
|
if (@available(iOS 10.0, *)) {
|
|
|
|
|
if ([hint isEqualToString:@"addressCityAndState"]) {
|
|
|
|
|
return UITextContentTypeAddressCityAndState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"addressState"]) {
|
|
|
|
|
return UITextContentTypeAddressState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"addressCity"]) {
|
|
|
|
|
return UITextContentTypeAddressCity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"sublocality"]) {
|
|
|
|
|
return UITextContentTypeSublocality;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"streetAddressLine1"]) {
|
|
|
|
|
return UITextContentTypeStreetAddressLine1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"streetAddressLine2"]) {
|
|
|
|
|
return UITextContentTypeStreetAddressLine2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"countryName"]) {
|
|
|
|
|
return UITextContentTypeCountryName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"fullStreetAddress"]) {
|
|
|
|
|
return UITextContentTypeFullStreetAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"postalCode"]) {
|
|
|
|
|
return UITextContentTypePostalCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"location"]) {
|
|
|
|
|
return UITextContentTypeLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"creditCardNumber"]) {
|
|
|
|
|
return UITextContentTypeCreditCardNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"email"]) {
|
|
|
|
|
return UITextContentTypeEmailAddress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"jobTitle"]) {
|
|
|
|
|
return UITextContentTypeJobTitle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"givenName"]) {
|
|
|
|
|
return UITextContentTypeGivenName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"middleName"]) {
|
|
|
|
|
return UITextContentTypeMiddleName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"familyName"]) {
|
|
|
|
|
return UITextContentTypeFamilyName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"name"]) {
|
|
|
|
|
return UITextContentTypeName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"namePrefix"]) {
|
|
|
|
|
return UITextContentTypeNamePrefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"nameSuffix"]) {
|
|
|
|
|
return UITextContentTypeNameSuffix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"nickname"]) {
|
|
|
|
|
return UITextContentTypeNickname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"organizationName"]) {
|
|
|
|
|
return UITextContentTypeOrganizationName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ([hint isEqualToString:@"telephoneNumber"]) {
|
|
|
|
|
return UITextContentTypeTelephoneNumber;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
|
if ([hint isEqualToString:@"password"]) {
|
|
|
|
|
return UITextContentTypePassword;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (@available(iOS 12.0, *)) {
|
|
|
|
|
if ([hint isEqualToString:@"oneTimeCode"]) {
|
|
|
|
|
return UITextContentTypeOneTimeCode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hints[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NSString* uniqueIdFromDictionary(NSDictionary* dictionary) {
|
|
|
|
|
NSDictionary* autofill = dictionary[@"autofill"];
|
|
|
|
|
return autofill == nil ? nil : autofill[@"uniqueIdentifier"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - FlutterTextPosition
|
|
|
|
|
|
|
|
|
|
@implementation FlutterTextPosition
|
|
|
|
|
@@ -140,6 +256,10 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface FlutterTextInputView ()
|
|
|
|
|
@property(nonatomic, copy) NSString* autofillId;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation FlutterTextInputView {
|
|
|
|
|
int _textInputClient;
|
|
|
|
|
const char* _selectionAffinity;
|
|
|
|
|
@@ -184,6 +304,7 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
[_markedTextRange release];
|
|
|
|
|
[_selectedTextRange release];
|
|
|
|
|
[_tokenizer release];
|
|
|
|
|
[_autofillId release];
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -241,7 +362,10 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
#pragma mark - UIResponder Overrides
|
|
|
|
|
|
|
|
|
|
- (BOOL)canBecomeFirstResponder {
|
|
|
|
|
return YES;
|
|
|
|
|
// Only the currently focused input field can
|
|
|
|
|
// become the first responder. This prevents iOS
|
|
|
|
|
// from changing focus by itself.
|
|
|
|
|
return _textInputClient != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UITextInput Overrides
|
|
|
|
|
@@ -600,16 +724,22 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
composingBase = ((FlutterTextPosition*)self.markedTextRange.start).index;
|
|
|
|
|
composingExtent = ((FlutterTextPosition*)self.markedTextRange.end).index;
|
|
|
|
|
}
|
|
|
|
|
[_textInputDelegate updateEditingClient:_textInputClient
|
|
|
|
|
withState:@{
|
|
|
|
|
@"selectionBase" : @(selectionBase),
|
|
|
|
|
@"selectionExtent" : @(selectionExtent),
|
|
|
|
|
@"selectionAffinity" : @(_selectionAffinity),
|
|
|
|
|
@"selectionIsDirectional" : @(false),
|
|
|
|
|
@"composingBase" : @(composingBase),
|
|
|
|
|
@"composingExtent" : @(composingExtent),
|
|
|
|
|
@"text" : [NSString stringWithString:self.text],
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
NSDictionary* state = @{
|
|
|
|
|
@"selectionBase" : @(selectionBase),
|
|
|
|
|
@"selectionExtent" : @(selectionExtent),
|
|
|
|
|
@"selectionAffinity" : @(_selectionAffinity),
|
|
|
|
|
@"selectionIsDirectional" : @(false),
|
|
|
|
|
@"composingBase" : @(composingBase),
|
|
|
|
|
@"composingExtent" : @(composingExtent),
|
|
|
|
|
@"text" : [NSString stringWithString:self.text],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (_textInputClient == 0 && _autofillId != nil) {
|
|
|
|
|
[_textInputDelegate updateEditingClient:_textInputClient withState:state withTag:_autofillId];
|
|
|
|
|
} else {
|
|
|
|
|
[_textInputDelegate updateEditingClient:_textInputClient withState:state];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)hasText {
|
|
|
|
|
@@ -671,12 +801,15 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation FlutterTextInputPlugin {
|
|
|
|
|
FlutterTextInputView* _view;
|
|
|
|
|
FlutterTextInputView* _secureView;
|
|
|
|
|
FlutterTextInputView* _activeView;
|
|
|
|
|
FlutterTextInputViewAccessibilityHider* _inputHider;
|
|
|
|
|
}
|
|
|
|
|
@interface FlutterTextInputPlugin ()
|
|
|
|
|
@property(nonatomic, retain) FlutterTextInputView* nonAutofillInputView;
|
|
|
|
|
@property(nonatomic, retain) FlutterTextInputView* nonAutofillSecureInputView;
|
|
|
|
|
@property(nonatomic, retain) NSMutableArray<FlutterTextInputView*>* inputViews;
|
|
|
|
|
@property(nonatomic, assign) FlutterTextInputView* activeView;
|
|
|
|
|
@property(nonatomic, retain) FlutterTextInputViewAccessibilityHider* inputHider;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation FlutterTextInputPlugin
|
|
|
|
|
|
|
|
|
|
@synthesize textInputDelegate = _textInputDelegate;
|
|
|
|
|
|
|
|
|
|
@@ -684,12 +817,13 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
self = [super init];
|
|
|
|
|
|
|
|
|
|
if (self) {
|
|
|
|
|
_view = [[FlutterTextInputView alloc] init];
|
|
|
|
|
_view.secureTextEntry = NO;
|
|
|
|
|
_secureView = [[FlutterTextInputView alloc] init];
|
|
|
|
|
_secureView.secureTextEntry = YES;
|
|
|
|
|
_nonAutofillInputView = [[FlutterTextInputView alloc] init];
|
|
|
|
|
_nonAutofillInputView.secureTextEntry = NO;
|
|
|
|
|
_nonAutofillInputView = [[FlutterTextInputView alloc] init];
|
|
|
|
|
_nonAutofillSecureInputView.secureTextEntry = YES;
|
|
|
|
|
_inputViews = [[NSMutableArray alloc] init];
|
|
|
|
|
|
|
|
|
|
_activeView = _view;
|
|
|
|
|
_activeView = _nonAutofillInputView;
|
|
|
|
|
_inputHider = [[FlutterTextInputViewAccessibilityHider alloc] init];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -698,9 +832,10 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
|
[self hideTextInput];
|
|
|
|
|
[_view release];
|
|
|
|
|
[_secureView release];
|
|
|
|
|
[_nonAutofillInputView release];
|
|
|
|
|
[_nonAutofillSecureInputView release];
|
|
|
|
|
[_inputHider release];
|
|
|
|
|
[_inputViews release];
|
|
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
@@ -733,58 +868,113 @@ static UIReturnKeyType ToUIReturnKeyType(NSString* inputType) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showTextInput {
|
|
|
|
|
NSAssert([UIApplication sharedApplication].keyWindow != nullptr,
|
|
|
|
|
UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
|
|
|
|
|
NSAssert(keyWindow != nullptr,
|
|
|
|
|
@"The application must have a key window since the keyboard client "
|
|
|
|
|
@"must be part of the responder chain to function");
|
|
|
|
|
_activeView.textInputDelegate = _textInputDelegate;
|
|
|
|
|
[_inputHider addSubview:_activeView];
|
|
|
|
|
[[UIApplication sharedApplication].keyWindow addSubview:_inputHider];
|
|
|
|
|
if (![_activeView isDescendantOfView:_inputHider]) {
|
|
|
|
|
[_inputHider addSubview:_activeView];
|
|
|
|
|
}
|
|
|
|
|
[keyWindow addSubview:_inputHider];
|
|
|
|
|
[_activeView becomeFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)hideTextInput {
|
|
|
|
|
[_activeView resignFirstResponder];
|
|
|
|
|
[_activeView removeFromSuperview];
|
|
|
|
|
[_inputHider removeFromSuperview];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setTextInputClient:(int)client withConfiguration:(NSDictionary*)configuration {
|
|
|
|
|
NSDictionary* inputType = configuration[@"inputType"];
|
|
|
|
|
NSString* keyboardAppearance = configuration[@"keyboardAppearance"];
|
|
|
|
|
if ([configuration[@"obscureText"] boolValue]) {
|
|
|
|
|
_activeView = _secureView;
|
|
|
|
|
NSArray* fields = configuration[@"fields"];
|
|
|
|
|
NSString* clientUniqueId = uniqueIdFromDictionary(configuration);
|
|
|
|
|
bool isSecureTextEntry = [configuration[@"obscureText"] boolValue];
|
|
|
|
|
|
|
|
|
|
if (fields == nil) {
|
|
|
|
|
_activeView = isSecureTextEntry ? _nonAutofillSecureInputView : _nonAutofillInputView;
|
|
|
|
|
[FlutterTextInputPlugin setupInputView:_activeView withConfiguration:configuration];
|
|
|
|
|
|
|
|
|
|
if (![_activeView isDescendantOfView:_inputHider]) {
|
|
|
|
|
[_inputHider addSubview:_activeView];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_activeView = _view;
|
|
|
|
|
NSAssert(clientUniqueId != nil, @"The client's unique id can't be null");
|
|
|
|
|
for (FlutterTextInputView* view in _inputViews) {
|
|
|
|
|
[view removeFromSuperview];
|
|
|
|
|
}
|
|
|
|
|
for (UIView* subview in _inputHider.subviews) {
|
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[_inputViews removeAllObjects];
|
|
|
|
|
|
|
|
|
|
for (NSDictionary* field in fields) {
|
|
|
|
|
FlutterTextInputView* newInputView = [[[FlutterTextInputView alloc] init] autorelease];
|
|
|
|
|
newInputView.textInputDelegate = _textInputDelegate;
|
|
|
|
|
[_inputViews addObject:newInputView];
|
|
|
|
|
|
|
|
|
|
NSString* autofillId = uniqueIdFromDictionary(field);
|
|
|
|
|
newInputView.autofillId = autofillId;
|
|
|
|
|
|
|
|
|
|
if ([clientUniqueId isEqualToString:autofillId]) {
|
|
|
|
|
_activeView = newInputView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[FlutterTextInputPlugin setupInputView:newInputView withConfiguration:field];
|
|
|
|
|
[_inputHider addSubview:newInputView];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_activeView.keyboardType = ToUIKeyboardType(inputType);
|
|
|
|
|
_activeView.returnKeyType = ToUIReturnKeyType(configuration[@"inputAction"]);
|
|
|
|
|
_activeView.autocapitalizationType = ToUITextAutoCapitalizationType(configuration);
|
|
|
|
|
[_activeView setTextInputClient:client];
|
|
|
|
|
[_activeView reloadInputViews];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)setupInputView:(FlutterTextInputView*)inputView
|
|
|
|
|
withConfiguration:(NSDictionary*)configuration {
|
|
|
|
|
NSDictionary* inputType = configuration[@"inputType"];
|
|
|
|
|
NSString* keyboardAppearance = configuration[@"keyboardAppearance"];
|
|
|
|
|
NSDictionary* autofill = configuration[@"autofill"];
|
|
|
|
|
|
|
|
|
|
inputView.secureTextEntry = [configuration[@"obscureText"] boolValue];
|
|
|
|
|
inputView.keyboardType = ToUIKeyboardType(inputType);
|
|
|
|
|
inputView.returnKeyType = ToUIReturnKeyType(configuration[@"inputAction"]);
|
|
|
|
|
inputView.autocapitalizationType = ToUITextAutoCapitalizationType(configuration);
|
|
|
|
|
|
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
|
NSString* smartDashesType = configuration[@"smartDashesType"];
|
|
|
|
|
// This index comes from the SmartDashesType enum in the framework.
|
|
|
|
|
bool smartDashesIsDisabled = smartDashesType && [smartDashesType isEqualToString:@"0"];
|
|
|
|
|
_activeView.smartDashesType =
|
|
|
|
|
inputView.smartDashesType =
|
|
|
|
|
smartDashesIsDisabled ? UITextSmartDashesTypeNo : UITextSmartDashesTypeYes;
|
|
|
|
|
NSString* smartQuotesType = configuration[@"smartQuotesType"];
|
|
|
|
|
// This index comes from the SmartQuotesType enum in the framework.
|
|
|
|
|
bool smartQuotesIsDisabled = smartQuotesType && [smartQuotesType isEqualToString:@"0"];
|
|
|
|
|
_activeView.smartQuotesType =
|
|
|
|
|
inputView.smartQuotesType =
|
|
|
|
|
smartQuotesIsDisabled ? UITextSmartQuotesTypeNo : UITextSmartQuotesTypeYes;
|
|
|
|
|
}
|
|
|
|
|
if ([keyboardAppearance isEqualToString:@"Brightness.dark"]) {
|
|
|
|
|
_activeView.keyboardAppearance = UIKeyboardAppearanceDark;
|
|
|
|
|
inputView.keyboardAppearance = UIKeyboardAppearanceDark;
|
|
|
|
|
} else if ([keyboardAppearance isEqualToString:@"Brightness.light"]) {
|
|
|
|
|
_activeView.keyboardAppearance = UIKeyboardAppearanceLight;
|
|
|
|
|
inputView.keyboardAppearance = UIKeyboardAppearanceLight;
|
|
|
|
|
} else {
|
|
|
|
|
_activeView.keyboardAppearance = UIKeyboardAppearanceDefault;
|
|
|
|
|
inputView.keyboardAppearance = UIKeyboardAppearanceDefault;
|
|
|
|
|
}
|
|
|
|
|
NSString* autocorrect = configuration[@"autocorrect"];
|
|
|
|
|
_activeView.autocorrectionType = autocorrect && ![autocorrect boolValue]
|
|
|
|
|
? UITextAutocorrectionTypeNo
|
|
|
|
|
: UITextAutocorrectionTypeDefault;
|
|
|
|
|
[_activeView setTextInputClient:client];
|
|
|
|
|
[_activeView reloadInputViews];
|
|
|
|
|
inputView.autocorrectionType = autocorrect && ![autocorrect boolValue]
|
|
|
|
|
? UITextAutocorrectionTypeNo
|
|
|
|
|
: UITextAutocorrectionTypeDefault;
|
|
|
|
|
if (@available(iOS 10.0, *)) {
|
|
|
|
|
if (autofill == nil) {
|
|
|
|
|
inputView.textContentType = @"";
|
|
|
|
|
} else {
|
|
|
|
|
inputView.textContentType = ToUITextContentType(autofill[@"hints"]);
|
|
|
|
|
[inputView setTextInputState:autofill[@"editingValue"]];
|
|
|
|
|
// An input field needs to be visible in order to get
|
|
|
|
|
// autofilled when it's not the one that triggered
|
|
|
|
|
// autofill.
|
|
|
|
|
inputView.frame = CGRectMake(0, 0, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setTextInputEditingState:(NSDictionary*)state {
|
|
|
|
|
|