Skip to content

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Nov 21, 2019

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.

gif

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:

  • iOS autocorrection rectangle should appear on demand and dismiss when the text changes or when focus is lost.
  • TextInputClient showAutocorrectionPromptRect method is called.

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Nov 21, 2019
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 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
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

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?

@LongCatIsLooong
Copy link
Contributor Author

LongCatIsLooong commented Dec 3, 2019

@justinmc oh sorry there's an engine PR flutter/engine#13959 which is also needed in order to get the rectangle to show up.

@justinmc
Copy link
Contributor

justinmc commented Dec 3, 2019

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?

@LongCatIsLooong
Copy link
Contributor Author

LongCatIsLooong commented Dec 3, 2019

One other thing: can this highlight be disabled on native without disabling autocorrection?

Not that I'm aware of.

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.

LGTM 👍

Copy link
Contributor

@HansMuller HansMuller left a 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;
Copy link
Contributor

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

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

Choose a reason for hiding this comment

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

shown => displayed

@LongCatIsLooong LongCatIsLooong merged commit 0f8c0da into flutter:master Dec 18, 2019
@LongCatIsLooong LongCatIsLooong deleted the autocorrection branch December 18, 2019 00:22
chingjun added a commit that referenced this pull request Dec 18, 2019
chingjun added a commit that referenced this pull request Dec 18, 2019
LongCatIsLooong added a commit to LongCatIsLooong/flutter that referenced this pull request Apr 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autocorrect tooltips don't appear on iOS

5 participants