Refactor: unwrap map graph (#2111)

pull/2115/head^2
James Rich 2025-06-14 18:12:26 +00:00 zatwierdzone przez GitHub
rodzic d7bd3ecaa7
commit 46501649c8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 23 dodań i 28 usunięć

Wyświetl plik

@ -20,7 +20,6 @@ package com.geeksville.mesh.navigation
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.ui.map.MapView
import kotlinx.serialization.Serializable
@ -28,25 +27,18 @@ import kotlinx.serialization.Serializable
sealed class MapRoutes {
@Serializable
data object Map : Route
@Serializable
data object MapGraph : Graph
}
fun NavGraphBuilder.mapGraph(
navController: NavHostController,
uiViewModel: UIViewModel,
) {
navigation<MapRoutes.MapGraph>(
startDestination = MapRoutes.Map,
) {
composable<MapRoutes.Map> {
MapView(
model = uiViewModel,
navigateToNodeDetails = {
navController.navigate(NodesRoutes.NodeDetail(it))
},
)
}
composable<MapRoutes.Map> {
MapView(
model = uiViewModel,
navigateToNodeDetails = {
navController.navigate(NodesRoutes.NodeDetail(it))
},
)
}
}

Wyświetl plik

@ -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
}
}
}
)