In iOS 18, using .highPriorityGesture
does not interfere with Button tap detection. However, on iOS 17 and earlier, setting a .highPriorityGesture
causes the Button's tap action to stop responding.
I am using .highPriorityGesture
in an attempt to support both tap and long-press gestures on a Button, which works as expected in iOS 18. However, the same implementation prevents taps on earlier versions.
Is using .highPriorityGesture
on a Button not recommended in this case? Or is this an issue specific to how .highPriorityGesture
behaves on iOS 17 and earlier?
Below is a sample code:
struct SampleButton: View {
let title: String
let action: () -> Void
var body: some View {
Button {
NSLog("Tapped")
action()
} label: {
Text(title)
}.highPriorityGesture(LongPressGesture(minimumDuration: 0.5).onEnded { _ in
NSLog("Long press.")
action()
})
}
}
struct ContentView: View {
var body: some View {
VStack {
SampleButton(title: "Tap or LongPress") {}
}
}
}
Environment:
- Xcode: Version 16.3 (16E140)
- iOS: iOS 18.4(simulator), iOS 17.5, iOS 16.4, iOS 15.2