I've implemented bottom bar in compose. When I cli...
# compose
r
I've implemented bottom bar in compose. When I click on bottom bar item once, it navigate to that section, but if I click on it again, it's not showing that section. What am I missing here? (code is in thread)
Copy code
@Composable
fun BottomBar(
    navController: NavHostController,
    items: List<Screens>,
    profilePicUrl: String?
) {
    BottomNavigation(
        modifier = Modifier.height(50.dp),
        backgroundColor = MaterialTheme.colors.background,
        contentColor = contentColorFor(MaterialTheme.colors.background)
    ) {
        val navBackStackEntry by navController.currentBackStackEntryAsState()
        val currentDestination = navBackStackEntry?.destination

        items.forEach { screen ->
            val selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true
            val iconRes = if (selected) screen.selectedIcon else screen.icon

            BottomNavigationItem(
                icon = {
                        Icon(
                            painterResource(id = iconRes),
                            modifier = Modifier.iconSize(),
                            contentDescription = screen.route
                        )
                },
                selected = selected,
                onClick = {
                    navController.navigate(screen.route) {
                        popUpTo(navController.graph.findStartDestination().id) {
                            saveState = true
                        }
                        launchSingleTop = true
                        restoreState = true
                    }
                },
                alwaysShowLabel = false
            )
        }
    }
}
c
Are you on latest navigation (I think alpha07 released ~2 days ago fixed this)
1
t
@rajesh Can you show ur
NavGraph
?
@Colton Idle are u talking abt this issue? https://issuetracker.google.com/issues/186392337
c
Nope. A different one (though that one seems similar/related)
🆗 1
r
@Colton Idle yes, updating to latest navigation lib fixed the issue. PS: I appreciate your efforts to actively help everyone in this channel.
@theapache64 issue was in navigation lib itself as pointed by colton