Having some trouble using compose navigation with ...
# compose
s
Having some trouble using compose navigation with multiple bottom navbar backstack support. Details in Thread đź§µ
So I am using this part as the official docs suggest in my BottomNavigationItem onClick()
Copy code
onClick = {
    currentNavController.navigate(item.screen.route) {
        popUpTo(currentNavController.graph.findStartDestination().id) {
            saveState = true
        }
        launchSingleTop = true
        restoreState = true
    }
}
However at the same time, I am using this
Copy code
composable(...) { from: NavBackStackEntry ->
    SomeComposable(
        goBack = {
            if (from.lifecycleIsResumed()) {
                navController.popBackStack()
            }
        }
    )
}
coming from the official jetsnack samples because otherwise I have the problem of triggering navigation multiple times if the user spam clicks. For example on the second destination of the bottom nav, on a detail screen, if the user spam clicks the button that does
navController.popBackStack()
it then sometimes pops all the way to the other bottom destination, which is not what I would expect. But with the combination of the two, I get in this state where if I am on that composable, and I click the currently selected bottom navigation item again, then the
goBack()
function just does nothing, it seems like the
from: NavBackStackEntry
is never reaches the
RESUMED
state, since when I remove the
from.lifecycleIsResumed()
check it works again. What a I missing here, is this workaround just not how I should “buffer” the user clicking like a maniac? Sorry if pinging is discouraged (Please do let me know if so, I won’t do it again), but I do think that if anyone definitely has an answer to this, it’s you @Ian Lake
i
I'd first try out a snapshot build (there's been a number of important fixes since alpha07 specifically in this area) by following the directions on https://androidx.dev/
s
Just tried with the latest build
7689780
and with
androidx.navigation:navigation-compose:2.4.0-SNAPSHOT
and I this behaviour is still happening. So do you confirm that this is a non-expected behaviour and that I am probably not messing up somewhere else? I hope that I explained what I am doing and what goes wrong in my question above.
Oh and if it matters, going back normally using the Android “go back” gesture works perfectly fine even when what I explained before breaks.
i
You should file a bug if your destination doesn't settle back into the
RESUMED
state after its animation finishes. That should always be the case
s
Alright, if I get some time later this week I will try to get a small project that reproduces this and submit the bug. Thank you for the help.