Open
Description
The renderings: Flow<Screen>
provided to WorkflowLayout.take()
can fire a lot more often than is useful, especially in large apps that don't use initialState
/ StateFlow.value
effectively. Can take
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.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Make WorkflowLayout throttle itself based on the frame clock[/-][+]Make WorkflowLayout sample based on the frame clock[/+]zach-klippenstein commentedon Jan 24, 2025
That would be the default behavior if
WorkflowLayout
were compose (since it would presumablycollectAsState
orcollectAsStateWithLifecycle
). I think for aView
we could do something like this:Caveat is I'm not sure how this will sync with Compose's frame callback. Compose also does
postFrameCallback
, so it would end up being a race and ifcollectAtFrame
lost then the new renderings wouldn't show in Compose until the next frame, I think.zach-klippenstein commentedon Jan 24, 2025
If we were, we'd still want to only operate on frames 😂
zach-klippenstein commentedon Jan 24, 2025
Actually I think we should probably just make
show
debounce itself until frame boundary, not put the logic intake
.zach-klippenstein commentedon Jan 24, 2025
I haven't thought about nesting. If
show
is called as a result of a parentWorkflowLayout
propagating the renderings down the view tree, then it shouldn't defer ever. (Compose also automatically handles this.) I'm not sure if this is a case we need to explicitly handle for views.Ok so maybe
take
is the right place to put this debouncing. Assuming, IIRC, that when propagating down the view tree we callshow
directly and don't usetake
.rjrjr commentedon Jan 24, 2025
In the few instances where we have nested
WorkflowLayout
it's due to a separate workflow runtime being spun up by a legacy presenter object and feeding it directly. There is no recursion built intoWorkflowLayout
itself; and I can't see a reason for feature code to ever do that beauseWorkflowViewStub
and@Composable WorkflowRendering()
exist and are attractive.rjrjr commentedon Jan 24, 2025
Did you just make an argument for us to get
WorkflowLayout
out of the top of our apps and do this instead? https://github.com/square/workflow-kotlin/blob/main/samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocompose/HelloComposeActivity.kt[-]Make WorkflowLayout sample based on the frame clock[/-][+]RA-64264 Make WorkflowLayout sample based on the frame clock[/+]