androidx.compose.material3

ModalNavigationDrawer

Composable function

A navigation drawer is a side panel with the app's destinations. Use it when there are more than five, or on large screens.

A drawer has three layers:

  1. The drawer itself (ModalNavigationDrawer) wraps your whole screen.
  2. A sheet (ModalDrawerSheet) goes in drawerContent. It is the panel.
  3. Items (NavigationDrawerItem) go in the sheet, one per destination.
An open modal drawer
An open modal drawer
var selected by remember { mutableIntStateOf(0) }
// Open only for this picture. Normally: rememberDrawerState(DrawerValue.Closed)
val drawerState = rememberDrawerState(DrawerValue.Open)
Box(Modifier.size(400.dp, 360.dp)) {
    ModalNavigationDrawer(
        drawerState = drawerState,
        drawerContent = {
            ModalDrawerSheet {
                Text("Mail", Modifier.padding(16.dp))
                NavigationDrawerItem(
                    label = { Text("Inbox") },
                    icon = { Icon(Icons.Filled.Email, null) },
                    badge = { Text("24") },
                    selected = selected == 0,
                    onClick = { selected = 0 },
                    modifier = Modifier.padding(horizontal = 12.dp),
                )
                NavigationDrawerItem(
                    label = { Text("Favorites") },
                    icon = { Icon(Icons.Filled.Favorite, null) },
                    selected = selected == 1,
                    onClick = { selected = 1 },
                    modifier = Modifier.padding(horizontal = 12.dp),
                )
            }
        },
    ) {
        Text("Screen content", Modifier.padding(16.dp))
    }
}

There are three types:

Each type has its own sheet. Use the matching one.

To open a modal drawer from a menu button, call drawerState.open() from a coroutine.

Parameters

@Composable
fun ModalNavigationDrawer(
    drawerContent: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed),
    gesturesEnabled: Boolean = true,
    scrimColor: Color = DrawerDefaults.scrimColor,
    content: @Composable () -> Unit,
)

drawerContent: @Composable () -> UnitRequired

The panel. Use the sheet that matches the drawer type, like ModalDrawerSheet.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. Items usually get Modifier.padding(horizontal = 12.dp).

drawerState: DrawerStateOptional

Default: rememberDrawerState(DrawerValue.Closed)

Whether the drawer is open. Create it with rememberDrawerState(DrawerValue.Closed). Call open() and close() on it.

gesturesEnabled: BooleanOptional

Default: true

Set to false to stop the user from swiping the drawer open or closed.

scrimColor: ColorOptional

Default: DrawerDefaults.scrimColor

The color of the dim layer behind a modal drawer.

content: @Composable () -> UnitRequired

The screen behind the drawer. For a sheet, the items inside it, placed in a Column.

Drawer types and parts