Skip to content

Disable swipe when no action added #31

Open
@zuinqstudio

Description

I have a reveal action to disclose hidden information in the cell. Once the hidden information is shown, there's no more action to perform, in this case I'd like to completely remove swipe effect; it'd be nice being able to disable it when the actions lists are empty.

Furthermore, I'm reusing the same composable in some scrollable rows, so in those cases I definitely need to disable swipe interactions in order for the horizontal scroll to work.

var unlocked by remember { mutableStateOf(false) }

val actions = mutableListOf<SwipeAction>()
if (!unlocked) {
    actions.add(
        SwipeAction(
            icon = {
                Column(
                    modifier = Modifier.padding(horizontal = 25.dp),
                    verticalArrangement = Arrangement.spacedBy(5.dp),
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {
                    Icon(painter = painterResource(R.drawable.ic_lock_open), contentDescription = "", tint = Primary)
                    Text(stringResource(id = R.string.reveal))
               }
            },
            background = Color.Transparent,
            onSwipe = {
                unlocked = true
            }
        )
    )
}

SwipeableActionsBox(
    endActions = actions,
    backgroundUntilSwipeThreshold = Color.Transparent,
    swipeThreshold = 80.dp,
    disabledWhenEmpty = true // <-- 
) {
        Row { ... }
}

(Very nice work by the way :) )

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions