Smorg
12/22/2023, 5:07 PMDisposableEffect
and navigation compose, and expect the behaviour as described but got something different. Any pointers to what might be the issue or could it be that my understanding of how disposable effects is meant to work is wrong?
@Composable
fun ReusableDisposableEffect() {
DisposableEffect(Unit) {
println("Effect")
onDispose {
println("Disposed")
}
}
}
fun ScreenA() {
ReusableDisposableEffect()
}
fun ScreenB() {
ReusableDisposableEffect()
}
// action: navigate from ScreenA to ScreenB with navigation compose
// Expected prints:
- Effect
- Disposed
- Effect
// Actual prints:
- Effect
- Effect
- Disposed
Ian Lake
12/22/2023, 5:21 PMSmorg
12/22/2023, 5:48 PMDisposableEffect
still didn’t have the expected behaviour as described above.
// Code snippet A: couldn't disable transition animation with this and as such could not verify transition as the cause of the issue
NavHost(
enterTransition = { EnterTransition.None },
exitTransition = { ExitTransition.None }
)
// Code snippet B: disabled transition animation this way, but DisposableEffect issue remains
NavHost(
enterTransition = {
fadeIn(
initialAlpha = 1F,
animationSpec = tween(durationMillis = 0, delayMillis = 0),
)
},
exitTransition = { fadeOut(animationSpec = tween(durationMillis = 0, delayMillis = 0)) }
)
Smorg
12/22/2023, 7:13 PMEnterTransition.None
and ExitTransition.None
now works, but the original issue persists.Ian Lake
12/22/2023, 7:24 PMIan Lake
12/22/2023, 7:25 PMlifecycle-runtime-compose
2.7 to get that API, currently in rc02 (going stable in January)Smorg
12/22/2023, 9:41 PM