-
Notifications
You must be signed in to change notification settings - Fork 29.7k
iOS UITextInput autocorrection prompt #45354
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 UITextInput autocorrection prompt #45354
Conversation
justinmc
left a comment
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 want to make sure that the showAutocorrectionPromptRect method on EditableText is necessary (commented above), otherwise this looks great. Sorry for the delay in reviewing this.
I like the pattern of having EditableText fully configurable and TextField and CupertinoTextField just specify their specific color 👍.
Oh and I just tried running this really quick because I wanted to see the "flickering", but I didn't see the rectangle showing up at all. I probably did something wrong, I just checked out your branch, ran the gallery, and went to the Cupertino text field page. Is there anything else I need to do to get it to show up?
| } | ||
|
|
||
| TextRange _promptRectRange; | ||
| /// Dismisses the currently shown prompt rectange and displays a new prompt rectangle |
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.
rectange => rectangle
| TextRange _currentPromptRectRange; | ||
|
|
||
| @override | ||
| void showAutocorrectionPromptRect(int start, int end) { |
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.
Why did you create this method instead of handling the range as a parameter only?
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.
It's part of the TextInputClient interface now.
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.
Oh I see, I didn't realize how that worked. Thanks.
| color: enabled ? decorationColor : (decorationColor ?? disabledColor), | ||
| ); | ||
|
|
||
| final Color selectionColor = CupertinoTheme.of(context).primaryColor.withOpacity(0.2); |
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.
Is there anywhere you can document what the selection color will be for Material and Cupertino?
|
@justinmc oh sorry there's an engine PR flutter/engine#13959 which is also needed in order to get the rectangle to show up. |
|
Ah of course, thanks. I tried it now and I do see what you mean about the flickering behavior, but I think it's not very noticeably wrong, at least not in the simulator. Should be fine, but I'll keep an eye out for issues about it in the future. One other thing: can this highlight be disabled on native without disabling autocorrection? |
Not that I'm aware of. |
justinmc
left a comment
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.
LGTM 👍
HansMuller
left a comment
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.
LGTM too
| } | ||
|
|
||
| /// The color used to paint the prompt rectangle. | ||
| Color get promptRectColor => _promptRectPaint.color; |
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.
Should note that this property only impacts non-web iOS applications. Likewise for promptRectRange.
Should also note that setting promptRectColor to null indicates that the promptRect shouldn't be drawn at all. There should be tests that cover this
| } | ||
|
|
||
| TextRange _promptRectRange; | ||
| /// Dismisses the currently shown prompt rectangle and displays a new prompt rectangle |
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.
shown => displayed
| /// Dismisses the currently shown prompt rectangle and displays a new prompt rectangle | ||
| /// over [newRange] in the given color [promptRectColor]. | ||
| /// | ||
| /// When set to null, the currently shown prompt rectangle (if any) will be dismissed. |
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.
shown => displayed
Description
This PR implements iOS UITextInput autocorrection prompt feature where typos get highlighted (surrounded by a prompt rectangle, much like text selection) before they are corrected.
Engine PR: flutter/engine#13959.
Caveat
The prompt rectangle may flicker if you type really really fast. This is because there's no signal we can get from the iOS side for dismissing the autocorrection prompt, so we'll have to dismiss the rectangle aggressively every time the text changes.
Related Issues
Fixes #12920
Tests
I added the following tests:
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?