-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
01bfbc5
to
2dc92da
Compare
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 Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
7e77bb3
to
a81175b
Compare
a81175b
to
174e9ef
Compare
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? |
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:
|
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. |
@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. |
This change introduces a new property,
forceFramesEnabled
, toSchedulerBinding
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
///
).