marcinmoskala
11/24/2024, 3:09 PMMutableState
leads to recomposition to all the composable functions that read this state, but I cannot find how exactly that is triggered.
Like in this simple code, clicks only cause "Recompose BodyReading" and "Value: true/false".
@Preview
@Composable
fun Recomposition() {
val value = remember { mutableStateOf(false) }
println("Recompose Recomposition")
Button(onClick = { value.value = !value.value }) {
Text("Click me")
}
BodyReading(value)
BodyWriting(value)
}
@Composable
fun BodyReading(value: MutableState<Boolean>) {
println("Recompose BodyReading")
println("Value: ${value.value}")
Text(" ")
Text(" ")
}
@Composable
fun BodyWriting(value: MutableState<Boolean>) {
println("Recompose BodyNotReading")
value.value = false
Text(" ")
Text(" ")
}
In the compiled code, I do not see any essential differences, except that the first one has additional print and value.getValue()
, while the other one value.setValue(false)
. They both start startRestartGroup
. My assumption is that getValue
sets some listener for recomposition, but I cannot find that, and I would love to understand how that works.Stylianos Gakis
11/24/2024, 3:22 PMmarcinmoskala
11/24/2024, 3:39 PM