I\'m trying to implement haptic feedback at the beginning of a tap for a Button in SwiftUI. Therefore I\'m trying to use simultaneousGesture, but I\'m sill struggling. I can\'t
I have a wrapper view that plays a haptic event, and then calls the action:
struct HapticButton: View {
let content: String
let action: () -> Void
init(_ content: String, _ action: @escaping () -> Void) {
self.content = content
self.action = action
}
var body: some View {
Button(content) {
HapticService.shared.play(event: .buttonTap)
self.action()
}
}
}
Used like:
HapticButton("Press me") { print("hello") } // plays haptic and prints