Skip to content

Conversation

@nate-thegrate
Copy link
Contributor

Both iOS and Android run into issues when the FocusManager starts responding to app lifecycle changes.

Fortunately, this feature is primarily meant for desktop platforms, so the problem can be resolved with a platform check.

fixes #148475

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: focus Focus traversal, gaining or losing focus labels May 18, 2024
@nate-thegrate nate-thegrate marked this pull request as ready for review May 18, 2024 16:17
ChangeNotifier.maybeDispatchObjectCreation(this);
}
if (kIsWeb || defaultTargetPlatform != TargetPlatform.android) {
final bool shouldListenToAppLifecycle = switch (defaultTargetPlatform) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Having the focus system automatically handle app lifecycle state changes is convenient in most cases, but what if a UI component wants to respond to app lifecycle events and user-initiated focus changes differently? If we do this automatically in the focus system, there's no way for a component to distinguish user-initiated focus changes and app-lifecycle focus changes.

For example a text field establishes / tears down an input connection based on whether it currently has focus. Automatically unfocusing on app pause doesn't work well. It makes more sense to me that UI components should have logic to handle app lifecycle changes themselves (at least for text fields that's the case).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Setting all UI components (not just text fields) to automatically unfocus/refocus based on app lifecycle state matches the behavior of other non-Flutter apps.

Example (Google Chrome)

chrome focus changes

But the fact that a widget may want to differentiate between app lifecycle events and user-initiated focus changes is a great point.

In my mind, it makes sense to apply the iOS platform check today, and then sometime soon we should swap out the current app lifecycle listener for a more robust implementation that allows for the TextField input connection optimization you mentioned.

@nate-thegrate nate-thegrate added the autosubmit Merge PR when tree becomes green via auto submit App label May 23, 2024
@auto-submit auto-submit bot merged commit 8d955cd into flutter:master May 23, 2024
@jmagman jmagman added the cp: stable cherry pick this pull request to stable release candidate branch label May 23, 2024
flutteractionsbot pushed a commit to flutteractionsbot/flutter that referenced this pull request May 23, 2024
Both iOS and Android run into issues when the FocusManager starts responding to app lifecycle changes.

Fortunately, this feature is primarily meant for desktop platforms, so the problem can be resolved with a platform check.

fixes flutter#148475
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 23, 2024
Renzo-Olivares added a commit that referenced this pull request May 23, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request May 23, 2024
flutter/flutter@73bf206...8d955cd

2024-05-23 [email protected] Update `FocusManager` platform check to include iOS (flutter/flutter#148612)
2024-05-23 [email protected] [iOS] fix hot restart with native assets (flutter/flutter#148752)
2024-05-23 [email protected] Roll Flutter Engine from b8b82454e302 to 964f087f288c (8 revisions) (flutter/flutter#148943)
2024-05-23 [email protected] Fix DecoratedSliver sample code to reflect the description (flutter/flutter#148621)
2024-05-23 [email protected] Test raw autocomplete api examples (flutter/flutter#148234)
2024-05-23 [email protected] Add test for scaffold.0.dart and scaffold.2.dart (flutter/flutter#148166)
2024-05-23 [email protected] Add tests for restorable_value.0.dart API example. (flutter/flutter#148676)
2024-05-23 [email protected] Roll Flutter Engine from 8b094fbb94d8 to b8b82454e302 (6 revisions) (flutter/flutter#148919)
2024-05-22 [email protected] Allow `RenderObject.getTransformTo` to take an arbitrary RenderObject in the same tree (flutter/flutter#148897)
2024-05-22 [email protected] 3.22.1 changelog updates (flutter/flutter#148895)
2024-05-22 [email protected] Add frame number and widget location map service extension (flutter/flutter#148702)
2024-05-22 [email protected] Remove an assert with false positives (flutter/flutter#148795)
2024-05-22 [email protected] Revert "Fix the second TextFormField to trigger onTapOutside" (flutter/flutter#148909)
2024-05-22 [email protected] [wiki migration] Remaining pages under docs/about/ (flutter/flutter#148782)
2024-05-22 [email protected] Roll Flutter Engine from b6971cdf14f8 to 8b094fbb94d8 (3 revisions) (flutter/flutter#148883)
2024-05-22 [email protected] Fix the second TextFormField to trigger onTapOutside (flutter/flutter#148206)
2024-05-22 [email protected] Try removing robolectric from `integration_test` tests (flutter/flutter#148803)
2024-05-22 [email protected] Prevent test folder deletion on running `flutter create --empty` on an existing app project (flutter/flutter#147160)
2024-05-22 [email protected] [wiki migration] Tool team pages (flutter/flutter#148779)
2024-05-22 [email protected] Roll Flutter Engine from c89defa55801 to b6971cdf14f8 (6 revisions) (flutter/flutter#148819)
2024-05-22 [email protected] [native_assets] Add support for link hooks (flutter/flutter#148474)
2024-05-22 [email protected] Roll Packages from ba19b24 to 6525441 (12 revisions) (flutter/flutter#148864)
2024-05-22 [email protected] Update tokens to 4.0.0 (flutter/flutter#148789)
2024-05-22 [email protected] Move Linux web_long_running_tests_2_5 to bringup (flutter/flutter#148854)

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],[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
@polina-c
Copy link
Contributor

FYI: this PR introduced a memory leak

#148985

victorsanni pushed a commit to victorsanni/flutter that referenced this pull request May 31, 2024
Both iOS and Android run into issues when the FocusManager starts responding to app lifecycle changes.

Fortunately, this feature is primarily meant for desktop platforms, so the problem can be resolved with a platform check.

fixes flutter#148475
@nate-thegrate nate-thegrate added the was reverted (optionally) marks a pull request as having been reverted after it was merged label Jul 12, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 6, 2024
@nate-thegrate nate-thegrate removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 12, 2024
@Para123123
Copy link

Flutter 3.32.5 also ran into this issue

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

Labels

cp: stable cherry pick this pull request to stable release candidate branch f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels. was reverted (optionally) marks a pull request as having been reverted after it was merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autofill Hints not populating in text fields on iOS with Flutter 3.22.0

5 participants