https://kotlinlang.org logo
#compose
Title
# compose
n

Neal Sanche

01/29/2021, 7:36 PM
I've been trying, probably for too long, to use @cb Insets Accompanist library to show a
BottomNavigation
with a height that also includes the navigation bar height, so that the
BottomNavigation
paints all the way to the bottom of the screen. I have tried all sorts of things, and just end up with a space underneath the bottom nav. I sort of want this effect without having to resort to making a column with a spacer at the bottom. Here's the code I have so far within my
Scaffold
Copy code
bottomBar = {
            Column(Modifier.background(MaterialTheme.colors.primary)) {
                BottomNavigation(
                    elevation = 0.dp,
                    backgroundColor = MaterialTheme.colors.primary,
                    contentColor = contentColorFor(MaterialTheme.colors.primary),
                ) {
                    bottomNavItems.forEach { screen ->
                        val navBackStackEntry by navController.currentBackStackEntryAsState()
                        val currentRoute =
                            navBackStackEntry?.arguments?.getString(KEY_ROUTE)
                                ?: Screen.Profile.route

                        BottomNavigationItem(
                            icon = { Icon(imageVector = screen.icon, contentDescription = null) },
                            label = { Text(stringResource(screen.resourceId)) },
                            selected = currentRoute == screen.route,
                            onClick = {
                                navController.navigate(screen.route) {
                                    popUpTo = navController.graph.startDestination
                                    launchSingleTop = true
                                }
                            }
                        )
                    }
                }
                Spacer(Modifier.navigationBarsHeight())
            }
        }
c

cb

01/29/2021, 7:57 PM
BottomNavigation
and
TopAppBar
and friends don’t allow setting of inner content padding to achieve what you want. Have a look at the sample for an idea of how to support this: https://github.com/chrisbanes/accompanist/blob/main/sample/src/main/java/dev/chrisbanes/accompanist/sample/insets/EdgeToEdgeLazyColumn.kt#L145
n

Neal Sanche

01/29/2021, 8:20 PM
Thanks, that's what I suspected as I played with it. Thanks very much for the link to the sample. It's a nice example, and I'll spend some time to integrate that idea into my little technology spike.
👍 2