Skip to content

Add FocusLifecyclePolicy to allow apps to control focus behavior during lifecycle changes #185311

Closed

Description

@frank-weindel

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

Activity

  1. frank-weindel commented on Apr 20, 2026

    @frank-weindel
    ContributorAuthor

    I have a PR for this feature but I am still working on getting the contribution approved by my company.

  2. added
    in triage
    on Apr 21, 2026
  3. saurabh-mirajkar commented on Apr 21, 2026

    @saurabh-mirajkar
    Contributor

    @frank-weindel Thanks for the proposal. Routing this to team-framework for further evaluation.

  4. added
    framework
    c: proposal
    f: focus
    team-framework
    and removed
    in triage
    on Apr 21, 2026
  5. added
    a: tv
    on Apr 21, 2026
  6. added
    P2
    triaged-framework
    on Apr 28, 2026
  7. added 4 commits that reference this issue on Aug 5, 2026
    8174267
    ba0a2cf
    d7eca09
    1abbfb3
  8. frank-weindel commented on Aug 5, 2026

    @frank-weindel
    ContributorAuthor

    @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. suspend is now suspendAndRestore, and persist is now preserve.

  9. added a commit that references this issue on Sep 17, 2026
    5d4b84f
  10. added a commit that references this issue on Sep 24, 2026
    91e554d
  11. added a commit that references this issue on Oct 3, 2026
    07fe4ec
  12. added a commit that references this issue on Oct 15, 2026
    5323742
  13. added a commit that references this issue on Oct 28, 2026
    13c5718
  14. added a commit that references this issue on Nov 2, 2026
    a25cb72
  15. added a commit that references this issue on Nov 18, 2026
    7f49251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: tvc: proposalf: focusframeworkteam-frameworktriaged-framework

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions