Skip to content

[SchedulerBinding] Add forceFramesEnabled to allow rendering when app is hidden or paused #173862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tguerin
Copy link

@tguerin tguerin commented Aug 15, 2025

This change introduces a new property, forceFramesEnabled, to SchedulerBinding that allows applications to continue rendering frames even when the app is in a hidden or paused state.

Some desktop applications, such as games or apps with animation-driven audio (e.g., Rive) rely on continuous frame rendering to maintain smooth animation timing and audio playback.
The current lifecycle behavior stops scheduling frames when the app is hidden or paused (e.g., mission control on MacOS), which can interrupt these use cases.

Without this addition, we have to use a workaround to achieve the same goal by tweaking the lifecycle of the app which is not ideal.

In the documentation I’ve added a warn regarding performance impact, however I could recommend to not use this property on mobile.

This change could help fix #133533.

Pre-launch Checklist

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

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Aug 15, 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 introduces forceFramesEnabled to SchedulerBinding, allowing apps to continue rendering when hidden or paused. The implementation is clear, well-documented, and includes a comprehensive set of tests. The logic for enabling/disabling frames and scheduling a new frame when needed appears correct.

I've found a small improvement opportunity in the new tests to ensure better test isolation by using the corresponding change that resets the _rootElement. Additionally, the change to WidgetsBinding.resetInternalState is not mentioned in the PR description, which would be good to add for clarity.

Overall, this is a great addition that addresses a valid use case.

@tguerin tguerin force-pushed the allow_rendering_when_hidden branch 5 times, most recently from 01bfbc5 to 2dc92da Compare August 15, 2025 21:39
@tguerin tguerin marked this pull request as draft August 15, 2025 21:42
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@tguerin tguerin force-pushed the allow_rendering_when_hidden branch 4 times, most recently from 7e77bb3 to a81175b Compare August 16, 2025 07:40
@tguerin tguerin marked this pull request as ready for review August 16, 2025 08:02
@tguerin tguerin force-pushed the allow_rendering_when_hidden branch from a81175b to 174e9ef Compare August 16, 2025 08:12
@justinmc
Copy link
Contributor

We should make sure we are very certain that we want to support this use case before we add something like this due to the ability to shoot yourself in the foot here. @loic-sharma do you know if this is a valid concern for multiwindow/desktop apps?

@loic-sharma
Copy link
Member

@loic-sharma do you know if this is a valid concern for multiwindow/desktop apps?

I don't know, however, I suspect that there's a better fix for #133533.

@chinmaygarde Would you have any thoughts on this change for this use case:

Some desktop applications, such as games or apps with animation-driven audio (e.g., Rive) rely on continuous frame rendering to maintain smooth animation timing and audio playback.
The current lifecycle behavior stops scheduling frames when the app is hidden or paused (e.g., mission control on MacOS), which can interrupt these use cases.

@tguerin
Copy link
Author

tguerin commented Aug 20, 2025

The fix was not originally made for this specific issue, but to address a problem we’re facing in our app. We are building a Desktop game, and when the window is completely covered, frame rendering stops, which prevents our animations from running.

To work around this, we currently have to intercept the hidden state and replace it with inactive, which is really hacky. The key requirement for us is to keep animations running even when the window is not visible.

I’m open to different approaches to achieve this, as long as we can meet that requirement.

@dkwingsmt
Copy link
Contributor

dkwingsmt commented Aug 22, 2025

@tguerin Can you explain why you'd like the animation to keep running at background? What is broken by missing these animation frames? It would be great if you can open a new issue for this so we can discuss it and track it more clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[macOS] After creating a new window, the secondary window may not respond properly after switching to a different app and returning to the window
4 participants