I'm experiencing a strange behaviour when using na...
# compose
j
I'm experiencing a strange behaviour when using nav3: I'm passing a function
navigateUp
to a composable which is implemented as
backstack::removeLastOrNull
. This function is being called when a certain state is collected from the
ViewModel
. When the function is called, it causes the composable to re-render twice which removes more screens from the backstack. When I remove the function call and replace it with a
println
it's only printed once. Can someone explain to me why removing a composable from the backstack causes it to rerender without any other state changes? Did someone experience the same?
1
w
Maybe Nav3 is recomposing your screen to prepare for the pop transition? You might be able to pause a debugger at the 2nd composition and see why it's recomposing. Generally if you're consuming a state as an event, you need to reset the state immediately after consuming it to avoid this issue with recollecting.
j
I think I can solve it by calling the function in a
LaunchedEffect
🤔