Archie
07/22/2020, 11:50 AMAdam Powell
07/22/2020, 1:42 PMArchie
07/22/2020, 3:24 PMonDispose { } will be called when the compose function isn’t part of the composition anymore.When is a compose function no longer part of the composition? Is everytime that it content changes? Like in the example in the documentation I cited:
@Composable
fun LifecycleDemo() {
val count = state { 0 }
Column {
Button(onClick = {
count.value++
}) {
Text("Click me")
}
if (count.value < 3) {
onActive { Log.d("Compose", "onactive with value: " + count.value) }
onDispose { Log.d("Compose", "onDispose because value=" + count.value) }
Text("You have clicked the button: " + count.value.toString())
}
}
}
If I understood it correctly, onDispose()
is attached to Column()
and so when count
gets to 3
it needs to "Recompose" (not really sure if thats the correct term) because Text()
is no longer part of it and so onDispose()
will be called? Did I understood it correctly?
If that is the case (in a different and unrelated question) the Column
before the count == 3
and the Column
after the count == 3
are of different instance?
Did I understood it correctly?Adam Powell
07/22/2020, 4:27 PMonActive
and onDispose
are themselves entities in the composition. If the surrounding condition is true, they enter the composition. If the surrounding condition becomes false, they leave the composition.Archie
07/22/2020, 6:58 PM