Are there other ways to cause recompositions other...
# compose-android
l
Are there other ways to cause recompositions other than changing UI state backed by
State
?
z
Yes, to name a few: • your caller is recomposed and passes you some new values • a static composition local is changed • I think maybe if you’re in a movableContent and moved? Not sure though But compose doesn’t make any guarantees about all the reasons a recomposition could happen, so even if you had an exhaustive list of reasons right now, it could change in the future.
l
Thank you for your response! I want to keep trying to poke holes in this. • In a purely compose world, the caller would be recomposed only when
State
changes too, right? • the static composition local would only be altered in a composition or recomposition, right? Which means in a purely compose world,
State
would have to change too, right? But
State
might change way up in the UI hierarchy and therefore the updated static composition local would really be the cause of the recompositions in the child composables. • does moving
movableContent
change some
State
? I didn’t look too far into the implementation.
z
Oh I misread your question, I thought you meant a state read by the composable in question. I guess technically all changes happen due to a snapshot state change somewhere? I think even when you call setContent on a ComposeView it just updates a state object.
🙌 1
Ok this is maybe one: the size of the host view could change based on some external trigger, and then some layout inside the composition could choose to subcompose something else based on this new constraints
l
whooooaaa.. that is an interesting one. But for all intents and purposes, all changes are due to a snapshot state change somewhere. Very good. I am writing an article and was going to claim that all recompositions can be sourced to some
State
update. It seems like that is mostly true.
z
Don’t quote me on that though. I’d need to comb through the source to verify. And more importantly, it’s not a guarantee made by compose.
l
Right I am just making a general claim about how recompositions occur and discussing how you can minimize them using some simple techniques
Thank you again for you time, Mr. Sir.
s
It is generally true, recomposition is driven by state changes. There are a few notable exceptions like subcompose layout, which Zach outlined above, but 99% of changes are driven by state.
l
Thank you! Love you guys ❤️