[英]Jetpack Compose Bottom Navigation Bar visibility changes with delay
I have a bottom navigation bar with 3 screen.我有一个带 3 个屏幕的底部导航栏。 I am hiding bottom navigation bar in detail screen with AnimatedVisibility
but visibility changes with delay.我使用AnimatedVisibility
在详细信息屏幕中隐藏了底部导航栏,但可见性会随着延迟而变化。
Surface(color = MaterialTheme.colors.background) {
// Get UI state
val uiState by rememberFlowWithLifecycle(flow = viewModel.uiState).collectAsState(initial = MainUiState(true))
// Set Status bar to transparent
SetStatusBarColor()
// Create Navigation
val navController = rememberNavController()
val navigationActions = remember(navController) {
NavActions(navController)
}
// Create Scaffold Composable
Scaffold(
topBar = { },
bottomBar = {
AnimatedVisibility(
visible = uiState.isBottomBarVisible,
) {
BottomNavigationBar(
navController,
navigationActions,
Modifier.navigationBarsPadding()
)
}
}
) { innerPaddings ->
NavigationGraph(
navController,
navigationActions,
Modifier
.padding(innerPaddings)
.statusBarsPadding()
)
}
// Change bottom bar state
val currentRoute = getCurrentRoute(navController = navController)
viewModel.changeBottomBarVisibility(currentRoute != Screen.Detail.path)
}
}
With default enter and exit animation, visibility changes without delay默认进出animation,能见度变化无延迟
But when I change enter and exit animations for example scale
, bottom bar has laggy behaviour while becoming invisible但是,当我更改进入和退出动画(例如scale
)时,底栏在变得不可见时会出现滞后行为
AnimatedVisibility(
visible = uiState.isBottomBarVisible,
enter = scaleIn(),
exit = scaleOut()
) {
BottomNavigationBar(
navController,
navigationActions,
Modifier.navigationBarsPadding()
)
}
Tested in Huawei P40 Lite and Google Pixel Emulator, behaviours are the same.在 Huawei P40 Lite 和 Google Pixel Emulator 中测试,行为相同。
Compose version is 1.0.5 Compose navigation version is 2.4.0 Compose animation version is 1.1.0 Compose 版本是 1.0.5 Compose 导航版本是 2.4.0 Compose animation 版本是 1.1.0
In short, animated visibility hasn't got smooth behaviour without default animation简而言之,动画可见性在没有默认值 animation 的情况下没有流畅的行为
I think, it's happens because size of screen changes when you hide bottomBar.我认为,这是因为当您隐藏 bottomBar 时屏幕大小会发生变化。 For fix that, try to delete modifier padding(innerPaddings)
in NavigationGraph
and control padding manually for each pages.要解决此问题,请尝试删除NavigationGraph
中的修饰符padding(innerPaddings)
并手动控制每个页面的填充。 If it's doesn't help, i will try your code later.如果它没有帮助,我稍后会尝试您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.