forked from BoCupp-Microsoft/VirtualKeyboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGestureRecognizer.js
38 lines (32 loc) · 1.13 KB
/
GestureRecognizer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export default class GestureRecognizer extends EventTarget {
constructor() {
super()
this.pointerDownsSeenDuringTapInterval = 0
this.pointerUpsSeenDuringTapInterval = 0
this.watchingForTap = false
}
watch(element) {
element.addEventListener("pointerdown", this.handlePointerDown.bind(this))
element.addEventListener("pointerup", this.handlePointerUp.bind(this))
}
handlePointerDown(e) {
if (!this.watchingForTap) {
setTimeout(this.handleTimerElapsed.bind(this), 500)
this.watchingForTap = true
}
this.pointerDownsSeenDuringTapInterval++
}
handlePointerUp(e) {
this.pointerUpsSeenDuringTapInterval++
if (this.pointerDownsSeenDuringTapInterval == 3 &&
this.pointerUpsSeenDuringTapInterval == 3) {
console.log("threefingertap detected")
this.dispatchEvent(new CustomEvent("threefingertap"))
}
}
handleTimerElapsed() {
this.pointerDownsSeenDuringTapInterval = 0
this.pointerUpsSeenDuringTapInterval = 0
this.watchingForTap = false
}
}