Repository navigation
Enable apps to control focus behavior during app lifecycle changes via FocusLifecyclePolicy - #190570
Conversation
|
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. |
1942c9a to
dd88157
Compare
Fixed. |
4cb5142 to
04cb4fe
Compare
FocusManager App Lifecycle behaviors via new FocusLifecyclePolicy options
FocusManager App Lifecycle behaviors via new FocusLifecyclePolicy optionsFocusLifecyclePolicy
d7a77a6 to
1abbfb3
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces the FocusLifecyclePolicy enum to configure how FocusManager manages primary focus during application lifecycle changes, alongside corresponding updates and tests. The review comments correctly point out syntax errors where leading-dot shorthand was used for enum values in documentation, initialization, and switch expressions, which is unsupported in Dart.
Piinks
left a comment
There was a problem hiding this comment.
Hey @frank-weindel welcome! This looks pretty good. Couple notes below.
cc @chunhtai for 2nd review
4f44c49 to
3aeb4f9
Compare
|
Updated based on feedback and also rebased. Sorry for the delay. I'll be more able to be more active with further feedback from this point on. |
| .suspendAndRestore => true, | ||
| .keepFocused => false, | ||
| }; | ||
| if (shouldListen && _appLifecycleListener == null) { |
There was a problem hiding this comment.
nit: can you add an assert(shouldListen == (_appLifecycleListener != null)) before the if condition so that it won't fail through unexpected situation?
There was a problem hiding this comment.
Do you mean adding it after the if block? I think that makes the most sense here. If so, I've added it.
3aeb4f9 to
fb92c13
Compare
|
Rebased and addressed latest round of comments. |
Piinks
left a comment
There was a problem hiding this comment.
LGTM! I think this may need the formatter run on it to pass CI
|
autosubmit label was removed for flutter/flutter/190570, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
auto label is removed for flutter/flutter/190570, Failed to enqueue flutter/flutter/190570 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
auto label is removed for flutter/flutter/190570, Failed to enqueue flutter/flutter/190570 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected.. |
|
autosubmit label was removed for flutter/flutter/190570, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@2f09f96...06f32f8 2026-11-18 [email protected] Move macOS desktop builds to ThinLTO (flutter/flutter#196804) 2026-11-18 [email protected] Roll Dart SDK from 5ed55b4b2ebc to 753488ede427 (2 revisions) (flutter/flutter#196893) 2026-11-18 [email protected] Roll Packages from 9af69be to dca2e58 (7 revisions) (flutter/flutter#196892) 2026-11-18 [email protected] Roll Skia from 503a380ebecc to 81ee7327e81c (29 revisions) (flutter/flutter#196889) 2026-11-18 [email protected] Roll Dart SDK from 26e38955d9d4 to 5ed55b4b2ebc (4 revisions) (flutter/flutter#196843) 2026-11-18 [email protected] Fix permissions for action updates (flutter/flutter#196791) 2026-11-18 [email protected] iOS: Apply platform view mutators from FlutterPlatformViewLayer (flutter/flutter#196753) 2026-11-18 [email protected] [flutter_tools] Remove ambient Doctor, FeatureFlags, and device getters (flutter/flutter#196572) 2026-11-18 [email protected] Fix RelativeRect.lerp crash when b is null (flutter/flutter#196655) 2026-11-18 [email protected] [web] Harden WebP and GIF header readers against truncated and malformed buffers (flutter/flutter#196075) 2026-11-17 [email protected] Enable apps to control focus behavior during app lifecycle changes via `FocusLifecyclePolicy` (flutter/flutter#190570) 2026-11-17 [email protected] Don't re-run the code freeze check on label changes (flutter/flutter#196745) 2026-11-17 [email protected] Android: Report FlutterView as a text editor while a text input client is attached (flutter/flutter#193074) 2026-11-17 [email protected] Roll Packages from 4c6a7d3 to 9af69be (5 revisions) (flutter/flutter#196812) 2026-11-17 [email protected] [flutter_tools] Handle target VM filesystem errors in DevFS.create (flutter/flutter#196234) 2026-11-17 [email protected] [flutter_tools] Clarify analytics reporting status when on a feature branch (flutter/flutter#194496) 2026-11-17 [email protected] [web] Recover CanvasKit surfaces from WebGL failures without per-frame null crashes (flutter/flutter#196257) 2026-11-17 [email protected] [devicelab] Trigger navigation tap via Flutter Driver in service_extensions_test (flutter/flutter#194456) If this roll has caused a breakage, revert this CL and set the roller to dry run mode 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
Closes #185311
This PR adds
FocusLifecyclePolicy, an enum that controlsFocusManager's behavior across app lifecycle transitions:automatic(default) — matches existing platform-specific behavior: save/restore on desktop/web, preserve-as-is on Android/iOS.suspendAndRestore— always save and clear focus on background, restore on foreground, regardless of platform.preserve— never save/restore; focus state is left as-is across lifecycle transitions, regardless of platform.Flutter developers who would like to control this behavior can set one of these enum values on the new
FocusManager.instance.lifecyclePolicyproperty ideally once at app initialization. The behavior of the defaultautomaticenum value matches the existing behavior prior to this PR so no breaking change is introduced by this PR.See Also #142930 (Original implementation of App Lifecycle triggered focus behaviors)
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot 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.