@@ -2,7 +2,9 @@ import SwiftUI
22import SwiftUtil
33
44struct GestureAction {
5+ var onPress : ( ( ) -> Void ) ? = nil
56 var onTap : ( ( ) -> Void ) ? = nil
7+ var onDoubleTap : ( ( ) -> Void ) ? = nil
68 var onLongPress : ( ( Int ) -> Void ) ? = nil
79 var onSwipe : ( ( SwipeDirection ) -> Void ) ? = nil
810 var onSlide : ( ( Int ) -> Void ) ? = nil
@@ -36,6 +38,7 @@ struct KeyModifier: ViewModifier {
3638 let moveSize : CGFloat = 30
3739
3840 @State private var touchId = 0
41+ @State private var lastTouchTime : Date ?
3942 @State private var isPressed = false
4043 @State private var startLocation : CGPoint ?
4144 @State private var lastLocation : CGFloat ?
@@ -97,6 +100,7 @@ struct KeyModifier: ViewModifier {
97100 let bubbleHeight = height - rowGap
98101
99102 if !isPressed { // touch start
103+ let touchTime = Date ( )
100104 touchId = ( touchId + 1 ) & 0xFFFF
101105 let currentTouchId = touchId
102106 isPressed = true
@@ -128,6 +132,15 @@ struct KeyModifier: ViewModifier {
128132 }
129133 }
130134 }
135+ if let t = lastTouchTime, let onDoubleTap = action. onDoubleTap,
136+ touchTime. timeIntervalSince ( t) < 0.3
137+ {
138+ onDoubleTap ( )
139+ lastTouchTime = nil
140+ } else {
141+ action. onPress ? ( )
142+ lastTouchTime = touchTime
143+ }
131144 } else { // touch move
132145 let dx = value. location. x - ( startLocation? . x ?? 0 )
133146 let dy = value. location. y - ( startLocation? . y ?? 0 )
0 commit comments