aheze / SwipeActions

Add customizable swipe actions to any view.

Home Page:https://twitter.com/aheze0/status/1646399867764510721

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

aheze opened this issue · comments

Happens occasionally - the swipe view gets stuck.

View more details...

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

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.

BounceBack.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

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.