情况
我正在使用 Kotlin
编写一个非常简单的应用程序& Android Jetpack Compose
我有一个 scaffold
包含我的navHost
和 bottomBar
.
我可以使用 bottomBar
在三个主屏幕之间导航。
其中一个主屏幕有一个详细屏幕,它不应该显示 bottomBar
.
我的代码
到目前为止,这是小菜一碟:
// MainActivitys onCreate
setContent {
val navController = rememberAnimatedNavController()
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route?.substringBeforeLast("/")
BottomBarNavTestTheme {
Scaffold(
bottomBar = {
if (currentRoute?.substringBeforeLast("/") == Screen.Detail.route) {
MyBottomNavigation(
navController,
currentRoute,
listOf(Screen.Dashboard, Screen.Map, Screen.Events) // main screens
)
}
}
) { innerPadding ->
NavHost( // to be replaced by AnimatedNavHost
navController = navController,
startDestination = Screen.Dashboard.route,
modifier = Modifier.padding(innerPadding)
) {
composable(Screen.Dashboard.route) { DashboardScreen() }
composable(Screen.Map.route) { MapScreen { navController.navigate(Screen.Detail.route) } }
composable(Screen.Events.route) { EventsScreen() }
composable(Screen.Detail.route) { MapDetailScreen() }
}
}
}
}
问题 :
我想在我的屏幕之间进行转换,所以我使用 Accompanists Navigation Animation :
只需更换
NavHost
与 AnimatedNavHost
.从
mainScreen
导航时至detailScreen
有一个奇怪的效果:这看起来很糟糕,我该如何解决?
解决方案
最佳解决方案如下所示:
最佳答案
因此,我们采用了一种解决方法:
scaffold
现在不包含 bottomBar
没有了bottomBar
. 这工作正常,只是
bottomBar
的波纹点击没有我们想要的那么流畅(我们在点击中交换它,所以这是意料之中的)这也解决了一个问题,即屏幕具有可滚动内容,由于隐藏底栏时滚动距离发生了变化,因此滚动距离有点困惑。
关于android - 使用伴奏导航动画时如何在 Jetpack Compose 中隐藏底栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68895484/