https://kotlinlang.org logo
#compose
Title
# compose
v

Vivek Sharma

11/13/2020, 10:30 AM
I was using compose-navigation with bottom nav, I got a doubt (As docs stated one is
Profile Composable
and other is
FriendList Composable
, using as eg. and below as onClick code
Copy code
onClick = {
              // This is the equivalent to popUpTo the start destination
                 navController.popBackStack(navController.graph.startDestination, false)
                 if (currentRoute != screen.route) {
                            navController.navigate(screen.route)
                 }
          }
) Lets say So startDestination is
Profile
, then we clicked on
FriendList
bottom nav item, and then we clicked Profile, then FriendList When I press back, I never go back to FriendList, though I have visited it twice How does popBackStack works here, popping till Profile and not including Profile
c

Cyril Find

11/13/2020, 10:44 AM
yes
popBackStack(navController.graph.startDestination, false)
pops everything up to profile not including it
it does so every time you navigate so there is never a lot of back stack entries in there
btw with alpha02 there's a new syntax
Copy code
navController.navigate(screen.route) {
                        launchSingleTop = true
                        popUpTo = navController.graph.startDestination
                    }
so you can customize it to your use case
v

Vivek Sharma

11/13/2020, 5:49 PM
@Cyril Find popping upto profile and suppose I have backstack like this : Profile(start) -> Friends -> Profile -> Fragment(at top) so if you pop upto startDestination , how it will work ?
c

Cyril Find

11/13/2020, 5:51 PM
i think it would just pop the last Fragment but the thing is you pop eveytime you navigate
so you just have 1 Profile in your backstack
6 Views