Is there a bug in the bottom nav docs? <https://de...
# compose
f
Is there a bug in the bottom nav docs? https://developer.android.com/jetpack/compose/navigation#bottom-nav I've checked it a dozen times and when I click a bottom nav destination twice, the screen goes empty (except for the starting destination)
2
j
If you file an issue, please link it, saw that recently too
f
@jossiwolf Will do. Good to know that I'm not the only one 👍
I'm just running someone elses app who uses the same code and indeed it happens there as well
i
f
Ok, thanks. I wrapped the
onClick
part of the bottom nav items with
if (currentDestination?.route != destination.route)
Do you think that's fine?
Well I guess the behavior is not great
c
Can downgrade to alpha04 or just wait another week or so for the next release.
t
I have a weird bug with bottom nav as well. Sometimes when I select an item on the bottom nav it just doesn’t navigate anywhere or navigate to the first item. It’s really hard to reproduce this but it does happen from time to time. I haven’t been able to narrow down what cause that yet. Here’s my bottom nav setup
Copy code
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun BottomBar(
    entry: NavBackStackEntry?,
    navController: NavController
) {
    val list = listOf(Screens.Home, Screens.MyGame, Screens.Schedule, <http://Screens.Shop|Screens.Shop>, Screens.Account)
    val currentRoute = entry?.destination?.route
    AnimatedVisibility(
        visible = currentRoute in list.map { it.route },
        enter = slideInVertically({ it * 2 }),
        exit = slideOutVertically({ it * 2 }, snap())
    ) {
        BottomNavigation(
            backgroundColor = Color.White
        ) {
            list.forEach { screen ->
                val selected = currentRoute == screen.route
                val iconRes = screen.icon ?: R.drawable.ic_home
                val color by animateColorAsState(targetValue = if (selected) ActionOrange else DarkGray)
                BottomNavigationItem(
                    icon = {
                        Icon(
                            painter = painterResource(id = iconRes),
                            contentDescription = "",
                            tint = color
                        )
                    },
                    label = {
                        Text(
                            text = screen.name.uppercase(),
                            style = TextStyle(
                                fontFamily = robotoFamily,
                                fontWeight = FontWeight.W700,
                                fontSize = 10.sp
                            ),
                            modifier = Modifier
                                .padding(top = 8.dp),
                            color = color
                        )
                    },
                    selected = selected,
                    onClick = {
                        navController.navigate(screen.route) {
                            navController.graph.startDestinationRoute?.let {
                                popUpTo(it) {
                                    saveState = true
                                }
                            }
                            launchSingleTop = true
                            restoreState = true
                        }
                    }
                )
            }
        }
    }
}
f
@Colton Idle oh cool I didn't know that downgrading fixed it 👍
👍 1