Navigation drawers provide ergonomic access to destinations in an app.
SampleModalNavigationDrawerWithGradientScrim
@Composable
fun SampleModalNavigationDrawerWithGradientScrim() {
var selectedIndex by remember { mutableIntStateOf(0) }
val items =
listOf(
"Home" to Icons.Default.Home,
"Settings" to Icons.Default.Settings,
"Favourites" to Icons.Default.Favorite,
)
val closeDrawerWidth = 80.dp
val backgroundContentPadding = 10.dp
ModalNavigationDrawer(
drawerContent = {
Column(
Modifier.background(Color.Gray).fillMaxHeight().padding(12.dp).selectableGroup(),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
items.forEachIndexed { index, item ->
val (text, icon) = item
NavigationDrawerItem(
selected = selectedIndex == index,
onClick = { selectedIndex = index },
leadingContent = { Icon(imageVector = icon, contentDescription = null) },
) {
Text(text)
}
}
}
},
scrimBrush = Brush.horizontalGradient(listOf(Color.DarkGray, Color.Transparent)),
) {
Button(
modifier =
Modifier.padding(closeDrawerWidth + backgroundContentPadding)
.height(100.dp)
.fillMaxWidth(),
onClick = {},
) {
Text("BUTTON")
}
}
}
SampleModalNavigationDrawerWithSolidScrim
@Composable
fun SampleModalNavigationDrawerWithSolidScrim() {
var selectedIndex by remember { mutableIntStateOf(0) }
val items =
listOf(
"Home" to Icons.Default.Home,
"Settings" to Icons.Default.Settings,
"Favourites" to Icons.Default.Favorite,
)
val closeDrawerWidth = 80.dp
val backgroundContentPadding = 10.dp
ModalNavigationDrawer(
drawerContent = {
Column(
Modifier.background(Color.Gray).fillMaxHeight().padding(12.dp).selectableGroup(),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
items.forEachIndexed { index, item ->
val (text, icon) = item
NavigationDrawerItem(
selected = selectedIndex == index,
onClick = { selectedIndex = index },
leadingContent = { Icon(imageVector = icon, contentDescription = null) },
) {
Text(text)
}
}
}
}
) {
Button(
modifier =
Modifier.padding(closeDrawerWidth + backgroundContentPadding)
.height(100.dp)
.fillMaxWidth(),
onClick = {},
) {
Text("BUTTON")
}
}
}