SwipeActions icon indicating copy to clipboard operation
SwipeActions copied to clipboard

Sometimes swipe gesture doesn't reset (when inside a scroll view / list)

Open aheze opened this issue 1 year ago • 5 comments

Happens occasionally - the swipe view gets stuck.

View more details...

Stuck between expanded/closed state with unwanted margin on the right

aheze avatar Apr 15 '23 06:04 aheze

Facing this with leadingActions specifically

heysaik avatar Apr 15 '23 22:04 heysaik

Workaround: just add a .id(UUID()) to SwipeView

I'm using it inside a List and it works

cristianbabin avatar Apr 21 '23 14:04 cristianbabin

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

Juhnkerg avatar Apr 21 '23 17:04 Juhnkerg

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.

Stuck between expanded/closed state with unwanted margin on the right

aheze avatar Apr 21 '23 17:04 aheze

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.

Juhnkerg avatar Apr 21 '23 20:04 Juhnkerg