Repository navigation
Description
Use case
The current FocusManager behavior during app lifecycle transitions (foreground/background) is hardcoded per platform: on desktop and web, the primary focus is stashed and then set to the Root focus node when the app loses system foreground focus and then restored when system focus is regained, while on Android and iOS this behavior is disabled due to known issues with keyboard and autofill interactions.
There is no way for an application to override this per-platform default. This is a problem for apps that need different behavior than what the platform default provides. For example:
- Embedded/TV platforms (e.g. RDK): Flutter apps running on TV platforms like RDK could benefit from focus persisting through lifecycle transitions when switching between foreground apps. The default desktop behavior of clearing and restoring focus is often disruptive in this context and can cause unnecessary engineering complications and bugs.
- Mobile apps that want to opt in to focus save/restore, for whatever reason, despite it being disabled by default on Android/iOS.
- Desktop/web apps that want to opt out of the save/restore behavior entirely. For example, a development team I'm on uses a MacOS build of a TV app that uses d-pad navigation for quicker development. We often activate floating window mode to keep the app's window on top of all other windows. Without this feature, focusing in and out of the app's window is always jarring due to focus resetting to the root, and then back to the preserved element when the window regains focus.
Proposal
Add a FocusLifecyclePolicy enum and a corresponding FocusManager.lifecyclePolicy property that allows apps to choose between three behaviors:
automatic(default): The current platform-dependent behavior. No change for existing apps.suspendAndRestore: Always save focus on background and restore on resume, regardless of platform. Enables save/restore on mobile platforms where it's currently disabled.keepFocused: Never modify focus during lifecycle changes, regardless of platform. Focus remains on whatever node has it when the app transitions to the background.
Usage:
FocusManager.instance.lifecyclePolicy = .keepFocused;This is a non-breaking change — the default automatic policy preserves existing behavior on all platforms.
See Also
- Have
FocusManagerrespond to app lifecycle state changes #142930- Original implementation of App Lifecycle triggered focus behaviors
Activity
frank-weindel commentedon Apr 20, 2026
I have a PR for this feature but I am still working on getting the contribution approved by my company.
saurabh-mirajkar commentedon Apr 21, 2026
@frank-weindel Thanks for the proposal. Routing this to
team-frameworkfor further evaluation.Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
frank-weindel commentedon Aug 5, 2026
@saurabh-mirajkar I've now been approved, CLA is signed, and have submitted a PR that is ready for review. I've decided to update the naming design of the policies to be more clear and less ambiguous.
suspendis nowsuspendAndRestore, andpersistis nowpreserve.Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…
Enable apps to control focus behavior during app lifecycle changes vi…