Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ static UITextContentType ToUITextContentType(NSArray<NSString*>* 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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -549,6 +557,7 @@ - (instancetype)init {
_enablesReturnKeyAutomatically = NO;
_keyboardAppearance = UIKeyboardAppearanceDefault;
_keyboardType = UIKeyboardTypeDefault;
_keyboardEnabled = YES;
_returnKeyType = UIReturnKeyDone;
_secureTextEntry = NO;
_accessibilityEnabled = NO;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1451,6 +1461,10 @@ - (void)updateMarkedRect:(NSDictionary*)dictionary {
}

- (void)showTextInput {
if (!_activeView.keyboardEnabled) {
[self hideTextInput];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the hideTextInput's implementation it removes the active view from the view hierarchy and disables accessibility. Will this break voiceover? @chunhtai

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it will, we may need to find a better way to prevent softkeyboard from showing up. whichever the method we found here, we need to make sure the key stroke feedback in voice over still works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use an empty UIView for inputView according to the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would either of you have a chance to give it a shot, or is there anyone else that might have time to help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently dealing with something else. I'll give that a try later.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputView didn't work as advertised for me, but inputViewController did. I overrode inputViewController like so :

  let inputVC = UIInputViewController()
  override var inputViewController: UIInputViewController? {
    shouldShowKeyboard ? nil : inputVC
  }

You get the system keyboard when returning nil for inputViewController, and a UIIpnutViewController gives a zero-width keyboard view.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Mind pushing the patch? I'll close this because I'm no iOS dev... 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for trying it out!

return;
}
_activeView.textInputDelegate = _textInputDelegate;
[self addToInputParentViewIfNeeded:_activeView];
// Adds a delay to prevent the text view from receiving accessibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@interface FlutterTextInputView ()
@property(nonatomic, copy) NSString* autofillId;
@property(nonatomic, assign) BOOL keyboardEnabled;

- (void)setEditableTransform:(NSArray*)matrix;
- (void)setTextInputState:(NSDictionary*)state;
Expand Down Expand Up @@ -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<FlutterTextInputView*>* 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 {
Expand Down