I am using Material's BottomAppBar
as my BottomNav in my Jetpack Compose's App. But when I tried to dock my fab on the BottomAppBar
, it covers the nav items as the screenshot shows. Is there any way that could auto-add a space beside the fab?
I want to implement this effect without adding Space
between nav items manually, like the effect below shows:
Below is my code:
@Composable
fun TestApp() {
val navController = rememberNavController()
Scaffold(
bottomBar = {
MyBottomAppBar(navController = navController)
},
floatingActionButton = {
FloatingActionButton(onClick = { }) {
Icon(imageVector = Icons.Rounded.Add, contentDescription = "fab")
}
},
floatingActionButtonPosition = FabPosition.Center,
isFloatingActionButtonDocked = true,
) {
NavHost(navController, startDestination = Screen.Bill.route) {
composable(Screen.Bill.route) { BillScreen() }
composable(Screen.Chart.route) { ChartScreen() }
composable(Screen.Budget.route) { BudgetScreen() }
composable(Screen.Account.route) { AccountScreen() }
}
}
}
@Composable
fun MyBottomAppBar(navController: NavController) {
BottomAppBar(
cutoutShape = CircleShape
) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
Screen.items.forEachIndexed { index, screen ->
BottomNavigationItem(
selected = (currentRoute == screen.route),
icon = { Icon(screen.iconRes, screen.route) },
label = { Text(stringResource(id = screen.labelRes)) },
onClick = {
navController.navigate(screen.route) {
popUpTo = navController.graph.startDestination
launchSingleTop = true
}
}
)
}
}
}