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

allan.conda

07/26/2022, 7:31 AM
Reading about Compose Phases, I’m not sure about one thing. How does Scrollable list states avoid causing a recomposition (just remeasure/redraw)? I’m reading the source and saw a lot of mutableStates to track the scroll state, which should trigger recomposition in my understanding. But it seems to just call
remeasure
instead. Is there an optimization happening somewhere for scrolling?
a

Albert Chang

07/26/2022, 9:09 AM
When you read the value of a snapshot state during one of the phases listed above, Compose automatically tracks what it was doing when the value was read.
As stated in the guide, a state doesn’t necessarily cause recomposition. If it’s only read in a layout scope, it’ll only trigger re-layout. Same for draw scope. If you are talking about lazy list, it’s actually irrelevant here because it doesn’t use states to trigger recomposition or re-layout.
a

allan.conda

07/26/2022, 9:55 AM
Ah, 🤦 makes sense. It will trigger a recomposition if the state is read within the composition scope.
3 Views