CamoNavigationDrawer
Concept
1. Why
A navigation drawer lists destinations with full labels, section headers and dividers. It has two modes:
- permanent: always visible on wide windows (the desktop sidebar; Apple's sidebar, Fluent's Nav);
- modal: slides in from the start edge over the content, with a scrim, on phones when there are too many destinations for a bar.
It uses the same CamoNavItem model, and the modal mode reuses the overlay frame machinery, from the side instead of the bottom.
2. Shape
Material mapping preview: the M3 navigation drawer.
- 360 wide.
surfaceContainerLow(modal) orsurface(permanent). - Items 56 tall, with a full-width
secondaryContainerpill when active. - Section titles
titleSmallinonSurfaceVariant. - The modal drawer has
shapes.largeend corners and ascrimat 32%.
3. API
Contract
fun <T> CamoNavigationDrawer(
sections: List<CamoNavSection<T>>, // one untitled section for simple lists
selected: T,
onSelect: (T) -> Unit,
header: Widget? = null, // app logo, account switcher
)
data class CamoNavSection<T>(val title: String? = null, val items: List<CamoNavItem<T>>)
fun CamoModalDrawer(
open: Boolean,
onDismissRequest: () -> Unit, // scrim tap, back, Esc, drag to the start edge
content: Slot, // a CamoNavigationDrawer
)
The modal drawer's visibility is state (open), not a route: a menu button toggles it, and selecting an item closes it. That's the convention on both platforms. It's layout chrome, not a destination.
State → renderer: DrawerState(modal, selectedKey). Slots: header?, and section titles + NavItemSlots.
Tokens used
colors.surface/surfaceContainerLow,secondaryContainer,onSecondaryContainer,onSurfaceVariant,outlineVariant,scrimtypography.labelLarge(items),titleSmall(section titles),shapes.full(item pill),shapes.large(modal corners)motion.durationMedium+easingEmphasized(slide)
Component theme
theme.components.navigationDrawer: NavigationDrawerTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
indicator | NavIndicator (Pill | Line | Dot | Fill | None) | Pill | the selected item's indicator. Line = a start-edge line (Fluent, Carbon); Fill = a filled row (Minimal). The size and shape fields apply to the chosen style. |
width | Dp | 360 | drawer width (max 80% of the window on phones) |
itemHeight | Dp | 56 | item rows |
itemShape | Shape | shapes.full | active pill |
modalShape | Shape | shapes.large (end corners) | modal container |
labelStyle / sectionTitleStyle | CamoTextStyle | labelLarge / titleSmall | texts |
scrimAlpha | Float | 0.32 | modal scrim |
colors | DrawerColors(container, modalContainer, indicator, selectedContent, content, sectionTitle) | M3 values | every color it uses |
Accessibility
- A navigation landmark. Section titles are headings. Items are links/tabs with a selected state.
- Modal: announced as a pane ("Navigation"). Focus moves in and is trapped. Back/Esc closes it and returns focus to the menu button.
- It's never drag-only: the scrim, back and Esc also close it.
4. Build steps
- The side frame (reusing the sheet frame's scrim, focus and dismissal logic, horizontally).
CamoNavigationDrawer,CamoModalDrawer,NavigationDrawerRenderer, and the DebugSkin renderer.- Sample: a permanent drawer on desktop (via
CamoAdaptiveNavigation), and a modal drawer on phones opened from the top bar's menu button. - Tests:
- open/close by button, scrim, back, Esc and drag;
- selecting closes the modal drawer;
- focus restored to the menu button;
- RTL slides in from the right.
Done when
- Both modes work on every platform, and match the bar and rail's selection in the adaptive sample.
5. Edge cases
| Case | Decided behavior |
|---|---|
| An edge-swipe to open (from the screen edge) | Off by default, because it conflicts with system back gestures on Android and iOS. Apps can enable it (CamoModalDrawer(edgeSwipeToOpen = true)). |
| Long destination lists | The drawer scrolls. The header stays fixed. |
| Nested destinations (expandable groups) | Later. |
- The drawer renderer draws a container (with the fixed header above a scrolling column), the section titles and the items. Items inside a
CamoModalDrawerclose it when chosen. CamoModalDrawer(open, onDismissRequest): the popup stays until the slide-out finishes; a scrim tap, back, Esc and a drag toward the start edge all callonDismissRequest; RTL slides in from the right. Kotlin uses a focus-trapping popup; Flutter anOverlayPortal(so it needs anOverlayabove it, as inside any route) with an autofocusFocusScopeand aPopScopefor back.edgeSwipeToOpenis not built (it is off by default).- Fluent's pane is 260 wide with items 40, a 2 px brand line and a subtle selected row.
Implementation
1. Why
The drawer has two modes: permanent (a side panel on wide windows) and modal (slides over the content with a scrim). Kotlin implements the modal one in-layer like the overlay frames: a scrim, a drag-to-close gesture with anchoredDraggable, a focus trap, back and Esc handling.
2. Shape
3. API
@Composable
public fun <T> CamoNavigationDrawer(
sections: List<CamoNavSection<T>>,
selected: T,
onSelect: (T) -> Unit,
modifier: Modifier = Modifier,
header: (@Composable () -> Unit)? = null,
)
@Composable
public fun CamoModalDrawer(open: Boolean, onDismissRequest: () -> Unit, modifier: Modifier = Modifier, content: @Composable () -> Unit)
- Items: full-width rows,
selectable(role = Role.Tab);style.indicatordrawsPill,Line(start edge),Fill(Minimal) orNone. Section titles are headings. - Modal drawer: rendered in the provider's overlay layer (above content, below snackbars).
AnchoredDraggableStatewith anchorsClosed = -panelWidthandOpen = 0(mirrored in RTL); a fling or a drag past half closes it and callsonDismissRequest. The scrim alpha follows the drag fraction. - Modality: the scrim consumes pointer input; focus moves to the first item on open and is trapped inside the panel (
focusGroup+focusProperties { exit = { FocusRequester.Cancel } }); the back handler and Esc callonDismissRequest;semantics { paneTitle = "Navigation" }. - Width:
min(style.width, 0.8 × window width)on phones.
4. Build steps
CamoNavSection,NavigationDrawerTheme/Style,CamoNavigationDrawer,CamoModalDrawer, the DebugSkin renderer.- UI tests: permanent selection; modal opens, closes by scrim, back, Esc and drag; focus is trapped and returns to the menu button; RTL slides from the right.
Done when
- The adaptive sample shows a permanent drawer on desktop, and a modal drawer from a top-bar menu button on phones, on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
open flips while dragging | The state animates to the new target from the current offset. |
| Selecting an item in the modal drawer | The app calls onSelect and closes the drawer (the sample shows the pattern: navigate, then open = false). |
| Nested destinations (expandable groups) | Later. |