mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Refactor: unwrap map graph (#2111)
This commit is contained in:
parent
d7bd3ecaa7
commit
46501649c8
2 changed files with 23 additions and 28 deletions
|
|
@ -20,7 +20,6 @@ package com.geeksville.mesh.navigation
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import com.geeksville.mesh.model.UIViewModel
|
import com.geeksville.mesh.model.UIViewModel
|
||||||
import com.geeksville.mesh.ui.map.MapView
|
import com.geeksville.mesh.ui.map.MapView
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
@ -28,25 +27,18 @@ import kotlinx.serialization.Serializable
|
||||||
sealed class MapRoutes {
|
sealed class MapRoutes {
|
||||||
@Serializable
|
@Serializable
|
||||||
data object Map : Route
|
data object Map : Route
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data object MapGraph : Graph
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.mapGraph(
|
fun NavGraphBuilder.mapGraph(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
uiViewModel: UIViewModel,
|
uiViewModel: UIViewModel,
|
||||||
) {
|
) {
|
||||||
navigation<MapRoutes.MapGraph>(
|
composable<MapRoutes.Map> {
|
||||||
startDestination = MapRoutes.Map,
|
MapView(
|
||||||
) {
|
model = uiViewModel,
|
||||||
composable<MapRoutes.Map> {
|
navigateToNodeDetails = {
|
||||||
MapView(
|
navController.navigate(NodesRoutes.NodeDetail(it))
|
||||||
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
|
||||||
import androidx.navigation.NavDestination.Companion.hasRoute
|
import androidx.navigation.NavDestination.Companion.hasRoute
|
||||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||||
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
|
@ -195,19 +196,21 @@ fun MainScreen(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
navController.navigate(destination.route) {
|
if (!isSelected) {
|
||||||
// Pop up to the start destination of the graph to
|
navController.navigate(destination.route) {
|
||||||
// avoid building up a large stack of destinations
|
// Pop up to the start destination of the graph to
|
||||||
// on the back stack as users select items
|
// avoid building up a large stack of destinations
|
||||||
// destination.route
|
// on the back stack as users select items
|
||||||
// popUpTo(navController.graph.findStartDestination().id) {
|
destination.route
|
||||||
// saveState = true
|
popUpTo(navController.graph.findStartDestination().id) {
|
||||||
// }
|
saveState = true
|
||||||
// Avoid multiple copies of the same destination when
|
}
|
||||||
// reselecting the same item
|
// Avoid multiple copies of the same destination when
|
||||||
launchSingleTop = true
|
// reselecting the same item
|
||||||
// Restore state when reselecting a previously selected item
|
launchSingleTop = true
|
||||||
restoreState = true
|
// Restore state when reselecting a previously selected item
|
||||||
|
restoreState = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue