Skip to content

Take back the reported text input connection when the platform restores focus - #192956

Open
pdenert wants to merge 1 commit into
flutter:masterfrom
pdenert:fix-ios-autofill-157495
Open

pdenert wants to merge 1 commit into
flutter:masterfrom
pdenert:fix-ios-autofill-157495

Conversation

@pdenert

@pdenert pdenert commented Sep 17, 2026 •

Copy link
Copy Markdown

When iOS restores first responder to a text input view whose connection it had reported closed, #191781 now reports that to the framework, and EditableText re-requests focus from TextInputClient.onFocusReceived. The client then attaches a new connection, which carries a new client id.

That is sufficient for #189051, where nothing is delivered during the switch. It is not sufficient for the AutoFill sheets: iOS delivers the text the user picked immediately after restoring first responder, using the client id it already holds. That delivery arrives before a newly attached connection exists, so the client id check in TextInput._handleTextInputInvocation discards it and the field stays empty.

This takes the reported connection back instead of letting a new one attach, so the id the platform is using stays valid and the text is applied. onFocusReceived still returns the same bool #191781 relies on to decide whether to resign the responder.

Framework-only; no engine changes.

Fixes #157495

Verification

Measured on a physical iPhone (iOS 26.5), with a locally built engine, using a minimal repro — a single TextField with keyboardType: TextInputType.emailAddress and autofillHints: [AutofillHints.email]:

Engine / framework Cursor returns Address lands
master (incl. #191781), unmodified yes no
master + this change yes yes

Both runs used the same engine build, so the only variable is this patch.

Instrumented trace of the failing case (swizzled FlutterTextInputView, unpatched framework) — iOS restores first responder and inserts the address 0.5 ms later, under the original client id:

becomeFirstResponder            appState=inactive
insertText: "…@icloud.com"
updateEditingState [1, {text: "…@icloud.com"}]   <- discarded, no current connection

Tests: 2 added in editable_text_test.dart covering the restore path and a restore for a different client id. editable_text_test.dart + text_input_test.dart + autofill_test.dart + autofill_group_test.dart: 608 passing.

Pre-launch Checklist

@google-cla

google-cla Bot commented Sep 17, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems platform-ios iOS applications specifically framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Sep 17, 2026
@pdenert
pdenert force-pushed the fix-ios-autofill-157495 branch 2 times, most recently from d76132b to 4542a58 Compare September 17, 2026 23:06
@pdenert
pdenert marked this pull request as ready for review September 29, 2026 09:20
@pdenert
pdenert requested a review from a team as a code owner September 29, 2026 09:20

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to reopen and restore a closed text input connection when an iOS text input view regains first responder status, preventing text from being discarded when system UI sheets (such as AutoFill) are dismissed. The changes are implemented across the iOS platform code and the Dart framework, accompanied by unit and widget tests. Feedback on the tests identifies a discrepancy in testTheConnectionIsOnlyReopenedOnce where the test logic does not align with its explanatory comment regarding multiple focus acquisitions without an intervening resign.

@LongCatIsLooong

LongCatIsLooong commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Ah for a second I thought this was a duplicate of #191781 but looks like this one allows the system to change the text inside of the input field as soon as the platform text field becomes the first responder (while with #191781 the flutter text field won't receive the text because it has not regained focus so there's no active connection yet, and also it may create a new UITextInput instance for the new connection so the text will be lost?)

@pdenert

pdenert commented Oct 2, 2026

Copy link
Copy Markdown
Author

@LongCatIsLooong yes, this restores the connection instead of creating a new one. I initially tried something like in #191781, but it was not enough to fix this issue

When iOS restores first responder to a text input view whose connection it
had reported closed, flutter#191781 now tells the framework, which re-requests
focus from TextInputClient.onFocusReceived. The client then attaches a new
connection, and that connection carries a new client id.

iOS delivers the text picked from an AutoFill sheet such as "Hide My Email"
immediately after restoring first responder, using the client id it already
holds. That delivery arrives before a newly attached connection exists, so
the client id check in TextInput._handleTextInputInvocation discards it and
the field stays empty.

Take the reported connection back instead of letting a new one attach, so
the id the platform is using stays valid and the text is applied.

Fixes flutter#157495
@pdenert
pdenert force-pushed the fix-ios-autofill-157495 branch from 5de7105 to 328d3a5 Compare October 12, 2026 18:03
@github-actions github-actions Bot removed platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Oct 12, 2026
@pdenert pdenert changed the title [iOS] Take the text input connection back when the platform reopens it Take back the reported text input connection when the platform restores focus Oct 12, 2026
@pdenert

pdenert commented Oct 13, 2026

Copy link
Copy Markdown
Author

@LongCatIsLooong I aligned my solution to the one that was merged in: #191781

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS Autofill "hide my email" does not work

2 participants