Refactor: unwrap map graph (#2111)

This commit is contained in:
James Rich 2025-06-14 18:12:26 +00:00 committed by GitHub
parent d7bd3ecaa7
commit 46501649c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 28 deletions

View file

@ -67,6 +67,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
@ -195,19 +196,21 @@ fun MainScreen(
}
},
onClick = {
navController.navigate(destination.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
// destination.route
// popUpTo(navController.graph.findStartDestination().id) {
// saveState = true
// }
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
if (!isSelected) {
navController.navigate(destination.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
destination.route
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
}
}
)