-
Notifications
You must be signed in to change notification settings - Fork 6k
[iOS] option to enable suggestions with autocorrect off #56859
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ | |
| static NSString* const kAutofillHints = @"hints"; | ||
|
|
||
| static NSString* const kAutocorrectionType = @"autocorrect"; | ||
| static NSString* const kEnableSuggestions = @"enableSuggestions"; | ||
|
|
||
| #pragma mark - Static Functions | ||
|
|
||
|
|
@@ -934,8 +935,10 @@ - (void)configureWithDictionary:(NSDictionary*)configuration { | |
| bool autocorrectIsDisabled = autocorrect && ![autocorrect boolValue]; | ||
| self.autocorrectionType = | ||
| autocorrectIsDisabled ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault; | ||
| NSString* enableSuggestions = configuration[kEnableSuggestions]; | ||
| bool disableSuggestions = enableSuggestions && ![enableSuggestions boolValue]; | ||
| self.spellCheckingType = | ||
| autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; | ||
| disableSuggestions ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existing code was landed by @bleroux in #46144 to fix flutter/flutter#134881. Updating this behaviour will be a minor regression to users who were relying on disabling autocorrect to disable spelling suggestions, but that seems reasonable since this adds a new finer-grained mechanism to opt out. The enableSuggestions API docs currently state that this flag only affects Android. @bleroux do you know the background on why we don't apply it to iOS as well? If we change this behaviour, we will definitely need to update the framework side API documentation to reflect this and point to Apple's
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't know the background. The documentation landed in flutter/flutter#42550. It seems that this was implemented to match an Android feature. Maybe something similar did not exist on the iOS side at that time?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My guess is that it wasn't possible to control these independently at the time that Flutter's enableSuggestions was added. Are we sure that's not still true? +1 to updating the docs if this change lands. |
||
| self.autofillId = AutofillIdFromDictionary(configuration); | ||
| if (autofill == nil) { | ||
| self.textContentType = @""; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -810,23 +810,6 @@ - (void)testInputActionContinueAction { | |
| OCMVerify([mockBinaryMessenger sendOnChannel:@"flutter/textinput" message:encodedMethodCall]); | ||
| } | ||
|
|
||
| - (void)testDisablingAutocorrectDisablesSpellChecking { | ||
| FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; | ||
|
|
||
| // Disable the interactive selection. | ||
| NSDictionary* config = self.mutableTemplateCopy; | ||
| [inputView configureWithDictionary:config]; | ||
|
|
||
| XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeDefault); | ||
| XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeDefault); | ||
|
|
||
| [config setValue:@(NO) forKey:@"autocorrect"]; | ||
| [inputView configureWithDictionary:config]; | ||
|
|
||
| XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeNo); | ||
| XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeNo); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't delete tests for existing behaviour; they were added for a reason. You'll need to update the existing test to reflect the new expected behaviour and add additional testing to cover all four combinations of autocorrect/enableSuggestions. |
||
| - (void)testReplaceTestLocalAdjustSelectionAndMarkedTextRange { | ||
| FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; | ||
| [inputView setMarkedText:@"test text" selectedRange:NSMakeRange(0, 5)]; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes:
BOOL, notbool. In this case, the surrounding code is unfortunately already using C++bool. I'll send a separate cleanup patch.enableSuggestions, for readability, please deal with this settings in terms ofenableSuggestionsin the Obj-C code. See the style guide rationale for why. Again, the surrounding code violates this and I'll send a separate patch to clean it up.Something like this works: