https://kotlinlang.org logo
#compose
Title
# compose
d

darkmoon_uk

12/10/2021, 12:52 AM
Do folk have any smart ways of discovering what causes a recomposition? My ideal would be some log that says 'Because <name> state changed at <file:line>'? My use case is debugging 'jank' in
AnimatedContent
transitions because multiple recompositions are firing where conceptually there should be only one. Carefully tracing the code for state changes is a given, just wondering if people can share any smart breakpoints/profiling tricks they're employing?
d

Doris Liu

12/10/2021, 1:17 AM
What does the code using
AnimatedContent
looks like? Can you share the code?
d

darkmoon_uk

12/10/2021, 1:35 AM
transitionTo
is my own infix function to determine what kind of transition should be used; either
SlideLeft
or
SlideRight
if the workflow state represents another 'screen', or
None
if the new state represents a state change within the current 'screen'.
d

Doris Liu

12/10/2021, 1:37 AM
Can you try to read the target state passed to the content instead of reading
workFlowState
directly?
d

darkmoon_uk

12/10/2021, 1:38 AM
You mean where I have
with(workflowState)
... and any such usages below that?
d

Doris Liu

12/10/2021, 1:38 AM
yep, try
with (it) ...
d

darkmoon_uk

12/10/2021, 1:39 AM
Ok
It does look better!
Can you say what the underlying difference is?
Presumably this means that calling the collecting property delegate again causes it to reemit for all consumption points in the
@Composable
?
d

Doris Liu

12/10/2021, 1:48 AM
There are multiple sets of content that
AnimatedContent
is transitioning in between, each is associated with a different target state. Each set of the content ideally should only reflect what's defined in their corresponding target state. That would require that the content read the state passed to the content lambda. By reading an external state (i.e. workflowState), all the active content is observing that change, therefore causing unnecessary recomposition
d

darkmoon_uk

12/10/2021, 1:49 AM
Rolled the code back and forward again to compare - this really fixed it, thanks @Doris Liu! 🙏 🎉 Thanks for the explanation too; I've learned something about state handling today 😁
👍 2
Yes, I think I see now, even though it's the same state, reaching across scope to effectively learn the same thing twice caused double composition.