mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 18:47:03 +05:30
android: refactor navigation destinations
This commit is contained in:
parent
45db8e8486
commit
7eddd653c5
2 changed files with 13 additions and 3 deletions
|
@ -0,0 +1,6 @@
|
|||
package dev.msfjarvis.claw.android.ui
|
||||
|
||||
object Destinations {
|
||||
const val Hottest = "hottest"
|
||||
const val Comments = "comments/%s"
|
||||
}
|
|
@ -50,6 +50,7 @@ fun LobstersApp(
|
|||
val scaffoldState = rememberScaffoldState()
|
||||
val listState = rememberLazyListState()
|
||||
val navController = rememberNavController()
|
||||
var currentDestination by remember { mutableStateOf(Destinations.Hottest) }
|
||||
var isFabVisible by remember { mutableStateOf(true) }
|
||||
val nestedScrollConnection = remember {
|
||||
object : NestedScrollConnection {
|
||||
|
@ -74,7 +75,7 @@ fun LobstersApp(
|
|||
}
|
||||
|
||||
override fun viewComments(postId: String) {
|
||||
navController.navigate("comments/$postId")
|
||||
navController.navigate(Destinations.Comments.format(postId))
|
||||
}
|
||||
|
||||
override fun toggleSave(post: SavedPost) {
|
||||
|
@ -82,6 +83,9 @@ fun LobstersApp(
|
|||
}
|
||||
}
|
||||
}
|
||||
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||
currentDestination = destination.route ?: Destinations.Hottest
|
||||
}
|
||||
LobstersTheme(darkTheme = isSystemInDarkTheme()) {
|
||||
ProvideWindowInsets {
|
||||
val useDarkIcons = MaterialTheme.colors.isLight
|
||||
|
@ -98,7 +102,7 @@ fun LobstersApp(
|
|||
topBar = { ClawAppBar(modifier = Modifier.statusBarsPadding()) },
|
||||
floatingActionButton = {
|
||||
ClawFab(
|
||||
isFabVisible = isFabVisible && navController.currentDestination?.route == "hottest",
|
||||
isFabVisible = isFabVisible && currentDestination == "hottest",
|
||||
listState = listState,
|
||||
modifier = Modifier.navigationBarsPadding(),
|
||||
)
|
||||
|
@ -115,7 +119,7 @@ fun LobstersApp(
|
|||
Modifier.nestedScroll(nestedScrollConnection),
|
||||
)
|
||||
}
|
||||
composable("comments/{postId}") { backStackEntry ->
|
||||
composable(Destinations.Comments.format("{postId}")) { backStackEntry ->
|
||||
CommentsPage(
|
||||
postId = requireNotNull(backStackEntry.arguments?.getString("postId")),
|
||||
getDetails = viewModel::getPostComments,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue