Skip to content

Commit 3c58b51

Browse files
committed
double tap shift
1 parent 1c0fe83 commit 3c58b51

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

uipanel/Key.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,13 @@ struct ShiftView: View {
301301
foreground: getNormalForeground(colorScheme),
302302
shadow: getShadow(colorScheme),
303303
action: GestureAction(
304-
onTap: {
304+
onPress: {
305305
virtualKeyboardView.setLayer(
306306
state == .normal ? "shift" : "default"
307307
)
308+
},
309+
onDoubleTap: {
310+
virtualKeyboardView.setLayer("shift", lock: true)
308311
}
309312
)
310313
)

uipanel/KeyModifier.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import SwiftUI
22
import SwiftUtil
33

44
struct 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

Comments
 (0)