androidx.compose.material3.adaptive.layout

AnimatedPaneExperimental

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

A part of ListDetailPaneScaffold. See that page for an overview and examples.

The wrapper for the content of each pane. It animates the pane in and out when the layout changes, like when the window gets wider or the user opens an item. Use it inside the pane slots of ListDetailPaneScaffold and SupportingPaneScaffold only.

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)
                }
            }
        },
    )
}

ParametersExperimental

@Composable
fun <RoleT : PaneScaffoldRole, ScaffoldValueT : PaneScaffoldValue<RoleT>> ExtendedPaneScaffoldPaneScope<RoleT, ScaffoldValueT>.AnimatedPane(
    modifier: Modifier = Modifier,
    enterTransition: EnterTransition = motionDataProvider.calculateDefaultEnterTransition(paneRole),
    exitTransition: ExitTransition = motionDataProvider.calculateDefaultExitTransition(paneRole),
    boundsAnimationSpec: FiniteAnimationSpec<IntRect> = PaneMotionDefaults.AnimationSpec,
    dragToResizeHandle: (@Composable (DragToResizeState) -> Unit)? = null,
    content: (@Composable AnimatedPaneScope.() -> Unit),
)

enterTransition: EnterTransitionOptionalSince 1.1

Default: motionDataProvider.calculateDefaultEnterTransition(paneRole)

How the pane appears. The default slides and fades it in, depending on the layout change.

exitTransition: ExitTransitionOptionalSince 1.1

Default: motionDataProvider.calculateDefaultExitTransition(paneRole)

How the pane disappears.

boundsAnimationSpec: FiniteAnimationSpec<IntRect>OptionalSince 1.1

Default: PaneMotionDefaults.AnimationSpec

How the pane moves and resizes when the layout changes.

dragToResizeHandle: (@Composable (DragToResizeState) -> Unit)?OptionalSince 1.3

Default: null

A handle to resize the pane when it floats over the others, for example as a sheet.

content: (@Composable AnimatedPaneScope.() -> Unit)Required

What the pane shows.

Same as in ListDetailPaneScaffold: modifier.

Parts

See also