diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt index f242c3815..912c665d6 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt @@ -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 + ) + } } // ** diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt index c50c62ee9..f8ddf0285 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt @@ -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,