因此,在我的撰写应用程序中,我设置了多个带有一个嵌套导航的屏幕,如下所示:
composable(
route = RackInspectionScreen.RackInspectionObservationsRecommendationsScreen.route
){
RackInspectionObservationsRecommendationsScreen(navController = navController)
}
// Nested Navigation Graph
navigation(
startDestination = RackInspectionScreen.RackInspectionDamageReportAreaScreen.route,
route = "rack_inspection_damage_report_route"
) {
composable(
route = RackInspectionScreen.RackInspectionDamageReportAreaScreen.route
){
RackInspectionDamageReportAreaScreen(navController = navController)
}
composable(
route = RackInspectionScreen.RackInspectionDamageReportRunScreen.route
){
RackInspectionDamageReportRunScreen(navController = navController)
} //MORE SCREENS...
}
composable(
route = RackInspectionScreen.RackInspectionAppendix1RackInspectionProceduresScreen.route
){
RackInspectionAppendix1RackInspectionProceduresScreen(navController = navController)
}
composable(
route = RackInspectionScreen.RackInspectionAppendix2DamageAssessmentGuidelinesScreen.route
){
RackInspectionAppendix2DamageAssessmentGuidelinesScreen(navController = navController)
} //MORE SCREENS...
我有一个 NavigationDrawer,当单击导航项时,用户可以在屏幕之间导航:
navigationItems.forEachIndexed { index, navigationItem ->
NavigationDrawerItem(
modifier = modifier
.padding(NavigationDrawerItemDefaults.ItemPadding),
label = { Text(text = navigationItem.title) },
selected = index == selectedItemIndex,
onClick = {
selectedItemIndex = index
scope.launch {
drawerState.close()
}
Log.d(TAG, navigationItem.route)
navHostController.navigate(route = navigationItem.route ){
// THIS DOSEN'T WORK:
// popUpTo(navigationItem.route){
// inclusive = true
// }
}
})
我想要的行为是最大限度地减少返回堆栈中的重复,最重要的是,返回到嵌套导航中的上一个位置。因此,每个“外部屏幕”在后台堆栈中只有一个实例,并且在后台堆栈中只有一个“嵌套屏幕”实例..
这个视频也许有助于解释这个问题:Android 上的多个 Backstacks(我的经验)- 与 Mitch 一起编码