mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 17:37:05 +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 scaffoldState = rememberScaffoldState()
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
|
var currentDestination by remember { mutableStateOf(Destinations.Hottest) }
|
||||||
var isFabVisible by remember { mutableStateOf(true) }
|
var isFabVisible by remember { mutableStateOf(true) }
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
|
@ -74,7 +75,7 @@ fun LobstersApp(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun viewComments(postId: String) {
|
override fun viewComments(postId: String) {
|
||||||
navController.navigate("comments/$postId")
|
navController.navigate(Destinations.Comments.format(postId))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toggleSave(post: SavedPost) {
|
override fun toggleSave(post: SavedPost) {
|
||||||
|
@ -82,6 +83,9 @@ fun LobstersApp(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||||
|
currentDestination = destination.route ?: Destinations.Hottest
|
||||||
|
}
|
||||||
LobstersTheme(darkTheme = isSystemInDarkTheme()) {
|
LobstersTheme(darkTheme = isSystemInDarkTheme()) {
|
||||||
ProvideWindowInsets {
|
ProvideWindowInsets {
|
||||||
val useDarkIcons = MaterialTheme.colors.isLight
|
val useDarkIcons = MaterialTheme.colors.isLight
|
||||||
|
@ -98,7 +102,7 @@ fun LobstersApp(
|
||||||
topBar = { ClawAppBar(modifier = Modifier.statusBarsPadding()) },
|
topBar = { ClawAppBar(modifier = Modifier.statusBarsPadding()) },
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
ClawFab(
|
ClawFab(
|
||||||
isFabVisible = isFabVisible && navController.currentDestination?.route == "hottest",
|
isFabVisible = isFabVisible && currentDestination == "hottest",
|
||||||
listState = listState,
|
listState = listState,
|
||||||
modifier = Modifier.navigationBarsPadding(),
|
modifier = Modifier.navigationBarsPadding(),
|
||||||
)
|
)
|
||||||
|
@ -115,7 +119,7 @@ fun LobstersApp(
|
||||||
Modifier.nestedScroll(nestedScrollConnection),
|
Modifier.nestedScroll(nestedScrollConnection),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable("comments/{postId}") { backStackEntry ->
|
composable(Destinations.Comments.format("{postId}")) { backStackEntry ->
|
||||||
CommentsPage(
|
CommentsPage(
|
||||||
postId = requireNotNull(backStackEntry.arguments?.getString("postId")),
|
postId = requireNotNull(backStackEntry.arguments?.getString("postId")),
|
||||||
getDetails = viewModel::getPostComments,
|
getDetails = viewModel::getPostComments,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue