androidx.compose.material3.adaptive.navigation

ThreePaneScaffoldNavigatorExperimental

Interface · from org.jetbrains.compose.material3.adaptive:adaptive-navigation:1.3.0

The navigator of a ListDetailPaneScaffold or SupportingPaneScaffold. It knows the window size, which pane is open, which item is open, and how to go back.

You call navigateTo when the user opens something and navigateBack for back. The scaffold follows.

The type argument T is the key of what is open, like an item ID. Use a type that can be saved, like Int or String, so it survives screen rotation.

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)
                }
            }
        },
    )
}
interface ThreePaneScaffoldNavigator<T>

How to get one

Use rememberListDetailPaneScaffoldNavigator or rememberSupportingPaneScaffoldNavigator.

Ready-made values and functions that return it

Properties

scaffoldDirective

val scaffoldDirective: PaneScaffoldDirective

How many panes fit in the window. Pass it to the scaffold's directive.

scaffoldStateSince 1.1

val scaffoldState: ThreePaneScaffoldState

Which panes show, with animations. Pass it to the scaffold's scaffoldState.

scaffoldValue

val scaffoldValue: ThreePaneScaffoldValue

Which panes show right now, without animation state.

currentDestination

val currentDestination: ThreePaneScaffoldDestinationItem<T>?

The open pane and its contentKey. null before anything was opened.

isDestinationHistoryAware

val isDestinationHistoryAware: Boolean

Whether back follows the full history, or only goes from detail to list.

Functions

peekPreviousScaffoldValueSince 1.1

fun peekPreviousScaffoldValue(
    backNavigationBehavior: BackNavigationBehavior = BackNavigationBehavior.PopUntilScaffoldValueChange,
): ThreePaneScaffoldValue

The panes that would show after going back, without going back.

fun navigateTo(
    pane: ThreePaneScaffoldRole,
    contentKey: T? = null,
)

Opens a pane, like ListDetailPaneScaffoldRole.Detail, with an optional key. A suspend function.

canNavigateBack

fun canNavigateBack(
    backNavigationBehavior: BackNavigationBehavior = BackNavigationBehavior.PopUntilScaffoldValueChange,
): Boolean

true if there is something to go back to. Use it to show or hide a back button.

fun navigateBack(
    backNavigationBehavior: BackNavigationBehavior = BackNavigationBehavior.PopUntilScaffoldValueChange,
): Boolean

Goes back. Returns false if there was nothing to go back to. A suspend function.

seekBackSince 1.1

fun seekBack(
    backNavigationBehavior: BackNavigationBehavior = BackNavigationBehavior.PopUntilScaffoldValueChange,
    fraction: Float = 1.0f,
)

Moves part of the way back, for a predictive back gesture. fraction goes from 0 to 1.