简体   繁体   English

Jetpack Compose 底部导航栏可见性随延迟变化

[英]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.

相关问题 Jetpack compose 中的底部导航栏重叠按钮 - Bottom navigation bar overlap button in jetpack compose Jetpack Compose - 底部导航栏不显示嵌套的 navGraph - Jetpack Compose - Bottom navigation bar isn't showing with nested navGraph Android底部导航栏可见性 - Android bottom navigation bar visibility Jetpack Compose – BottomBar 在底部导航下方 - Jetpack Compose – BottomBar is under Bottom Navigation Jetpack compose - 更改底部栏切口颜色 - Jetpack compose - change bottom bar cutout color 使用伴奏导航时如何隐藏 Jetpack Compose 中的底部栏 Animation - How to hide bottom bar in Jetpack Compose when using Accompanists` Navigation Animation 如何在向下滚动时隐藏底部导航栏并在jetpack compose中向上滚动时显示它? - How to hide bottom navigation bar while scrolling down and show it while scrolling up in jetpack compose? Jetpack Compose - 如果有嵌套导航,则不选择底部导航图标 - Jetpack Compose - Bottom navigation icon is not selected if it has nested navigation 如何在 Android Jetpack Compose 中进行圆底导航 - How to make rounded bottom navigation in Android Jetpack Compose Jetpack Compose 底部导航、fab 按钮和保存屏幕 state - Jetpack Compose bottom navigation, fab button and save screen state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM