Nuru Nabiyev
08/03/2023, 9:03 PMPablichjenkov
08/03/2023, 9:33 PMArkadii Ivanov
08/03/2023, 9:36 PMArkadii Ivanov
08/03/2023, 9:36 PMPablichjenkov
08/03/2023, 9:36 PMArkadii Ivanov
08/04/2023, 5:37 AMAlexander Maryanovsky
08/04/2023, 8:37 AMAlexander Maryanovsky
08/04/2023, 8:40 AMAlexander Maryanovsky
08/04/2023, 8:42 AMDensity
that I think has been already fixed, where the values change, but the object stays the same, so there’s no recomposition.Nuru Nabiyev
08/04/2023, 8:45 PMwindow
object but it did not work. Indeed DisposableEffect is called when old onDispose was not executedNuru Nabiyev
08/04/2023, 8:47 PMrememberCoroutinescope
keeps executingNuru Nabiyev
08/04/2023, 8:49 PMAlexander Maryanovsky
08/04/2023, 9:28 PMNuru Nabiyev
08/05/2023, 11:10 AMval myflow = flow {
repeat(100) {
delay(1000)
println("emitting $it")
emit(it)
}
}
@Composable
fun TestDispose() {
Box {
val scope = rememberCoroutineScope()
scope.launch {
println("scope started")
myflow.collectLatest {
println("collecting $it")
}
}
}
}
then the scope.launch block will be executed again once I move from a screen to another. So Box is instantiated, but scope is not remembered apparently? But if I put that block into Disposable then everything works (as should be), and Disposable is not started again but also onDispose is not executed either. Which is also weird because if Box is re-instantiated, then why old Disposable is working as it is in a new box?Alexander Maryanovsky
08/05/2023, 11:20 AMscope.launch
will be executed on every (re)composition.Alexander Maryanovsky
08/05/2023, 11:20 AMAlexander Maryanovsky
08/05/2023, 11:21 AMonDispose
is not meant to be called on every recomposition; only when the composition of the current function goes awayNuru Nabiyev
08/05/2023, 11:21 AMNuru Nabiyev
08/05/2023, 11:22 AMNuru Nabiyev
08/05/2023, 11:22 AMcomposition of the current function goes away
?Nuru Nabiyev
08/05/2023, 11:22 AMAlexander Maryanovsky
08/05/2023, 11:25 AMNuru Nabiyev
08/05/2023, 11:26 AMAlexander Maryanovsky
08/05/2023, 11:27 AMUnit
key there’s no reason for onDispose to be called. It will only be called when the function is no longer part of the composition:
@Composable
fun MyScreen() {
var showWidget by remember { mutableStateOf(true) }
if (showWidget)
MyWidget()
Button(
onClick = { showWidget = false },
) {
Text("Hide Widget")
}
}
@Composable
fun MyWidget() {
DisposableEffect(Unit) {
onDispose {
println("onDispose")
}
}
}
Nuru Nabiyev
08/05/2023, 11:28 AMNuru Nabiyev
08/05/2023, 11:28 AMAlexander Maryanovsky
08/05/2023, 11:28 AMAlexander Maryanovsky
08/05/2023, 11:29 AM