you can detect press or long press while using focusable, like this:
import SwiftUI
struct TestView: View
{
@State var isFocused: Bool = false
var body: some View
{
Button(action: {
print("Clicked") // simple click
}, label: {
Text("Click Me")
})
.buttonStyle(PlainButtonStyle())
.focusable(true, onFocusChange: { focused in
self.isFocused = focused
})
// long press (hold for at least half a second)
.highPriorityGesture(
LongPressGesture(minimumDuration: 0.5)
.onEnded { _ in
print("Long Pressed ...")
}
)
// click
.onLongPressGesture(minimumDuration: 0.01, perform: {
print("Single Short Click Pressed ...")
})
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: