Compose Component

SwipeToRevealCard

SwipeToReveal Material composable for Cards.

SwipeToRevealCardSample

@OptIn(ExperimentalWearMaterialApi::class)
@Composable
@Sampled
fun SwipeToRevealCardSample(swipeToDismissBoxState: SwipeToDismissBoxState) {
    val revealState = rememberRevealState()
    SwipeToRevealCard(
        revealState = revealState,
        modifier =
            Modifier.fillMaxWidth()
                // Use edgeSwipeToDismiss to allow SwipeToDismissBox to capture swipe events
                .edgeSwipeToDismiss(swipeToDismissBoxState),
        primaryAction = {
            SwipeToRevealPrimaryAction(
                revealState = revealState,
                icon = { Icon(SwipeToRevealDefaults.Delete, "Delete") },
                label = { Text("Delete") },
                onClick = { /* Add the click handler here */ },
            )
        },
        secondaryAction = {
            SwipeToRevealSecondaryAction(
                revealState = revealState,
                onClick = { /* Add the click handler here */ },
            ) {
                Icon(SwipeToRevealDefaults.MoreOptions, "More Options")
            }
        },
        undoPrimaryAction = {
            SwipeToRevealUndoAction(
                revealState = revealState,
                label = { Text("Undo") },
                onClick = { /* Add the undo handler for primary action */ },
            )
        },
        undoSecondaryAction = {
            SwipeToRevealUndoAction(
                revealState = revealState,
                label = { Text("Undo") },
                onClick = { /* Add the undo handler for secondary action */ },
            )
        },
        onFullSwipe = { /* Add the full swipe handler here */ },
    ) {
        AppCard(
            onClick = { /* Add the Card click handler */ },
            appName = { Text("App name") },
            appImage = {
                Icon(
                    painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
                    contentDescription = "airplane",
                    modifier =
                        Modifier.size(CardDefaults.AppImageSize)
                            .wrapContentSize(align = Alignment.Center),
                )
            },
            title = { Text("App Card") },
            time = { Text("now") },
            modifier =
                Modifier.semantics {
                    // Use custom actions to make the primary and secondary actions accessible
                    customActions =
                        listOf(
                            CustomAccessibilityAction("Delete") {
                                /* Add the primary action click handler here */
                                true
                            },
                            CustomAccessibilityAction("More Options") {
                                /* Add the secondary click handler here */
                                true
                            },
                        )
                },
        ) {
            Text("Basic card with Swipe to Reveal actions")
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: