androidx.compose.material3.adaptive.layout

ListDetailPaneScaffoldExperimental

Composable function · from org.jetbrains.compose.material3.adaptive:adaptive-layout:1.3.0

A list-detail layout shows a list, and the details of the item the user picked. Think of a mail app.

You don't write the "if wide, else" yourself. A navigator knows the window size and which item is open, and the scaffold shows the right panes.

On a wide window: list and detail side by side
On a wide window: list and detail side by side
val messages = listOf("Lunch on Friday?", "Your order has shipped", "Photos from the trip", "Meeting notes")

Box(Modifier.size(840.dp, 300.dp)) { Inbox(windowWidthDp = 840) }

/** A list of messages and the selected one. Works with one pane or two. */
@Composable
fun Inbox(windowWidthDp: Int) {
    val scope = rememberCoroutineScope()
    // The navigator decides which panes show. In an app, call it without arguments:
    // it reads the window size itself.
    val navigator = rememberListDetailPaneScaffoldNavigator<Int>(
        scaffoldDirective = calculatePaneScaffoldDirective(
            WindowAdaptiveInfo(WindowSizeClass.BREAKPOINTS_V2.computeWindowSizeClass(widthDp = windowWidthDp, heightDp = 480), Posture()),
        ),
    )
    val selected = navigator.currentDestination?.contentKey

    ListDetailPaneScaffold(
        directive = navigator.scaffoldDirective,
        scaffoldState = navigator.scaffoldState,
        listPane = {
            AnimatedPane {
                LazyColumn {
                    itemsIndexed(messages) { index, message ->
                        ListItem(
                            headlineContent = { Text(message) },
                            colors = ListItemDefaults.colors(
                                containerColor = if (index == selected) MaterialTheme.colorScheme.secondaryContainer
                                else MaterialTheme.colorScheme.surface,
                            ),
                            modifier = Modifier.clickable {
                                scope.launch { navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, index) }
                            },
                        )
                    }
                }
            }
        },
        detailPane = {
            AnimatedPane {
                Column(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surfaceContainerLow).padding(16.dp)) {
                    // Only needed when the list is hidden (one pane).
                    if (navigator.canNavigateBack()) {
                        IconButton(onClick = { scope.launch { navigator.navigateBack() } }) {
                            Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back")
                        }
                    }
                    Text(selected?.let { messages[it] } ?: "Pick a message", style = MaterialTheme.typography.titleLarge)
                }
            }
        },
    )
}
On a phone: only the list shows
On a phone: only the list shows
val messages = listOf("Lunch on Friday?", "Your order has shipped", "Photos from the trip", "Meeting notes")

Box(Modifier.size(360.dp, 300.dp)) { Inbox(windowWidthDp = 360) }

/** A list of messages and the selected one. Works with one pane or two. */
@Composable
fun Inbox(windowWidthDp: Int) {
    val scope = rememberCoroutineScope()
    // The navigator decides which panes show. In an app, call it without arguments:
    // it reads the window size itself.
    val navigator = rememberListDetailPaneScaffoldNavigator<Int>(
        scaffoldDirective = calculatePaneScaffoldDirective(
            WindowAdaptiveInfo(WindowSizeClass.BREAKPOINTS_V2.computeWindowSizeClass(widthDp = windowWidthDp, heightDp = 480), Posture()),
        ),
    )
    val selected = navigator.currentDestination?.contentKey

    ListDetailPaneScaffold(
        directive = navigator.scaffoldDirective,
        scaffoldState = navigator.scaffoldState,
        listPane = {
            AnimatedPane {
                LazyColumn {
                    itemsIndexed(messages) { index, message ->
                        ListItem(
                            headlineContent = { Text(message) },
                            colors = ListItemDefaults.colors(
                                containerColor = if (index == selected) MaterialTheme.colorScheme.secondaryContainer
                                else MaterialTheme.colorScheme.surface,
                            ),
                            modifier = Modifier.clickable {
                                scope.launch { navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, index) }
                            },
                        )
                    }
                }
            }
        },
        detailPane = {
            AnimatedPane {
                Column(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surfaceContainerLow).padding(16.dp)) {
                    // Only needed when the list is hidden (one pane).
                    if (navigator.canNavigateBack()) {
                        IconButton(onClick = { scope.launch { navigator.navigateBack() } }) {
                            Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back")
                        }
                    }
                    Text(selected?.let { messages[it] } ?: "Pick a message", style = MaterialTheme.typography.titleLarge)
                }
            }
        },
    )
}

The steps:

  1. Create a navigator with rememberListDetailPaneScaffoldNavigator. The type argument is the key of an item, here an Int.
  2. Pass its scaffoldDirective and scaffoldState to ListDetailPaneScaffold.
  3. Wrap each pane's content in AnimatedPane.
  4. When the user picks an item, call navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, key).
  5. Read the open item from navigator.currentDestination?.contentKey.

navigateTo and navigateBack are suspend functions. Call them from rememberCoroutineScope().launch { }.

On a phone, give the detail pane a back button that calls navigator.navigateBack(). Show it only when navigator.canNavigateBack() is true. For the system back gesture, see the Adaptive layouts guide.

This is in a separate library: org.jetbrains.compose.material3.adaptive:adaptive-layout, plus adaptive-navigation for the navigator. It is experimental: add @OptIn(ExperimentalMaterial3AdaptiveApi::class).

With a valueExperimental

You say which panes show. For full control or tests.

@Composable
fun ListDetailPaneScaffold(
    directive: PaneScaffoldDirective,
    value: ThreePaneScaffoldValue,
    listPane: @Composable ThreePaneScaffoldPaneScope.() -> Unit,
    detailPane: @Composable ThreePaneScaffoldPaneScope.() -> Unit,
    modifier: Modifier = Modifier,
    extraPane: (@Composable ThreePaneScaffoldPaneScope.() -> Unit)? = null,
    paneExpansionDragHandle: (@Composable ThreePaneScaffoldScope.(PaneExpansionState) -> Unit)? = null,
    paneExpansionState: PaneExpansionState? = null,
)

directive: PaneScaffoldDirectiveRequired

How many panes fit and how much space goes between them. Pass navigator.scaffoldDirective. To make your own, see calculatePaneScaffoldDirective.

value: ThreePaneScaffoldValueRequired

Which panes show and which are hidden, as a fixed value. Usually you pass scaffoldState instead.

listPane: @Composable ThreePaneScaffoldPaneScope.() -> UnitRequired

The list. Wrap it in AnimatedPane { }.

detailPane: @Composable ThreePaneScaffoldPaneScope.() -> UnitRequired

The details of the open item. Wrap it in AnimatedPane { }. Show a hint like "Pick a message" when nothing is open.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

extraPane: (@Composable ThreePaneScaffoldPaneScope.() -> Unit)?Optional

Default: null

An optional third pane, for more about the detail, like attachments. It shows next to the detail on very wide windows, and replaces it on smaller ones.

paneExpansionDragHandle: (@Composable ThreePaneScaffoldScope.(PaneExpansionState) -> Unit)?OptionalSince 1.1

Default: null

A handle between the panes that the user drags to change their widths. Usually a VerticalDragHandle with Modifier.paneExpansionDraggable(...).

paneExpansionState: PaneExpansionState?OptionalSince 1.1

Default: null

Remembers where the user dragged the handle. Create it with rememberPaneExpansionState.

With a stateExperimental

Animates between layouts. Use this with a navigator.

@Composable
fun ListDetailPaneScaffold(
    directive: PaneScaffoldDirective,
    scaffoldState: ThreePaneScaffoldState,
    listPane: @Composable ThreePaneScaffoldPaneScope.() -> Unit,
    detailPane: @Composable ThreePaneScaffoldPaneScope.() -> Unit,
    modifier: Modifier = Modifier,
    extraPane: (@Composable ThreePaneScaffoldPaneScope.() -> Unit)? = null,
    paneExpansionDragHandle: (@Composable ThreePaneScaffoldScope.(PaneExpansionState) -> Unit)? = null,
    paneExpansionState: PaneExpansionState? = null,
)

scaffoldState: ThreePaneScaffoldStateRequiredSince 1.1

Which panes show, with animations between changes. Pass navigator.scaffoldState.

Same as above: directive, listPane, detailPane, modifier, extraPane, paneExpansionDragHandle, paneExpansionState.

Parts

See also