From 2f12ee6ce0645e23ae1b5c67263108fb0964967d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 15 Jun 2021 23:35:09 +0200 Subject: [PATCH 1/3] iOS: add support for TextInputType.none TextInputType.none makes it possible to disable the virtual keyboard for certain TextFields, and lays the foundations for custom in-app virtual keyboards (flutter/flutter#76072). Ref: flutter/flutter#83567 --- .../ios/framework/Source/FlutterTextInputPlugin.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 038a40d378c63..156c8fb1176da 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -253,6 +253,13 @@ static UITextContentType ToUITextContentType(NSArray* hints) { return hints[0]; } +static BOOL isKeyboardEnabled(NSDictionary* type) { + NSString* inputType = type[@"name"]; + if ([inputType isEqualToString:@"TextInputType.none"]) + return NO; + return YES; +} + // Retrieves the autofillId from an input field's configuration. Returns // nil if the field is nil and the input field is not a password field. static NSString* autofillIdFromDictionary(NSDictionary* dictionary) { @@ -508,6 +515,7 @@ @interface FlutterTextInputView () @property(nonatomic, assign) CGRect markedRect; @property(nonatomic) BOOL isVisibleToAutofill; @property(nonatomic, assign) BOOL accessibilityEnabled; +@property(nonatomic, assign) BOOL keyboardEnabled; - (void)setEditableTransform:(NSArray*)matrix; @end @@ -549,6 +557,7 @@ - (instancetype)init { _enablesReturnKeyAutomatically = NO; _keyboardAppearance = UIKeyboardAppearanceDefault; _keyboardType = UIKeyboardTypeDefault; + _keyboardEnabled = YES; _returnKeyType = UIReturnKeyDone; _secureTextEntry = NO; _accessibilityEnabled = NO; @@ -580,6 +589,7 @@ - (void)configureWithDictionary:(NSDictionary*)configuration { self.secureTextEntry = [configuration[kSecureTextEntry] boolValue]; self.keyboardType = ToUIKeyboardType(inputType); + self.keyboardEnabled = isKeyboardEnabled(inputType); self.returnKeyType = ToUIReturnKeyType(configuration[kInputAction]); self.autocapitalizationType = ToUITextAutoCapitalizationType(configuration); @@ -1451,6 +1461,10 @@ - (void)updateMarkedRect:(NSDictionary*)dictionary { } - (void)showTextInput { + if (!_activeView.keyboardEnabled) { + [self hideTextInput]; + return; + } _activeView.textInputDelegate = _textInputDelegate; [self addToInputParentViewIfNeeded:_activeView]; // Adds a delay to prevent the text view from receiving accessibility From 0af48cc4c393372cda123371532dffc475d41497 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 16 Jun 2021 08:49:43 +0200 Subject: [PATCH 2/3] Add test for keyboardEnabled --- .../Source/FlutterTextInputPluginTest.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m index d52359ecb387f..0e2ffa151d5f6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m @@ -14,6 +14,7 @@ @interface FlutterTextInputView () @property(nonatomic, copy) NSString* autofillId; +@property(nonatomic, assign) BOOL keyboardEnabled; - (void)setEditableTransform:(NSArray*)matrix; - (void)setTextInputState:(NSDictionary*)state; @@ -192,6 +193,22 @@ - (void)testKeyboardType { // Verify keyboardType is set to the value specified in config. XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeURL); + XCTAssertEqual(inputView.keyboardEnabled, YES); +} + +- (void)testKeyboardDisabled { + NSDictionary* config = self.mutableTemplateCopy; + [config setValue:@{@"name" : @"TextInputType.none"} forKey:@"inputType"]; + [self setClientId:123 configuration:config]; + + // Find all the FlutterTextInputViews we created. + NSArray* inputFields = self.installedInputViews; + + FlutterTextInputView* inputView = inputFields[0]; + + // Verify keyboardType is set to the value specified in config. + XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeDefault); + XCTAssertEqual(inputView.keyboardEnabled, NO); } - (void)testAutocorrectionPromptRectAppears { From 95cb5db31c2832eff0e4ce9f0b8e5829a99169a0 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 16 Jun 2021 12:54:43 +0200 Subject: [PATCH 3/3] Update comments in tests --- .../ios/framework/Source/FlutterTextInputPluginTest.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m index 0e2ffa151d5f6..230fc627ae36e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m @@ -191,7 +191,8 @@ - (void)testKeyboardType { FlutterTextInputView* inputView = inputFields[0]; - // Verify keyboardType is set to the value specified in config. + // Verify keyboardType and keyboardEnabled are set as appropriate for the input + // type specified in config. XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeURL); XCTAssertEqual(inputView.keyboardEnabled, YES); } @@ -206,7 +207,8 @@ - (void)testKeyboardDisabled { FlutterTextInputView* inputView = inputFields[0]; - // Verify keyboardType is set to the value specified in config. + // Verify keyboardType and keyboardEnabled are set as appropriate for the input + // type specified in config. XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeDefault); XCTAssertEqual(inputView.keyboardEnabled, NO); }