mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Hello, mpv! 🎉
This commit is contained in:
48
Shared/Player/TapRecognizerViewModifier.swift
Normal file
48
Shared/Player/TapRecognizerViewModifier.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import SwiftUI
|
||||
|
||||
struct TapRecognizerViewModifier: ViewModifier {
|
||||
@State private var singleTapIsTaped: Bool = .init()
|
||||
|
||||
var tapSensitivity: Double
|
||||
var singleTapAction: () -> Void
|
||||
var doubleTapAction: () -> Void
|
||||
|
||||
init(tapSensitivity: Double, singleTapAction: @escaping () -> Void, doubleTapAction: @escaping () -> Void) {
|
||||
self.tapSensitivity = tapSensitivity
|
||||
self.singleTapAction = singleTapAction
|
||||
self.doubleTapAction = doubleTapAction
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content.gesture(simultaneouslyGesture)
|
||||
}
|
||||
|
||||
private var singleTapGesture: some Gesture {
|
||||
TapGesture(count: 1).onEnded {
|
||||
singleTapIsTaped = true
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + tapSensitivity) {
|
||||
if singleTapIsTaped {
|
||||
singleTapAction()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var doubleTapGesture: some Gesture {
|
||||
TapGesture(count: 2).onEnded {
|
||||
singleTapIsTaped = false
|
||||
doubleTapAction()
|
||||
}
|
||||
}
|
||||
|
||||
private var simultaneouslyGesture: some Gesture {
|
||||
singleTapGesture.simultaneously(with: doubleTapGesture)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func tapRecognizer(tapSensitivity: Double, singleTapAction: @escaping () -> Void, doubleTapAction: @escaping () -> Void) -> some View {
|
||||
modifier(TapRecognizerViewModifier(tapSensitivity: tapSensitivity, singleTapAction: singleTapAction, doubleTapAction: doubleTapAction))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user