Reading about <Compose Phases>, I’m not sure about...
# compose
a
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
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
Ah, 🤦 makes sense. It will trigger a recomposition if the state is read within the composition scope.