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

[ios17][text_input]fix ios 17.0 keyboard freeze when switching languages (without relying on text affinity) #47566

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Nov 1, 2023

After close examination of the UIKit's default string tokenizer, when querying the line enclosing the end of doc position in forward direction, we should return nil (regardless whether the position is forward or backward affinity).

This aligns with the API doc:

If the text position is at a text-unit boundary, it is considered enclosed only if the next position in the given direction is entirely enclosed.

Will cherry pick this soon. Otherwise it will be less and less important as users upgrade to iOS 17.1.

Why my previous workaround also works?

It turns out my previous workaround PR #46591 works only because our misuse of text affinity in our text input. Specifically, when adding text affinity support, we only added it to FlutterTextPosition, but not FlutterTextRange. So when getting the beginning/end position from the range, we assign arbitrary affinities.

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

flutter/flutter#134716

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

@hellohuanlin hellohuanlin marked this pull request as ready for review November 9, 2023 19:01
@hellohuanlin
Copy link
Contributor Author

I need to do more testing on iOS 17.0 and 17.1 (and the newly released 17.1.1), around voice control, scribble and floating cursor selection. But so far this PR is looking good and should be ready for review

@stuartmorgan
Copy link
Contributor

when querying the line enclosing the end of doc position in forward direction, we should return nil (regardless whether the position is forward or backward affinity). This is undocumented behavior of UIKit

Is it undocumented? The docs for the method we are implementing say:

If the text position is at a text-unit boundary, it is considered enclosed only if the next position in the given direction is entirely enclosed.

Isn't the case here that we are at a boundary, and the next position in the given direction doesn't exist (in which case the next position can't be entirely enclosed)?

@hellohuanlin
Copy link
Contributor Author

Isn't the case here that we are at a boundary, and the next position in the given direction doesn't exist (in which case the next position can't be entirely enclosed)?

True. It sounds indeed like what we are doing here.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM with comment nit.

inDirection:(UITextDirection)direction {
// TODO(hellohuanlin): remove iOS 17 check. The same logic should apply to older iOS version.
if (@available(iOS 17.0, *)) {
// If querying the line from end of document in forward direction, report not found.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should link to and quote the docs I mentioned in my comment so that it's clear why.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for looking into this!

@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2023
@auto-submit auto-submit bot merged commit ffcc5bf into flutter:main Nov 14, 2023
22 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 14, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 14, 2023
hellohuanlin added a commit to hellohuanlin/engine that referenced this pull request Nov 14, 2023
…ges (without relying on text affinity) (flutter#47566)

After close examination of the UIKit's default string tokenizer, when querying the line enclosing the end of doc position **in forward direction**, we should return nil (regardless whether the position is forward or backward affinity). 

This aligns with the [API doc](https://developer.apple.com/documentation/uikit/uitextinputtokenizer/1614464-rangeenclosingposition?language=objc): 

> If the text position is at a text-unit boundary, it is considered enclosed only if the next position in the given direction is entirely enclosed.

Will cherry pick this soon. Otherwise it will be less and less important as users upgrade to iOS 17.1. 

### Why my previous workaround also works? 

It turns out my previous workaround PR flutter#46591 works only because our misuse of text affinity in our text input. Specifically, when adding text affinity support, we only added it to `FlutterTextPosition`, but not `FlutterTextRange`. So when getting the beginning/end position from the range, we assign arbitrary affinities. 

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

flutter#46591

*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
hellohuanlin added a commit to hellohuanlin/engine that referenced this pull request Nov 14, 2023
…ges (without relying on text affinity) (flutter#47566)

After close examination of the UIKit's default string tokenizer, when querying the line enclosing the end of doc position **in forward direction**, we should return nil (regardless whether the position is forward or backward affinity). 

This aligns with the [API doc](https://developer.apple.com/documentation/uikit/uitextinputtokenizer/1614464-rangeenclosingposition?language=objc): 

> If the text position is at a text-unit boundary, it is considered enclosed only if the next position in the given direction is entirely enclosed.

Will cherry pick this soon. Otherwise it will be less and less important as users upgrade to iOS 17.1. 

### Why my previous workaround also works? 

It turns out my previous workaround PR flutter#46591 works only because our misuse of text affinity in our text input. Specifically, when adding text affinity support, we only added it to `FlutterTextPosition`, but not `FlutterTextRange`. So when getting the beginning/end position from the range, we assign arbitrary affinities. 

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

flutter#46591

*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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 14, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 14, 2023
…138441)

flutter/engine@f15b259...c5a067b

2023-11-14 [email protected] Roll Skia from 650913eacd01 to 15a2577b12c1 (1 revision) (flutter/engine#48036)
2023-11-14 [email protected] Roll Skia from 6feae2c274ce to 650913eacd01 (1 revision) (flutter/engine#48034)
2023-11-14 [email protected] [macOS] Eliminate unused OCMock includes (flutter/engine#48031)
2023-11-14 [email protected] [ios17][text_input]fix ios 17.0 keyboard freeze when switching languages (without relying on text affinity) (flutter/engine#47566)

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 [email protected],[email protected],[email protected] 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://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Nov 16, 2023
…ching languages (#48041)

CP for #47566

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

flutter/flutter#134716

*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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants