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

[iOSTextInputPlugin] bypass UIKit floating cursor coordinates clamping #26486

Merged

Conversation

LongCatIsLooong
Copy link
Contributor

Fixes flutter/flutter#70267.

The current implementation "works" only because UIKit doesn't properly handle "nil" somewhere: flutter/flutter#70267 (comment), and it breaks once the keyboard adds marked text to the input field.

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.
  • The reviewer has submitted any presubmit flakes in this PR using the engine presubmit flakes form before re-triggering the failure.

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

@google-cla google-cla bot added the cla: yes label May 29, 2021
@LongCatIsLooong LongCatIsLooong force-pushed the ios-floating-cursor-fix branch 2 times, most recently from ea93e35 to 3a10d3f Compare May 29, 2021 12:06
// This makes sure UITextSelectionView.interactionAssistant is not nil so
// UITextSelectionView has access to this view (and its bounds). Otherwise
// floating cursor breaks: https://github.com/flutter/flutter/issues/70267.
if (@available(iOS 13.0, *)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested on an iOS 12 simulator and couldn't reproduce the issue.

@@ -79,7 +79,6 @@ - (void)setUp {
}

- (void)tearDown {
[engine stopMocking];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line caused all the tests in the file to fail. Did we upgrade ocmock or something?

Copy link
Member

Choose a reason for hiding this comment

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

Nope we didn't. You shouldn't remove this line. The tests are running as part of CI so we know this works before the changes here. Let me know what errors you are getting and I can try to help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put it back it starts failing again: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket.appspot.com/8845604182114825824/+/u/Host_Tests_for_ios_debug_sim/stdout

/opt/s/w/ir/cache/builder/src/out/ios_debug_sim/../../flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm:1211: error: -[FlutterTextInputPluginTest testPasswordAutofillHack] : failed: caught "NSInternalInconsistencyException", "** Cannot use mock object OCClassMockObject(FlutterEngine) at 0x600002eabb60. This error usually occurs when a mock object is used after stopMocking has been called on it. In most cases it is not necessary to call stopMocking. If you know you have to, please make sure that the mock object is not used afterwards."

Copy link
Member

@gaaclarke gaaclarke Jun 1, 2021

Choose a reason for hiding this comment

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

This means you are leaking an object beyond your test that is talking to the mock engine, probably a view controller. Let me look at your test code to see if I can spot it. (this can cause other tests to fail beyond yours)

Copy link
Member

@gaaclarke gaaclarke Jun 1, 2021

Choose a reason for hiding this comment

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

Looks like your test is fine. One of 2 things are happening:

  1. Your test is messing up the timing and surfacing an issue that was already present where we weren't correctly synchronizing some asynchronous operations (like NSNotifications)
  2. You've introduced a leak that is causing view controllers not to be deallocated, which causes them to leak into other tests and break them.

Here's an example where I had to fix similar issues:
27bf114#diff-9df3e6878a0f23383e1f2de991386935e435c5b77c863de75bd67a4ced38591dR136

I'd try running that test / writing one similar to make sure that the view controller is being deleted. If you run that one test and it fails, you'll know you introduced a leak. Otherwise tracking down the timing issue will take a bit more work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out UIKit is keeping some of the input views alive and modifying the content of these views even they're removed from the view hierarchy. #26547

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Code looks good. We just have to fix your tests so you don't call stopMocking.

@chinmaygarde
Copy link
Member

@gaaclarke Looks like you review comments were addressed. Another pass?

@LongCatIsLooong
Copy link
Contributor Author

@chinmaygarde I chose to address a problem in a different PR: #26547. It's currently being reviewed and I think we'll come back to this PR once that problem is fixed.

@LongCatIsLooong LongCatIsLooong force-pushed the ios-floating-cursor-fix branch from 459fd32 to fa1e498 Compare June 4, 2021 05:07
@LongCatIsLooong LongCatIsLooong force-pushed the ios-floating-cursor-fix branch from 2e3485a to 659e74a Compare June 4, 2021 08:33
Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

LGTM!

// not have access to its FlutterTextInputDelegate any more.
- (void)decommision {
- (void)decommission {
Copy link
Member

Choose a reason for hiding this comment

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

😁

@jmagman jmagman mentioned this pull request Oct 19, 2022
8 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] long press to move cursor is moving improperly if content is Chinese/Japanese
4 participants