Am building `Owl` on my own to practice `Compose`....
# compose
m
Am building
Owl
on my own to practice
Compose
. I have problem with
BottomNavigation
and navigation component. code in thread.
Copy code
private enum class CourseTab(
    @StringRes val label: Int,
    @DrawableRes val icon: Int,
) {
    MyCourses(R.string.my_courses, R.drawable.ic_featured),
    Featured(R.string.featured, R.drawable.ic_featured),
    Search(R.string.search, R.drawable.ic_search),
}

@Composable
fun Courses() {
    BlueTheme {
        val navController = rememberNavController()
        val tabs = CourseTab.values()
        Scaffold(
            bottomBar = {
                BottomNavigation(modifier = Modifier.navigationBarsPadding()) {
                    tabs.forEach { tab ->
                        BottomNavigationItem(
                            modifier = Modifier.navigationBarsPadding(),
                            icon = {
                                Icon(
                                    painter = painterResource(id = tab.icon),
                                    contentDescription = stringResource(id = tab.label),
                                )
                            },
                            label = { Text(text = stringResource(id = tab.label)) },
                            selected = tab.name == navController.currentBackStackEntry?.arguments?.getString(KEY_ROUTE),
                            onClick = { navController.navigate(tab.name) },
                            alwaysShowLabel = false,
                            selectedContentColor = MaterialTheme.colors.secondary,
                            unselectedContentColor = LocalContentColor.current,
                        )
                    }
                }
            }
        ) { innerPadding ->
            val modifier = Modifier.padding(innerPadding)
            NavHost(
                navController = navController,
                startDestination = CourseTab.MyCourses.name,
            ) {
                composable(CourseTab.MyCourses.name) { MyCourses(modifier) }
                composable(CourseTab.Featured.name) { FeaturedCourses(modifier) }
                composable(CourseTab.Search.name) { SearchCourses(modifier) }
            }
        }
    }
}
how to make navigation item be selected when destination connected to it is displayed?
right now they are not changing but destinations are being set
o
I saw a tweet about that I think (can't find it back 😭 ), it was following a question by @John O'Reilly if I remember well (renamed to something else IIRC)
m
I totally forgot about this https://developer.android.com/jetpack/compose/navigation#bottom-nav but I can’t find
navigate
method with
popUpTo
n
The
popUpTo
is inside the lambda, maybe you were looking in the parameters. Other than that maybe just check if you have the proper import
m
Right! @Nikola Drljaca. I was sooo tired that I din’t notice that
popUpTo
is not a parameter 😄 😄 😄
Thanks 😄
n
Nema na čemu 😄
😄 1