Skip to content

Conversation

danieldaquino
Copy link

Summary

Currently, SwipeView has a drag gesture applied as a highPriorityGesture. It was found that in some cases it can cause unintended behaviour when combined with other gestures.

For example, when adding a long-press gesture to the SwipeView label, that long-press gesture does not get activated unless the user lifts their finger (at least this is the case on iOS 18.0)

This pull request makes the SwipeView drag gesture priority configurable.

Testing

Device: iPhone 16 simulator
SwipeActions: 33d99756c3112e1a07c1732e3cddc5ad5bd0c5f4 (This PR)
Steps:

  1. Create an example project with this code
import SwiftUI
import SwipeActions

struct ContentView: View {
    var body: some View {
        SwipeView(label: {
            LongPressView()
        }, leadingActions: { _ in
            Button(action: { print("hi") }, label: {
                Text("hello")
            })
        })
        .swipeDragGesturePriority(.high)
    }
}

struct LongPressView: View {
    @State private var isPressing = false
    @State private var pressed = false

    var body: some View {
        Text("Hold Me")
            .padding(pressed ? 40 : 20)
            .background(isPressing ? Color.red : Color.blue)
            .foregroundColor(.white)
            .cornerRadius(10)
            .onLongPressGesture(minimumDuration: 0.5, pressing: { pressing in
                withAnimation {
                    self.isPressing = pressing
                }
            }, perform: {
                // Action to perform after the long press is recognized
                withAnimation {
                    pressed.toggle()
                }
            })
            .sheet(isPresented: $pressed, content: {
                Text("Long press complete!")
            })
    }
}

#Preview {
    return ContentView()
}
  1. Try long-pressing the button — The long-press was only recognized when lifting a finger, which seems to match behavior when using a high priority gesture
  2. Change .swipeDragGesturePriority(.high) in the code with .swipeDragGesturePriority(.normal)
  3. Try long-pressing the button — The long-press was recognized without lifting a finger, which seems to match behavior when using a normal priority gesture
  4. Try swiping and ensure that capability is unaffected

Results: Works as expected.

Other notes

Please let me know if there are any questions, concerns, or suggestions.

Thank you!

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

Successfully merging this pull request may close these issues.

1 participant