Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable swipe when no action added #31

Open
zuinqstudio opened this issue Jun 21, 2024 · 0 comments
Open

Disable swipe when no action added #31

zuinqstudio opened this issue Jun 21, 2024 · 0 comments

Comments

@zuinqstudio
Copy link

zuinqstudio commented Jun 21, 2024

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 :) )

Repository owner deleted a comment from umardev500 Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant