Skip to content

Conversation

@koji-1009
Copy link
Contributor

@koji-1009 koji-1009 commented Aug 12, 2025

fix #145681

I created a PR based on the survey described in comment. The existing processing is not deleted, but the method to be executed is moved. If _autofillContext is not empty, the timing of removing activeView and _inputHider is delayed.

Pre-launch Checklist

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

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions bot added platform-ios iOS applications specifically engine flutter/engine related. See also e: labels. team-ios Owned by iOS platform team labels Aug 12, 2025
Copy link
Contributor

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

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 provides a solid fix for autofill context cleanup and view lifecycle management in the iOS text input plugin. The changes are well-reasoned, moving logic to more appropriate locations to correctly handle the delayed removal of views when an autofill context is active. The introduction of the _pendingInputHiderRemoval flag is a clean way to manage this state. The accompanying tests are thorough, covering the new logic, regressions, and edge cases, which gives confidence in the correctness of the fix. The code quality is high and adheres to the project's existing style.

@koji-1009 koji-1009 force-pushed the fix/autofill_context branch from c1d2fb5 to 05c2779 Compare August 12, 2025 03:39
@koji-1009
Copy link
Contributor Author

Hi @LongCatIsLooong, I've removed removeFromSuperview from hideTextInput. What do you think of this fix?

@koji-1009 koji-1009 marked this pull request as ready for review August 12, 2025 14:09
@koji-1009 koji-1009 requested a review from a team as a code owner August 12, 2025 14:09
@jmagman
Copy link
Member

jmagman commented Aug 14, 2025

Need to make sure this doesn't regress #71885.
cc @chunhtai who worked on this flutter/engine#23776

}

- (void)dealloc {
[_autofillContext removeAllObjects];
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching these! nit: should this just call reset then?

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 changed it to call reset. Thanks for the advice. 5af6987

selector:@selector(enableActiveViewAccessibility)
userInfo:nil
repeats:NO];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm hoping we can just remove these (at least the timer).

Per @chunhtai (if I recall correctly) this is for cases like navigating to a new route with an "autofocus: true" text field. But I think when that happens, the accessibility bridge would have already received the new semantics tree, especially with the current implementation where autofocus is scheduled in a post frame callback and semantics updates are sent synchronously to the accessibility bridge on iOS.

Copy link
Contributor

Choose a reason for hiding this comment

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

@chunhtai do you think this can be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if we're worried about the timing with the semantics tree update, shouldn't accessibility bridge be the one that calls enableActiveViewAccessbility when it's ready, instead of the text input plugin tries to coordinate with the accessibility bridge?

Copy link
Contributor

@chunhtai chunhtai Sep 15, 2025

Choose a reason for hiding this comment

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

The current implementation was five years ago bf551a3.

Where this changed was introduced 4 years ago d2dacb3

I am not sure if this is still needed either though.

if we're worried about the timing with the semantics tree update, shouldn't accessibility bridge be the one that calls enableActiveViewAccessbility.

This is only an issue due to iOS internal implementation that it reuses UItextinput for text editing and a11y tree. From the framework perspective, there is nothing wrong that autofocus the textfield and then sends a11y tree update. The keyboard focus and a11y focus are separated concepts in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is removing this delay necessary for autofill to work?

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong Sep 15, 2025

Choose a reason for hiding this comment

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

Is removing this delay necessary for autofill to work?

I would think not (it's more of a drive-by comment).

From the framework perspective, there is nothing wrong that autofocus the textfield and then sends a11y tree update. The keyboard focus and a11y focus are separated concepts in the first place.

Yeah the framework doesn't have to know about the details of what UIKit / the text input plugin does, but the iOS accessibility bridge is specialized for the iOS implementation, and to me it seems to be the perfect place to determining when to switch between an a11y node and the "real" input field (instead of using a timer in TextInputPlugin). But again I digress.

IIRC the PR moves the switch code from show/hide to setInputClient/clearInputClient, so the timing is a bit different and the app may call show/hide themselves to dismiss / reveal the virtual keyboard. Do you happen to know if that will break anything, or are there things we should test to make sure there's no regression.

Copy link
Contributor

Choose a reason for hiding this comment

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

the iOS accessibility bridge is specialized for the iOS implementation, and to me it seems to be the perfect place to determining when to switch between an a11y node and the "real" input field (instead of using a timer in TextInputPlugin). But again I digress.

Oh I misread the original question, yeah moving this to ios a11ybridge is fine. It just feels a bit weird that a11y needs to listen to textinputplugin activation and then set the attribute on textinputplugin, but I get it makes a bit more sense to structure the code this way

PR moves the switch code from show/hide to setInputClient/clearInputClient, so the timing is a bit different and the app may call show/hide themselves to dismiss / reveal the virtual keyboard. Do you happen to know if that will break anything, or are there things we should test to make sure there's no regression.

I think this is probably fine. to do a manual test just create a push a new route with autofocus textfield in voice over and see if you will see weird focus behavior

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good I'll give that a try.

Copy link
Contributor

Choose a reason for hiding this comment

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

(trying the implementation out now).

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried out the patch and the behavior seems to be exactly the same in my test app:

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
      child: TextButton(
          onPressed: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (context) {
              return Scaffold(
                //appBar: AppBar(title: const Text('My Page')),
                body: Column(
                  children: [
                    TextButton(
                      child: const Text('POP'),
                      onPressed: () {
                        Navigator.pop(context);
                      },
                    ),
                    TextField(
                      autofocus: true,
                    )
                  ],
                ),
              );
            }));
          },
          child: Text('123')),
    ));
  }
}

The only weirdness I observed: when I press the "123" button and wait for the route transition to finish, the accessibility focus indicator (the rectangle with black borders) would sometimes show over an empty area with no interactive UI elements and announce "one hundred and twenty three". I'm seeing that with and without this patch so I guess that's not related.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@LongCatIsLooong
Copy link
Contributor

the google testing failures don't seem related. Syncing to the tip of the tree and retrying.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Oct 20, 2025
Merged via the queue into flutter:master with commit 4ea3451 Oct 20, 2025
184 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2025
@koji-1009
Copy link
Contributor Author

Thank you!

@koji-1009 koji-1009 deleted the fix/autofill_context branch October 20, 2025 06:01
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 20, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 20, 2025
flutter/flutter@891d7d5...2d34167

2025-10-20 [email protected] Cleanup create_updated_flutter_deps.py a bit (flutter/flutter#177162)
2025-10-20 [email protected] Fixed hot reload/restart crashes after closing browser tab on web-server device (flutter/flutter#177026)
2025-10-20 [email protected] Roll Skia from 0a3ace6fde82 to ed4294faecde (2 revisions) (flutter/flutter#177249)
2025-10-20 [email protected] Add DropdownMenu.decorationBuilder (flutter/flutter#176264)
2025-10-20 [email protected] Roll Skia from 05e2f42f533d to 0a3ace6fde82 (1 revision) (flutter/flutter#177242)
2025-10-20 [email protected] Roll Skia from 89abc5393317 to 05e2f42f533d (1 revision) (flutter/flutter#177238)
2025-10-20 [email protected] [ios][engine] Fix autofill context cleanup and view lifecycle management (flutter/flutter#173598)
2025-10-20 [email protected] Fix Image.network not using cache when headers are specified (flutter/flutter#176831)
2025-10-19 [email protected] Roll Dart SDK from a66f334fee2a to 2cd2106f2cef (4 revisions) (flutter/flutter#177190)
2025-10-19 [email protected] Roll Skia from 2d424175a481 to 89abc5393317 (1 revision) (flutter/flutter#177235)
2025-10-19 [email protected] Make sure that a ListTile doesn't crash in 0x0 environment (flutter/flutter#176176)
2025-10-19 [email protected] Make sure that a DropdownButton doesn't crash in 0x0 environment (flutter/flutter#174880)
2025-10-19 [email protected] Roll Skia from 899155871d29 to 2d424175a481 (1 revision) (flutter/flutter#177229)
2025-10-19 [email protected] Roll Skia from b864c56efb66 to 899155871d29 (1 revision) (flutter/flutter#177227)
2025-10-19 [email protected] Roll Fuchsia Linux SDK from M8WT2GMY46e_0fFho... to tKrvmvTOQITL81oOC... (flutter/flutter#177223)
2025-10-19 [email protected] Roll Skia from 0992b560454f to b864c56efb66 (1 revision) (flutter/flutter#177222)
2025-10-18 [email protected] Fix HEIF decoding (flutter/flutter#176860)
2025-10-18 [email protected] Roll Skia from 74df18176924 to 0992b560454f (1 revision) (flutter/flutter#177217)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
…ent (flutter#173598)

fix flutter#145681

I created a PR based on the survey described in
[comment](flutter#145681 (comment)).
The existing processing is not deleted, but the method to be executed is
moved. If `_autofillContext` is not empty, the timing of removing
`activeView` and `_inputHider` is delayed.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

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

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: LongCatIsLooong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-ios iOS applications specifically team-ios Owned by iOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutofillContextAction.cancel in AutofillGroup#onDisposeAction does not work as expected on iPhone.

4 participants