Swipe to dismiss

Reveals or triggers an action when an item is swiped sideways.

When to use

Use it for list items with one or two quick actions, such as archive and delete. The background content is revealed during the swipe and tells the user what will happen.

Swiping is a shortcut. Offer the same actions in a menu or on selection, because not everyone can swipe.

Playground

The interactive page has a playground with live property controls for this component and generated code.

Examples

Swipe to delete

var visible by remember { mutableStateOf(true) }
val state = rememberSwipeToDismissBoxState()

if (visible) {
    SwipeToDismissBox(
        state = state,
        onDismiss = { visible = false },
        backgroundContent = {
            Box(
                Modifier.fillMaxSize().background(MaterialTheme.colorScheme.errorContainer).padding(horizontal = 24.dp),
                contentAlignment = Alignment.CenterEnd,
            ) {
                Icon(Icons.Rounded.Delete, contentDescription = "Delete")
            }
        },
    ) {
        ListItem(headlineContent = { Text("Swipe to delete") })
    }
}

Parameters

NameTypeDefaultDescription
stateSwipeToDismissBoxStaterememberSwipeToDismissBoxState(). Exposes the direction and progress.
backgroundContent@Composable RowScope.() -> UnitDrawn behind the item during the swipe.
onDismiss(SwipeToDismissBoxValue) -> Unit{}Called when the item was swiped past the threshold.
enableDismissFromStartToEnd / EndToStartBooleantrueAllowed directions.

Guidelines

Do:

Don't:

Accessibility

Related components