kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Refactor: unwrap map graph (#2111)
rodzic
d7bd3ecaa7
commit
46501649c8
|
|
@ -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))
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue