Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[ios][ios17]fix auto correction highlight on top left corner #44779

Merged
merged 4 commits into from
Aug 17, 2023

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Aug 16, 2023

Fix native auto-correction highlight region on top left corner.

This PR uses the system auto-correction highlight on iOS 17, which was disabled by #44354

Screenshot 2023-08-16 at 1 19 39 PM

List which issues are fixed by this PR. You must list at least one issue.

Fixes flutter/flutter#131622
Fixes flutter/flutter#131695
Fixes flutter/flutter#130818

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

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 Hixie said 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.

NSArray* transform = dictionary[@"transform"];
[_activeView setEditableTransform:transform];
int leftIndex = 12;
int topIndex = 13;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: these should be const.

_activeView.selectionRects = rectsAsRect;
[_activeView.inputDelegate textDidChange:_activeView];
} else {
_activeView.selectionRects = rectsAsRect;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than duplicate this line, which could cause drift over time, we should refactor to look more like the other method where there's a bool for sending updates.:

BOOL triggerTextUpdates = NO;
if (@available(iOS 17, *)) {
  // move explanatory comment here.
  triggerTextUpdates = YES;
}
if (triggerTextUpdates) {
  [_activeView.inputDelegate textWillChange:_activeView];
}
_activeView.selectionRects = rectsAsRect;
if (triggerTextUpdates) {
  [_activeView.inputDelegate textDidChange:_activeView];
}

_activeView.frame =
CGRectMake(0, 0, [dictionary[@"width"] intValue], [dictionary[@"height"] intValue]);
_activeView.tintColor = [UIColor clearColor];
} else {
if (@available(iOS 17, *)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a TODO to simplify all of this logic. It looks like post cherry-pick we can probably just make the _inputHider.frame logic unconditional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The iOS 16 behavior is different - the highlight region does not match the size of text (see screenshot in flutter/flutter#131695 for iOS 16). But will add a TODO to explain this.

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.

Some comments to make sure I understand how this bug affects versions before iOS 17, but looks good overall.

Comment on lines 2470 to 2472
// This is to fix an issue where the system auto-correction highlight is displayed at
// the top left corner of the screen on iOS 17+.
// See https://github.com/flutter/flutter/issues/131695
Copy link
Contributor

Choose a reason for hiding this comment

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

The autocorrect highlight is also displayed in the top left corner on earlier versions, it's just smaller, right? This sentence seems misleading, maybe remove it but keep the "See...". Really this is just positioning the input in the correct place, the place as Flutter's input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. How about instead of deleting it, I add a new line saying "This problem also happens on iOS 16, but the size of highlight does not match the text"?

// the top left corner of the screen on iOS 17+.
// See https://github.com/flutter/flutter/issues/131695
_inputHider.frame =
CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if you pass the real width and height here like in the scribble case above instead of 0,0?
[dictionary[@"width"] intValue], [dictionary[@"height"] intValue]

Copy link
Contributor Author

@hellohuanlin hellohuanlin Aug 16, 2023

Choose a reason for hiding this comment

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

I've tried that and got the same result in my tests. Nothing seems to break. But wanted to be safe and keep the same zero size as before.

Copy link
Contributor

Choose a reason for hiding this comment

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

(This is one of the things I was thinking would be part of unifying the these two codepaths in a follow-up, master-only PR.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a todo there.

BOOL shouldNotifyTextChange = NO;
if (@available(iOS 17, *)) {
// Force UIKit to query the selectionRects again on iOS 17+
// This is to fix a bug on iOS 17+ where UIKit queries the outdated selectionRects after
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to above, I think this bug exists on all versions of iOS, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in this case - in iOS 16, we do not use system highlight, so no such bug.

I also tried to notify the change on iOS 16 and nothing seems to break, but just to be safe here.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

// the top left corner of the screen on iOS 17+.
// See https://github.com/flutter/flutter/issues/131695
_inputHider.frame =
CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

(This is one of the things I was thinking would be part of unifying the these two codepaths in a follow-up, master-only PR.)

@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 17, 2023
@auto-submit auto-submit bot merged commit 5c05519 into flutter:main Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 17, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 17, 2023
…132797)

flutter/engine@5336702...5019d6d

2023-08-17 dkwingsmt@users.noreply.github.com Basic view management for engine classes (flutter/engine#42991)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from d0d390f9310d to bfd45173e5e3 (5 revisions) (flutter/engine#44820)
2023-08-17 matanlurey@users.noreply.github.com Implement 2 suggested Clang Tidy fixes we don't look for yet. (flutter/engine#44816)
2023-08-17 louiseh0313@gmail.com Add share to selection controls (flutter/engine#44554)
2023-08-17 zanderso@users.noreply.github.com Adds new builders for partial clang-tidy checks. (flutter/engine#44811)
2023-08-17 41930132+hellohuanlin@users.noreply.github.com [ios][ios17]fix auto correction highlight on top left corner (flutter/engine#44779)
2023-08-17 109111084+yaakovschectman@users.noreply.github.com [Windows] Delay enabling app lifecycle states until requested (flutter/engine#44238)
2023-08-17 dkwingsmt@users.noreply.github.com Move `viewConfiguration` parsing from `PlatformDispatcher` to `_hooks` (flutter/engine#44787)
2023-08-17 skia-flutter-autoroll@skia.org Roll Dart SDK from 92c32df13d31 to 7e4e5796ee99 (2 revisions) (flutter/engine#44810)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from c4805a975ab3 to d0d390f9310d (2 revisions) (flutter/engine#44807)
2023-08-17 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from cPncZK6z8HmuOmQr_... to 7xOzci7fempFgHNk9... (flutter/engine#44809)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from efb5a5e0b78b to c4805a975ab3 (2 revisions) (flutter/engine#44795)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from 11cb8cdd37c1 to efb5a5e0b78b (1 revision) (flutter/engine#44792)
2023-08-17 matanlurey@users.noreply.github.com Passthrough stderr results of clang_tidy when --enable-check-profile. (flutter/engine#44789)
2023-08-17 skia-flutter-autoroll@skia.org Roll Dart SDK from d6e1fca5dbdf to 92c32df13d31 (1 revision) (flutter/engine#44788)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from cPncZK6z8Hmu to 7xOzci7fempF

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@cyanglaz
Copy link
Contributor

I checked out this fix, now the system popup is not showing at all for flutter/flutter#132594

@justinmc
Copy link
Contributor

Hmm that's not what I would expect for this change... @cyanglaz You tried it on iOS 17?

@cyanglaz
Copy link
Contributor

yes on simulator tho

auto-submit bot pushed a commit that referenced this pull request Aug 18, 2023
…OS 17 (again) (#44812)

CP for #44779

Tested the stable branch with the fix on iPhone and iPad, with hardware and software keyboards, and with and without IME languages, iOS 16 and iOS 17

*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one issue.*

Fixes flutter/flutter#131622
Fixes flutter/flutter#131695
Fixes flutter/flutter#130818

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
@cyanglaz
Copy link
Contributor

@justinmc I saw that the fix is also cherry-picked. Can you or someone else confirm the issue that I saw and maybe we need to revert this fix and the cp if the issue does exist?

@hellohuanlin
Copy link
Contributor Author

Hmmm strange. When I tried it the system menu shows right next to the text field (the correct position) rather than the top left corner. But it did show up

@hellohuanlin
Copy link
Contributor Author

When i tried it on the release candidate branch (with the fix), the button does show up. But looks like the buttons are tappable. Here's iPhone simulator + iOS 17:

Simulator.Screen.Recording.-.iPhone.14.Pro.Max.-.2023-08-21.at.10.26.35.mp4

Hmmm, I may have remembered incorrectly previously. Could be a false alarm. Sorry :(

gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
…#44779)

Fix native auto-correction highlight region on top left corner. 

This PR uses the system auto-correction highlight on iOS 17, which was disabled by flutter#44354

<img width="479" alt="Screenshot 2023-08-16 at 1 19 39 PM" src="https://github.com/flutter/engine/assets/41930132/a5a1dda7-ba21-462e-a65c-1afeecf7559f">

*List which issues are fixed by this PR. You must list at least one issue.*

Fixes flutter/flutter#131622
Fixes flutter/flutter#131695
Fixes flutter/flutter#130818

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
auto-submit bot pushed a commit that referenced this pull request Sep 7, 2023
…ain)" (#45523)

This reverts part of #44779. Verified this to be the regression for flutter/flutter#133908. 

This pair of `textWill/DidChange` calls was added in Beta 1, in order to fix highlight region missing last character (more details [here](https://docs.google.com/document/d/1sM3HMv-SQin39yX1aPUU7vtGv7Hcef1Quc3QhRXBl6A/edit?resourcekey=0-SFYD8vmOIkXiXCZvB1Wlcw#heading=h.ddlvu2i2epyl)). 

However, that fix doesn't work anymore for Beta 7 - it turns out that in Beta 7, the system doesn't rely on the `selectionRects` to determine the highlight region anymore. Instead, the system relies on `firstRectForRange` API. So we fixed the system highlight in `firstRectForRange` in Beta 7. 

So even after reverting this change, the system highlight still works correctly in Beta 7. I was initially leaning towards keeping these calls even after Beta 7, because without it, the `selectionRects` are still out of sync with iOS text input system. (more details [here](https://docs.google.com/document/d/1sM3HMv-SQin39yX1aPUU7vtGv7Hcef1Quc3QhRXBl6A/edit?resourcekey=0-SFYD8vmOIkXiXCZvB1Wlcw)). 

However, I was able to verify that it is indeed `textWill/DidChange` that introduced the regression for IME inputs (It's unclear why they are related, so need further investigation). 

In summary, after this revert, system highlights are still in the right place, and with the right length. 

*List which issues are fixed by this PR. You must list at least one issue.*

Fixes flutter/flutter#133908

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-ios
Projects
None yet
4 participants