mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 10:37:05 +05:30
android: migrate away from Accompanist Insets
This commit is contained in:
parent
edd537b351
commit
9f7a5446f8
3 changed files with 102 additions and 109 deletions
|
@ -55,7 +55,6 @@ dependencies {
|
||||||
implementation(projects.common)
|
implementation(projects.common)
|
||||||
implementation(projects.database)
|
implementation(projects.database)
|
||||||
implementation(compose.material3)
|
implementation(compose.material3)
|
||||||
implementation(libs.accompanist.insets)
|
|
||||||
implementation(libs.accompanist.swiperefresh)
|
implementation(libs.accompanist.swiperefresh)
|
||||||
implementation(libs.accompanist.sysuicontroller)
|
implementation(libs.accompanist.sysuicontroller)
|
||||||
implementation(libs.androidx.activity.compose)
|
implementation(libs.androidx.activity.compose)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.msfjarvis.claw.android.ui
|
package dev.msfjarvis.claw.android.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
@ -31,9 +32,6 @@ import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.navArgument
|
import androidx.navigation.navArgument
|
||||||
import androidx.navigation.navDeepLink
|
import androidx.navigation.navDeepLink
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
import com.google.accompanist.insets.ProvideWindowInsets
|
|
||||||
import com.google.accompanist.insets.navigationBarsPadding
|
|
||||||
import com.google.accompanist.insets.statusBarsPadding
|
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||||
import dev.msfjarvis.claw.android.R
|
import dev.msfjarvis.claw.android.R
|
||||||
import dev.msfjarvis.claw.android.ui.decorations.ClawAppBar
|
import dev.msfjarvis.claw.android.ui.decorations.ClawAppBar
|
||||||
|
@ -76,115 +74,112 @@ fun LobstersApp(
|
||||||
LocalHTMLConverter provides htmlConverter,
|
LocalHTMLConverter provides htmlConverter,
|
||||||
colorScheme = decideColorScheme(LocalContext.current),
|
colorScheme = decideColorScheme(LocalContext.current),
|
||||||
) {
|
) {
|
||||||
ProvideWindowInsets {
|
val currentUiMode = LocalConfiguration.current.uiMode
|
||||||
val currentUiMode = LocalConfiguration.current.uiMode
|
val systemBarsColor = MaterialTheme.colorScheme.surfaceColorAtNavigationBarElevation()
|
||||||
val systemBarsColor = MaterialTheme.colorScheme.surfaceColorAtNavigationBarElevation()
|
val backgroundColor = MaterialTheme.colorScheme.background
|
||||||
val backgroundColor = MaterialTheme.colorScheme.background
|
val navItems =
|
||||||
val navItems =
|
listOf(
|
||||||
listOf(
|
NavigationItem(
|
||||||
NavigationItem(
|
label = "Hottest",
|
||||||
label = "Hottest",
|
route = Destinations.Hottest.getRoute(),
|
||||||
route = Destinations.Hottest.getRoute(),
|
icon = painterResource(R.drawable.ic_whatshot_24dp),
|
||||||
icon = painterResource(R.drawable.ic_whatshot_24dp),
|
) { coroutineScope.launch { networkListState.animateScrollToItem(index = 0) } },
|
||||||
) { coroutineScope.launch { networkListState.animateScrollToItem(index = 0) } },
|
NavigationItem(
|
||||||
NavigationItem(
|
label = "Saved",
|
||||||
label = "Saved",
|
route = Destinations.Saved.getRoute(),
|
||||||
route = Destinations.Saved.getRoute(),
|
icon = painterResource(commonR.drawable.ic_favorite_24dp),
|
||||||
icon = painterResource(commonR.drawable.ic_favorite_24dp),
|
) { coroutineScope.launch { savedListState.animateScrollToItem(index = 0) } },
|
||||||
) { coroutineScope.launch { savedListState.animateScrollToItem(index = 0) } },
|
)
|
||||||
)
|
|
||||||
|
|
||||||
SideEffect { systemUiController.setStatusBarColor(color = systemBarsColor) }
|
SideEffect { systemUiController.setStatusBarColor(color = systemBarsColor) }
|
||||||
|
|
||||||
// Track UI mode as a key to force a navbar color update when dark theme is toggled
|
// Track UI mode as a key to force a navbar color update when dark theme is toggled
|
||||||
LaunchedEffect(currentDestination, currentUiMode) {
|
LaunchedEffect(currentDestination, currentUiMode) {
|
||||||
val color =
|
val color =
|
||||||
if (navItems.none { item -> item.route == currentDestination }) {
|
if (navItems.none { item -> item.route == currentDestination }) {
|
||||||
backgroundColor
|
backgroundColor
|
||||||
} else {
|
} else {
|
||||||
systemBarsColor
|
systemBarsColor
|
||||||
}
|
}
|
||||||
systemUiController.setNavigationBarColor(color = color)
|
systemUiController.setNavigationBarColor(color = color)
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
ClawAppBar(
|
ClawAppBar(
|
||||||
modifier = Modifier.statusBarsPadding(),
|
backgroundColor = systemBarsColor,
|
||||||
backgroundColor = systemBarsColor,
|
navigationIcon = {
|
||||||
navigationIcon = {
|
if (navItems.none { it.route == currentDestination }) {
|
||||||
if (navItems.none { it.route == currentDestination }) {
|
IconButton(onClick = { navController.popBackStack() }) {
|
||||||
IconButton(onClick = { navController.popBackStack() }) {
|
Icon(
|
||||||
Icon(
|
imageVector = Icons.Filled.ArrowBack,
|
||||||
imageVector = Icons.Filled.ArrowBack,
|
contentDescription = "Go back to previous screen",
|
||||||
contentDescription = "Go back to previous screen",
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title = {
|
|
||||||
if (navItems.any { it.route == currentDestination }) {
|
|
||||||
Text(text = stringResource(commonR.string.app_name), fontWeight = FontWeight.Bold)
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
)
|
},
|
||||||
},
|
title = {
|
||||||
bottomBar = {
|
if (navItems.any { it.route == currentDestination }) {
|
||||||
ClawNavigationBar(
|
Text(text = stringResource(commonR.string.app_name), fontWeight = FontWeight.Bold)
|
||||||
navController = navController,
|
}
|
||||||
items = navItems,
|
},
|
||||||
isVisible = navItems.any { it.route == currentDestination },
|
)
|
||||||
)
|
},
|
||||||
},
|
bottomBar = {
|
||||||
) { paddingValues ->
|
ClawNavigationBar(
|
||||||
NavHost(
|
navController = navController,
|
||||||
navController,
|
items = navItems,
|
||||||
startDestination = Destinations.startDestination.getRoute(),
|
isVisible = navItems.any { it.route == currentDestination },
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) { paddingValues ->
|
||||||
|
NavHost(
|
||||||
|
navController,
|
||||||
|
startDestination = Destinations.startDestination.getRoute(),
|
||||||
|
) {
|
||||||
|
val uri = LobstersApi.BASE_URL
|
||||||
|
composable(
|
||||||
|
route = Destinations.Hottest.getRoute(),
|
||||||
|
deepLinks =
|
||||||
|
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
|
||||||
) {
|
) {
|
||||||
val uri = LobstersApi.BASE_URL
|
setWebUri("https://lobste.rs/")
|
||||||
composable(
|
HottestPosts(
|
||||||
route = Destinations.Hottest.getRoute(),
|
items = networkPosts,
|
||||||
deepLinks =
|
listState = networkListState,
|
||||||
listOf(navDeepLink { uriPattern = uri }, navDeepLink { uriPattern = "$uri/" }),
|
isPostSaved = viewModel::isPostSaved,
|
||||||
) {
|
reloadPosts = viewModel::reloadPosts,
|
||||||
setWebUri("https://lobste.rs/")
|
postActions = postActions,
|
||||||
HottestPosts(
|
modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()),
|
||||||
items = networkPosts,
|
)
|
||||||
listState = networkListState,
|
}
|
||||||
isPostSaved = viewModel::isPostSaved,
|
composable(Destinations.Saved.getRoute()) {
|
||||||
reloadPosts = viewModel::reloadPosts,
|
setWebUri(null)
|
||||||
postActions = postActions,
|
DatabasePosts(
|
||||||
modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()),
|
items = savedPosts,
|
||||||
)
|
listState = savedListState,
|
||||||
}
|
isSaved = viewModel::isPostSaved,
|
||||||
composable(Destinations.Saved.getRoute()) {
|
postActions = postActions,
|
||||||
setWebUri(null)
|
modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()),
|
||||||
DatabasePosts(
|
)
|
||||||
items = savedPosts,
|
}
|
||||||
listState = savedListState,
|
composable(
|
||||||
isSaved = viewModel::isPostSaved,
|
route = Destinations.Comments.getRoute("{postId}"),
|
||||||
postActions = postActions,
|
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
||||||
modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()),
|
deepLinks =
|
||||||
)
|
listOf(
|
||||||
}
|
navDeepLink { uriPattern = "$uri/s/{postId}/.*" },
|
||||||
composable(
|
navDeepLink { uriPattern = "$uri/s/{postId}" },
|
||||||
route = Destinations.Comments.getRoute("{postId}"),
|
),
|
||||||
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
) { backStackEntry ->
|
||||||
deepLinks =
|
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
|
||||||
listOf(
|
setWebUri("https://lobste.rs/s/$postId")
|
||||||
navDeepLink { uriPattern = "$uri/s/{postId}/.*" },
|
CommentsPage(
|
||||||
navDeepLink { uriPattern = "$uri/s/{postId}" },
|
postId = postId,
|
||||||
),
|
getDetails = viewModel::getPostComments,
|
||||||
) { backStackEntry ->
|
modifier = Modifier.navigationBarsPadding(),
|
||||||
val postId = requireNotNull(backStackEntry.arguments?.getString("postId"))
|
postActions = postActions,
|
||||||
setWebUri("https://lobste.rs/s/$postId")
|
)
|
||||||
CommentsPage(
|
|
||||||
postId = postId,
|
|
||||||
getDetails = viewModel::getPostComments,
|
|
||||||
modifier = Modifier.navigationBarsPadding(),
|
|
||||||
postActions = postActions,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ serialization = "1.3.2"
|
||||||
sqldelight = "1.5.3"
|
sqldelight = "1.5.3"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
accompanist-insets = { module = "com.google.accompanist:accompanist-insets", version.ref = "accompanist" }
|
|
||||||
accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "accompanist" }
|
accompanist-swiperefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "accompanist" }
|
||||||
accompanist-sysuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
|
accompanist-sysuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
|
||||||
androidx-activity-compose = "androidx.activity:activity-compose:1.6.0-alpha01"
|
androidx-activity-compose = "androidx.activity:activity-compose:1.6.0-alpha01"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue