本文章向大家介绍[Jetpack Compose] popUpTo 的一些理解,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
// Pop everything up to the "home" destination off the back stack before
// navigating to the "friendslist" destination
navController.navigate("friendslist") {
popUpTo("home")
}
// Pop everything up to and including the "home" destination off
// the back stack before navigating to the "friendslist" destination
navController.navigate("friendslist") {
popUpTo("home") { inclusive = true }
}
// Navigate to the "search” destination only if we’re not already on
// the "search" destination, avoiding multiple copies on the top of the
// back stack
navController.navigate("search") {
launchSingleTop = true
}
我们来看看第一行注释:
Pop everything up to the "home" destination off the back stack before navigating to the "friendslist" destination
其译文为:在导航到"friendslist"页面之前,把在返回堆栈中所有处于 "home"页面之上的项弹出。
这句话意思就是,当导航到“friendlist”页面时,此时再按返回键,将返回到“home”页面,无论其中我跳转到其他页面多少次,只要最终我停留在“friendlist”页面,那我返回就一定是返回到“home”页面的。
inclusive = true表示,在导航到"friendslist"页面之前,把在返回堆栈中所有处于 "home"页面之上(包括home页面)的项弹出。