-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] option to enable suggestions with autocorrect off #56859
base: main
Are you sure you want to change the base?
[iOS] option to enable suggestions with autocorrect off #56859
Conversation
cc @cbracken |
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.
I've left style/testing comments inline, but at a much higher level, I'm not entirely whether enableSuggestions
is the right approach here.
EditableText
widgets have a spellCheckConfiguration
property that holds a SpellCheckConfiguration
. I would have assumed that passing SpellCheckConfiguration.disabled
would be the way to do this.
@justinmc will know the answer to that question.
@@ -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]; |
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:
- In Objective-C we should be using
BOOL
, notbool
. In this case, the surrounding code is unfortunately already using C++bool
. I'll send a separate cleanup patch. - The Dart side API for this is
enableSuggestions
, for readability, please deal with this settings in terms ofenableSuggestions
in 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:
NSString* enableSuggestionsValue = configuration[kEnableSuggestions];
BOOL enableSuggestions = enabledSuggestionsValue ? enableSuggestionsValue.boolValue : YES;
self.spellCheckingType = | ||
autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; | ||
disableSuggestions ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; |
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.
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 UITextSpellCheckingType
docs.
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.
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?
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?
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.
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.
XCTAssertEqual(inputView.autocorrectionType, UITextAutocorrectionTypeNo); | ||
XCTAssertEqual(inputView.spellCheckingType, UITextSpellCheckingTypeNo); | ||
} | ||
|
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.
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.
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.
To be clear on iOS these are the three features we're talking about here:
So suggestions and autocorrect are controlled by the same flag, and this PR wants to be able to control them independently? @jan-swiezynski Can you confirm that your understanding is the same as mine and that this PR has the desired effect?
self.spellCheckingType = | ||
autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; | ||
disableSuggestions ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault; |
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.
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.
@justinmc Yes, exactly. The change separates autocorrect from suggestions displays and allows presenting suggestions but with autocorrect feature disabled. |
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.
I checked out this branch locally and it fixes the intended bug, but it's not possible to hide suggestions while enabling autocorrect! Is it possible to fix that as well?
autocorrect | enableSuggestions | spellCheckConfiguration | This PR |
---|---|---|---|
false | false | SpellCheckConfiguration.disabled() | ✅ |
false | false | SpellCheckConfiguration() | ✅ |
false | true | SpellCheckConfiguration.disabled() | ✅ |
false | true | SpellCheckConfiguration() | ✅ |
true | false | SpellCheckConfiguration.disabled() | ❌ Suggestions appear but should not. |
true | false | SpellCheckConfiguration() | ❌ Suggestions appear but should not. |
true | true | SpellCheckConfiguration.disabled() | ✅ |
true | true | SpellCheckConfiguration() | ✅ |
Edit: This is broken on the main
branch as well, so I'm ok with considering this a separate issue if it's not a trivial fix.
Hi @jan-swiezynski is this still on your radar? |
Yes, I'll get back to it in few days. |
There is no possibility on iOS to leave the auto-suggest bar visible and have the autocorrection turned off when showing
TextField
. Tapping outsideTextField
with autocorrection on fills theTextField
with suggestion and it's not always an intended behaviour.Fixes flutter/flutter#159584
Removed 1 Test.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.