SwipeActions
SwipeActions copied to clipboard
Sometimes swipe gesture doesn't reset (when inside a scroll view / list)
Facing this with leadingActions specifically
Workaround: just add a .id(UUID()) to SwipeView
I'm using it inside a List and it works
Workaround: just add a .id(UUID()) to SwipeView
I'm using it inside a List and it works
Could you please tell me more about it? I used the following code snippet, but it wouldn't work, swipe gesture doesn't reset.
SwipeView {
Container(title: "Basic")
} trailingActions: { _ in
SwipeAction("Tap Me!") {}
}.id(UUID())
Important information
Just making sure we're on the same page here: to return to the closed
state, just do context.state.wrappedValue = .closed
. No need to add a custom .id
or anything. Example:
SwipeView {
Text("Swipe to Trigger, Then Return")
.frame(maxWidth: .infinity)
.padding(.vertical, 32)
.background(Color.blue.opacity(0.1))
.cornerRadius(32)
} trailingActions: { context in
SwipeAction("Bounce Back") {
context.state.wrappedValue = .closed /// here!
}
.allowSwipeToTrigger()
}
.swipeActionWidth(140)
This works fine.
https://user-images.githubusercontent.com/49819455/233702091-a637f754-6a9a-48b5-acba-808aa98e05f9.mov
The actual problem
The problem in this issue is about the swipe view getting stuck midway between the expanded/closed state. I can't consistently reproduce this, but it seems to have something to do with scrolling.

The issue about the swipe view getting stuck midway between the expanded/closed state probably because of the swiftUI Gestures
. Using .allowsHitTesting() might help solve the problem.