mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 18:47:03 +05:30
feat(android): link up bottombar visibility with scroll
This commit is contained in:
parent
d678843230
commit
f1fcaf53f4
3 changed files with 17 additions and 4 deletions
|
@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Change submitter text to 'authored' when applicable
|
||||
- Unread comments now have a brighter background rather than a text badge
|
||||
- Opening posts you have previously seen will show the number of new comments since last visit
|
||||
- Opening posts you have previously seen will show the number of new comments since last visit
|
||||
- Bottom navigation's visibility now interacts with the scroll behavior of the post lists
|
||||
|
||||
## [1.48.0] - 2024-06-05
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@ import androidx.compose.animation.core.LinearOutSlowInEasing
|
|||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.material3.BottomAppBar
|
||||
import androidx.compose.material3.BottomAppBarScrollBehavior
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
@ -29,11 +31,13 @@ import kotlinx.collections.immutable.ImmutableList
|
|||
|
||||
const val AnimationDuration = 100
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ClawNavigationBar(
|
||||
navController: NavController,
|
||||
items: ImmutableList<NavigationItem>,
|
||||
isVisible: Boolean,
|
||||
scrollBehavior: BottomAppBarScrollBehavior,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
|
@ -52,7 +56,7 @@ fun ClawNavigationBar(
|
|||
),
|
||||
modifier = Modifier,
|
||||
) {
|
||||
NavigationBar(modifier = modifier) {
|
||||
BottomAppBar(modifier = modifier, scrollBehavior = scrollBehavior) {
|
||||
val navBackStackEntry = navController.currentBackStackEntryAsState().value
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
items.forEach { navItem ->
|
||||
|
|
|
@ -26,6 +26,7 @@ import androidx.compose.material.icons.filled.Whatshot
|
|||
import androidx.compose.material.icons.outlined.FavoriteBorder
|
||||
import androidx.compose.material.icons.outlined.NewReleases
|
||||
import androidx.compose.material.icons.outlined.Whatshot
|
||||
import androidx.compose.material3.BottomAppBarDefaults
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
|
@ -44,6 +45,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
@ -110,6 +112,8 @@ fun LobstersPostsScreen(
|
|||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val postActions = rememberPostActions(context, urlLauncher, navController, viewModel)
|
||||
|
||||
val scrollBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior()
|
||||
|
||||
val hottestPosts = viewModel.hottestPosts.collectAsLazyPagingItems()
|
||||
val newestPosts = viewModel.newestPosts.collectAsLazyPagingItems()
|
||||
val savedPosts by viewModel.savedPostsByMonth.collectAsState(persistentMapOf())
|
||||
|
@ -205,11 +209,15 @@ fun LobstersPostsScreen(
|
|||
navController = navController,
|
||||
items = navItems,
|
||||
isVisible = currentDestination.any(navDestinations),
|
||||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
}
|
||||
},
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
modifier = modifier.semantics { testTagsAsResourceId = true },
|
||||
modifier =
|
||||
modifier.nestedScroll(scrollBehavior.nestedScrollConnection).semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
) { paddingValues ->
|
||||
Row(modifier = Modifier.padding(paddingValues)) {
|
||||
AnimatedVisibility(visible = navigationType == ClawNavigationType.NAVIGATION_RAIL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue