小编ism*_*l M的帖子

Jetpack compose BottomNavigation - java.lang.IllegalStateException:已附加到生命周期所有者

当我双击同一项目或如果我很快进入每个可组合屏幕时,我会收到一条错误消息,我该如何解决此问题?我尝试改变一些东西,但我无法解决它,而且我找不到任何资源来解决这个问题。

底部导航实施

@Composable
fun BottomNav(
    navController: NavController,
    bottomNavState: MutableState<Boolean>,
) {

    val navItems = listOf(
        Screen.HomeScreen,
        Screen.BookmarkScreen,
        Screen.MyRecipesScreen,
        Screen.FavouriteScreen
    )

    AnimatedVisibility(
        visible = bottomNavState.value,
        enter = slideInVertically(initialOffsetY = { it }),
        exit = slideOutVertically(targetOffsetY = { it }),
        content = {
            BottomNavigation(
                backgroundColor = Color.White,
                elevation = 12.dp
            ) {

                val bottomNavBackStackEntry by navController.currentBackStackEntryAsState()
                val currentDestination = bottomNavBackStackEntry?.destination

                navItems.forEach { item ->

                    BottomNavigationItem(
                        icon = {
                            Icon(painter = painterResource(id = item.icon), contentDescription = "")
                        },
                        label = {
                            Text(text = …
Run Code Online (Sandbox Code Playgroud)

kotlin android-jetpack android-jetpack-navigation android-jetpack-compose

13
推荐指数
1
解决办法
1509
查看次数