mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-27 18:22:31 +01:00
- Inverts the scroll to hide for channels and chats
- Awaits half of the bar to change visibility
This commit is contained in:
parent
dab02f2cbd
commit
384594ba5c
@ -150,6 +150,14 @@ sealed class Route(
|
||||
route = "Settings",
|
||||
icon = R.drawable.ic_settings
|
||||
)
|
||||
|
||||
companion object {
|
||||
val InvertedLayouts = setOf(
|
||||
Channel.route,
|
||||
Room.route,
|
||||
RoomByAuthor.route
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// **
|
||||
|
@ -42,6 +42,7 @@ import com.vitorpamplona.amethyst.ui.buttons.NewCommunityNoteButton
|
||||
import com.vitorpamplona.amethyst.ui.buttons.NewImageButton
|
||||
import com.vitorpamplona.amethyst.ui.buttons.NewNoteButton
|
||||
import com.vitorpamplona.amethyst.ui.navigation.*
|
||||
import com.vitorpamplona.amethyst.ui.navigation.Route.Companion.InvertedLayouts
|
||||
import com.vitorpamplona.amethyst.ui.note.UserReactionsViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.AccountState
|
||||
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
||||
@ -56,6 +57,7 @@ import com.vitorpamplona.amethyst.ui.screen.NostrVideoFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.NotificationViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.abs
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class, ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
@ -193,8 +195,7 @@ fun MainScreen(
|
||||
}
|
||||
}
|
||||
|
||||
val bottomBarHeight = 50.dp
|
||||
val bottomBarHeightPx = with(LocalDensity.current) { bottomBarHeight.roundToPx().toFloat() }
|
||||
val bottomBarHeightPx = with(LocalDensity.current) { 50.dp.roundToPx().toFloat() }
|
||||
val bottomBarOffsetHeightPx = remember { mutableStateOf(0f) }
|
||||
|
||||
val nestedScrollConnection = remember {
|
||||
@ -202,13 +203,24 @@ fun MainScreen(
|
||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||
val delta = available.y
|
||||
val newOffset = bottomBarOffsetHeightPx.value + delta
|
||||
bottomBarOffsetHeightPx.value = newOffset.coerceIn(-bottomBarHeightPx, 0f)
|
||||
|
||||
val currentRoute = navState.value?.destination?.route
|
||||
|
||||
bottomBarOffsetHeightPx.value = if (currentRoute !in InvertedLayouts) {
|
||||
newOffset.coerceIn(-bottomBarHeightPx, 0f)
|
||||
} else {
|
||||
newOffset.coerceIn(0f, bottomBarHeightPx)
|
||||
}
|
||||
|
||||
return Offset.Zero
|
||||
}
|
||||
}
|
||||
}
|
||||
val shouldShow = bottomBarOffsetHeightPx.value == 0f
|
||||
val shouldShow = remember {
|
||||
derivedStateOf {
|
||||
abs(bottomBarOffsetHeightPx.value) < bottomBarHeightPx / 2.0f
|
||||
}
|
||||
}
|
||||
|
||||
ModalBottomSheetLayout(
|
||||
sheetState = sheetState,
|
||||
@ -223,7 +235,7 @@ fun MainScreen(
|
||||
.nestedScroll(nestedScrollConnection),
|
||||
bottomBar = {
|
||||
AnimatedContent(
|
||||
targetState = shouldShow,
|
||||
targetState = shouldShow.value,
|
||||
transitionSpec = {
|
||||
slideInVertically { height -> height } togetherWith
|
||||
slideOutVertically { height -> height }
|
||||
@ -236,7 +248,7 @@ fun MainScreen(
|
||||
},
|
||||
topBar = {
|
||||
AnimatedContent(
|
||||
targetState = shouldShow,
|
||||
targetState = shouldShow.value,
|
||||
transitionSpec = {
|
||||
slideInVertically { height -> 0 } togetherWith
|
||||
slideOutVertically { height -> 0 }
|
||||
@ -262,7 +274,7 @@ fun MainScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
Crossfade(
|
||||
targetState = shouldShow,
|
||||
targetState = shouldShow.value,
|
||||
animationSpec = tween(durationMillis = 100)
|
||||
) { state ->
|
||||
if (state) {
|
||||
@ -280,7 +292,7 @@ fun MainScreen(
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(bottom = if (bottomBarOffsetHeightPx.value == 0f || navState.value?.destination?.route != Route.Home.base) it.calculateBottomPadding() else 0.dp)
|
||||
.padding(bottom = if (shouldShow.value) it.calculateBottomPadding() else 0.dp)
|
||||
) {
|
||||
AppNavigation(
|
||||
homeFeedViewModel = homeFeedViewModel,
|
||||
|
Loading…
x
Reference in New Issue
Block a user