Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jan-swiezynski
Copy link

There is no possibility on iOS to leave the auto-suggest bar visible and have the autocorrection turned off when showing TextField. Tapping outside TextField with autocorrection on fills the TextField with suggestion and it's not always an intended behaviour.

Autocorrection on

Autocorrection off, enableSuggestion on

Fixes flutter/flutter#159584

Removed 1 Test.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • [] I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@chinmaygarde
Copy link
Member

cc @cbracken

@cbracken cbracken self-requested a review December 4, 2024 15:33
Copy link
Member

@cbracken cbracken left a 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];
Copy link
Member

@cbracken cbracken Dec 4, 2024

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, not bool. 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 of enableSuggestions 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;
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor

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);
}

Copy link
Member

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.

@cbracken cbracken requested review from justinmc and bleroux December 4, 2024 16:33
Copy link
Contributor

@justinmc justinmc left a 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:

Spell check Suggestions Autocorrect
Red underline, red highlight, and suggestion dialog for misspelled words. Completion suggestions that appear above the software keyboard as the user types. If a hardware keyboard is used instead, there is a blue highlight and a suggestion dialog. Automatic replacement of common typos.
Disabled by default, enable with spellCheckConfiguration: SpellCheckConfiguration(). Enabled by default, disable with autocorrect: false. After this PR, would instead be disabled with enableSuggestions: false. Enabled by default, disable with autocorrect: false.
Screenshot 2024-12-04 at 1 06 36 PM Screenshot 2024-12-04 at 1 07 22 PM Screenshot 2024-12-04 at 1 21 15 PM

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;
Copy link
Contributor

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.

@jan-swiezynski
Copy link
Author

@justinmc Yes, exactly. The change separates autocorrect from suggestions displays and allows presenting suggestions but with autocorrect feature disabled.

Copy link
Contributor

@justinmc justinmc left a 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.

@cbracken
Copy link
Member

Hi @jan-swiezynski is this still on your radar?

@jan-swiezynski
Copy link
Author

Hi @jan-swiezynski is this still on your radar?

Yes, I'll get back to it in few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to disable autocorrection and leave the auto-suggest bar visible on iOS with TextField
5 participants