I have a BottomNavBar
which is called inside the bottomBar
of a Scaffold
.
Every screen contains a LazyColumn
which displays a bunch of images.
For some reason when I finish scrolling, the BottomNavBar
overlaps the lower part of the items list.
How can I fix this?
Here the set content of MainActivity
SetContent{ Scaffold( topBar = { TopAppBar( title = { Text(text = "tartufozon") }, actions = { IconButton(onClick = { Timber.d("Mail clicked") }) { Icon(Icons.Default.Email, contentDescription = null) } } ) }, bottomBar = { BottomNavBar(navController = navController) } ) { BottomNavScreensController(navController = navController) } }
Recomposition is the process of calling your composable functions again when inputs change. This happens when the function's inputs change. When Compose recomposes based on new inputs, it only calls the functions or lambdas that might have changed, and skips the rest.
How do you get the device width in jetpack compose? If you want to get the size in pixels: val screenDensity = configuration. densityDpi / 160f and multiply with dp, for example val screenHeight = configuration. screenHeightDp.
Compose allows you to do more with less code compared to XML. Compose is Intuitive. This means that you just need to tell Compose what you want to show the user. Compose is compatible with all your existing code: you can call Compose code from Views and Views from Compose.
As per the API definition for Scaffold, your inner content (the trailing lambda you have your BottomNavScreensController
in), is given a PaddingValues
object that gives you the right amount of padding for your top app bar, bottom bar, etc.
Right now, you're not referencing that padding at all and hence, your content is not padded in. This is what is causing your overlap.
You can add a Box
around your BottomNavScreensController
to apply the padding, or pass the padding directly into your BottomNavScreensController
so that each individual screen can correctly apply the padding; either solution works.
Scaffold( topBar = { // }, bottomBar = { // } ) { innerPadding -> // Apply the padding globally to the whole BottomNavScreensController Box(modifier = Modifier.padding(innerPadding)) { BottomNavScreensController(navController = navController) } } }
Following ianhanniballake's answer and its comments and just to save you few minutes. The code would be something like:
Scaffold( topBar = { // }, bottomBar = { // } ) { innerPadding -> Box(modifier = Modifier.padding( PaddingValues(0.dp, 0.dp, 0.dp, innerPadding.calculateBottomPadding()) { BottomNavScreensController(navController = navController) } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With