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 diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m index d52359ecb387f..230fc627ae36e 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; @@ -190,8 +191,26 @@ - (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); +} + +- (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 and keyboardEnabled are set as appropriate for the input + // type specified in config. + XCTAssertEqual(inputView.keyboardType, UIKeyboardTypeDefault); + XCTAssertEqual(inputView.keyboardEnabled, NO); } - (void)testAutocorrectionPromptRectAppears {