-
Notifications
You must be signed in to change notification settings - Fork 101
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
RA-64264 Make WorkflowLayout sample based on the frame clock #1257
Comments
That would be the default behavior if suspend fun <T> Flow<T>.collectAtFrame(choreographer: Choreographer, collector: () -> Unit) {
var frameScheduled = false
var mostRecentValue: T? = null
val frameCallback = FrameCallback {
// Not worried about races since everything's on the main thread, otherwise we'd need
// a lock probably.
frameScheduled = false
collector(mostRecentValue)
}
try {
collect { value ->
mostRecentValue = value
if (!frameScheduled) {
frameScheduled = true
// This is a fire-once callback: It automatically gets removed after firing.
choreographer.postFrameCallback(frameCallback)
}
}
} finally {
// Noop if no callback currently posted.
choreographer.removeFrameCallback(frameCallback)
}
} Caveat is I'm not sure how this will sync with Compose's frame callback. Compose also does |
If we were, we'd still want to only operate on frames 😂 |
I haven't thought about nesting. If Ok so maybe |
In the few instances where we have nested |
Did you just make an argument for us to get |
The
renderings: Flow<Screen>
provided toWorkflowLayout.take()
can fire a lot more often than is useful, especially in large apps that don't useinitialState
/StateFlow.value
effectively. Cantake
buffer what it receives, keeping only the latest, and take care to call [show] either once or never for frame clock tick?Remember that it is absolutely fine to drop renderings; each time a new rendering appears it means that the combined workflow state has changed, and the previous ones are now invalid. We're not an animation tool.
The text was updated successfully, but these errors were encountered: