Hi, since the compose bom composeBom = “2024.02.00” version, the implementation has changed from `...
y
Hi, since the compose bom composeBom = “2024.02.00” version, the implementation has changed from
Copy code
val dismissState = rememberDismissState(
    confirmValueChange = {
        if (it == DismissValue.DismissedToStart) {
            onEventSent(ListContract.Event.DeleteAction(item))
            contentItems.remove(item)
        }
        true
    }
)
to
Copy code
val dismissState = rememberSwipeToDismissBoxState(
        confirmValueChange = {})

SwipeToDismissBox(
    state = dismissState,
but this generates me 2x event for swipe action. And I have to check aka
Copy code
val dismissState = rememberSwipeToDismissBoxState(
    confirmValueChange = {
        if (it == SwipeToDismissBoxValue.EndToStart && contentItems.contains(item)) {
            onEventSent(ListContract.Event.DeleteAction(item))
            contentItems.remove(item)
        }
        true
    }
)
I didn’t find much documentation on how to use it correctly except that for wearables there is onDismissed
Copy code
SwipeToDismissBox(
    state = state,
    onDismissed = {}
Could someone please help me how to do it correctly?
j
confirmValueChange
is just a callback to indicate whether the component is allowed to move to a certain state, it should not be used to perform actions. Use a
snapshotFlow
instead to listen for the state changes.
y
@jossiwolf do you mean something like this? Or how? LaunchedEffect(dismissState) { snapshotFlow { dismissState.currentValue } .collect { currentValue -> if (currentValue == SwipeToDismissBoxValue.EndToStart && contentItems.contains(item)) { onEventSent(ListContract.Event.DeleteAction(item)) contentItems.remove(item) } } } It seems strange to me to use it like that.
j
Yes, that's the recommended way.
❤️ 1
y
@jossiwolf thank you very much… 🙏🏻