mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2024-09-29 16:30:49 +00: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",
|
route = "Settings",
|
||||||
icon = R.drawable.ic_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.NewImageButton
|
||||||
import com.vitorpamplona.amethyst.ui.buttons.NewNoteButton
|
import com.vitorpamplona.amethyst.ui.buttons.NewNoteButton
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.*
|
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.note.UserReactionsViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.AccountState
|
import com.vitorpamplona.amethyst.ui.screen.AccountState
|
||||||
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
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.NotificationViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel
|
import com.vitorpamplona.amethyst.ui.screen.ThemeViewModel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.math.abs
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterialApi::class, ExperimentalAnimationApi::class)
|
@OptIn(ExperimentalMaterialApi::class, ExperimentalAnimationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@ -193,8 +195,7 @@ fun MainScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val bottomBarHeight = 50.dp
|
val bottomBarHeightPx = with(LocalDensity.current) { 50.dp.roundToPx().toFloat() }
|
||||||
val bottomBarHeightPx = with(LocalDensity.current) { bottomBarHeight.roundToPx().toFloat() }
|
|
||||||
val bottomBarOffsetHeightPx = remember { mutableStateOf(0f) }
|
val bottomBarOffsetHeightPx = remember { mutableStateOf(0f) }
|
||||||
|
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
@ -202,13 +203,24 @@ fun MainScreen(
|
|||||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||||
val delta = available.y
|
val delta = available.y
|
||||||
val newOffset = bottomBarOffsetHeightPx.value + delta
|
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
|
return Offset.Zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val shouldShow = bottomBarOffsetHeightPx.value == 0f
|
val shouldShow = remember {
|
||||||
|
derivedStateOf {
|
||||||
|
abs(bottomBarOffsetHeightPx.value) < bottomBarHeightPx / 2.0f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ModalBottomSheetLayout(
|
ModalBottomSheetLayout(
|
||||||
sheetState = sheetState,
|
sheetState = sheetState,
|
||||||
@ -223,7 +235,7 @@ fun MainScreen(
|
|||||||
.nestedScroll(nestedScrollConnection),
|
.nestedScroll(nestedScrollConnection),
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
AnimatedContent(
|
AnimatedContent(
|
||||||
targetState = shouldShow,
|
targetState = shouldShow.value,
|
||||||
transitionSpec = {
|
transitionSpec = {
|
||||||
slideInVertically { height -> height } togetherWith
|
slideInVertically { height -> height } togetherWith
|
||||||
slideOutVertically { height -> height }
|
slideOutVertically { height -> height }
|
||||||
@ -236,7 +248,7 @@ fun MainScreen(
|
|||||||
},
|
},
|
||||||
topBar = {
|
topBar = {
|
||||||
AnimatedContent(
|
AnimatedContent(
|
||||||
targetState = shouldShow,
|
targetState = shouldShow.value,
|
||||||
transitionSpec = {
|
transitionSpec = {
|
||||||
slideInVertically { height -> 0 } togetherWith
|
slideInVertically { height -> 0 } togetherWith
|
||||||
slideOutVertically { height -> 0 }
|
slideOutVertically { height -> 0 }
|
||||||
@ -262,7 +274,7 @@ fun MainScreen(
|
|||||||
},
|
},
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
Crossfade(
|
Crossfade(
|
||||||
targetState = shouldShow,
|
targetState = shouldShow.value,
|
||||||
animationSpec = tween(durationMillis = 100)
|
animationSpec = tween(durationMillis = 100)
|
||||||
) { state ->
|
) { state ->
|
||||||
if (state) {
|
if (state) {
|
||||||
@ -280,7 +292,7 @@ fun MainScreen(
|
|||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
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(
|
AppNavigation(
|
||||||
homeFeedViewModel = homeFeedViewModel,
|
homeFeedViewModel = homeFeedViewModel,
|
||||||
|
Loading…
Reference in New Issue
Block a user