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

brabo-hi

12/03/2021, 7:33 PM
Hi all, when navigating from what is the difference between
Copy code
navController.navigate("nextPage") {
    popUpTo("currentPage") { inclusive = true }
}

//and 
navController.navigateUp()
navController.navigate("nextPage")
i

Ian Lake

12/04/2021, 2:07 AM
The first does a single atomic event (and popUpTo is a no-op if currentPage isn't on the back stack, which probably doesn't make a difference in your case). The second one does a
navigateUp()
operation first (which is different from
popBackStack()
in cases where you have deep linked into that destination or any other case where you don't have anything before the current destination on the back stack) then does a separate
navigate()
operation after the
navigateUp()
has completed
In the Compose world, the snapshot system tends to paper over the non-atomic nature of the second one (as you'll only get the final state in the next recomposition)
b

brabo-hi

12/06/2021, 5:53 PM
thanks, what is the best practice if i want to close current page and navigate to next page? I am having issue when using (https://github.com/google/accompanist/tree/main/navigation-material) it doesn’t always pop the current page. Which means from next page, when i backclick it still has current page on the stack
i

Ian Lake

12/06/2021, 5:56 PM
Your first code with
popUpTo
is the correct code to be using
b

brabo-hi

12/07/2021, 7:03 PM
thanks @Ian Lake