@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.9-1
Sign up to get free protection for your applications and to get access to all the features.
- package/harmony/gesture_handler/BuildProfile.ets +6 -0
- package/harmony/gesture_handler/build-profile.json5 +18 -7
- package/harmony/gesture_handler/hvigorfile.ts +2 -2
- package/harmony/gesture_handler/index.ets +3 -3
- package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
- package/harmony/gesture_handler/oh-package.json5 +12 -11
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +103 -34
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -15
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +27 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -17
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -12
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +72 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +123 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
- package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +42 -42
- package/harmony/gesture_handler/src/main/ets/Event.ts +67 -67
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +52 -37
- package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerArkUIAdapter.ets → GestureHandlerArkUIAdapter.ts} +202 -201
- package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +44 -44
- package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +280 -280
- package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +22 -22
- package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +27 -27
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +108 -108
- package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +182 -182
- package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +114 -114
- package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +33 -33
- package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +327 -327
- package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +239 -239
- package/harmony/gesture_handler/src/main/ets/RNGHError.ts +4 -4
- package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +47 -28
- package/harmony/gesture_handler/src/main/ets/{RNGHRootTouchHandler.ets → RNGHRootTouchHandlerArkTS.ts} +59 -57
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +87 -0
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +37 -36
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +183 -125
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +52 -55
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +23 -11
- package/harmony/gesture_handler/src/main/ets/State.ts +46 -46
- package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +205 -205
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +36 -36
- package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +98 -98
- package/harmony/gesture_handler/src/main/ets/View.ts +70 -70
- package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +42 -42
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +140 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +101 -0
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +3 -0
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
- package/harmony/gesture_handler/src/main/ets/types.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
- package/harmony/gesture_handler/src/main/module.json5 +7 -7
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +7 -7
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +15 -15
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/gesture_handler/ts.ts +2 -1
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js +6 -3
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +5 -13
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +31 -28
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +42 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +10 -0
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +11 -0
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
- package/lib/module/RNGestureHandlerModule.js +3 -2
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js +3 -11
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js +20 -19
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js +6 -14
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js +3 -0
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js +3 -0
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -6
- package/lib/typescript/RNGestureHandlerModule.d.ts.map +1 -1
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +9 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +15 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +15 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +7 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -0
- package/package.json +66 -70
- package/src/RNGestureHandlerModule.ts +5 -6
- package/src/components/GestureHandlerRootView.tsx +23 -34
- package/src/handlers/createHandler.tsx +534 -535
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -0
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -0
- package/README.md +0 -1
- package/lib/commonjs/components/GestureButtons.js +0 -186
- package/lib/commonjs/components/GestureButtons.js.map +0 -1
- package/lib/commonjs/components/GestureHandlerButton.js +0 -9
- package/lib/commonjs/components/GestureHandlerButton.js.map +0 -1
- package/lib/commonjs/components/RNGestureHandlerButton.js +0 -23
- package/lib/commonjs/components/RNGestureHandlerButton.js.map +0 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +0 -247
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +0 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js +0 -58
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +0 -1
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js +0 -18
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +0 -1
- package/lib/commonjs/components/touchables/index.js +0 -21
- package/lib/commonjs/components/touchables/index.js.map +0 -1
- package/lib/commonjs/handlers/NativeViewGestureHandler.js +0 -19
- package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/PanGestureHandler.js +0 -103
- package/lib/commonjs/handlers/PanGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/TapGestureHandler.js +0 -22
- package/lib/commonjs/handlers/TapGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/createNativeWrapper.js +0 -64
- package/lib/commonjs/handlers/createNativeWrapper.js.map +0 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -22
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +0 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -554
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/commonjs/init.js +0 -24
- package/lib/commonjs/init.js.map +0 -1
- package/lib/module/components/GestureButtons.js +0 -168
- package/lib/module/components/GestureButtons.js.map +0 -1
- package/lib/module/components/GestureHandlerButton.js +0 -3
- package/lib/module/components/GestureHandlerButton.js.map +0 -1
- package/lib/module/components/RNGestureHandlerButton.js +0 -17
- package/lib/module/components/RNGestureHandlerButton.js.map +0 -1
- package/lib/module/components/touchables/GenericTouchable.js +0 -238
- package/lib/module/components/touchables/GenericTouchable.js.map +0 -1
- package/lib/module/components/touchables/TouchableOpacity.js +0 -49
- package/lib/module/components/touchables/TouchableOpacity.js.map +0 -1
- package/lib/module/components/touchables/TouchableWithoutFeedback.js +0 -9
- package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +0 -1
- package/lib/module/components/touchables/index.js +0 -8
- package/lib/module/components/touchables/index.js.map +0 -1
- package/lib/module/handlers/NativeViewGestureHandler.js +0 -12
- package/lib/module/handlers/NativeViewGestureHandler.js.map +0 -1
- package/lib/module/handlers/PanGestureHandler.js +0 -92
- package/lib/module/handlers/PanGestureHandler.js.map +0 -1
- package/lib/module/handlers/TapGestureHandler.js +0 -14
- package/lib/module/handlers/TapGestureHandler.js.map +0 -1
- package/lib/module/handlers/createNativeWrapper.js +0 -57
- package/lib/module/handlers/createNativeWrapper.js.map +0 -1
- package/lib/module/handlers/gestureHandlerCommon.js +0 -15
- package/lib/module/handlers/gestureHandlerCommon.js.map +0 -1
- package/lib/module/handlers/gestures/GestureDetector.js +0 -543
- package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/module/init.js +0 -17
- package/lib/module/init.js.map +0 -1
- package/lib/typescript/components/GestureButtons.d.ts +0 -122
- package/lib/typescript/components/GestureButtons.d.ts.map +0 -1
- package/lib/typescript/components/GestureHandlerButton.d.ts +0 -5
- package/lib/typescript/components/GestureHandlerButton.d.ts.map +0 -1
- package/lib/typescript/components/RNGestureHandlerButton.d.ts +0 -2
- package/lib/typescript/components/RNGestureHandlerButton.d.ts.map +0 -1
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +0 -68
- package/lib/typescript/components/touchables/GenericTouchable.d.ts.map +0 -1
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +0 -26
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +0 -1
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +0 -8
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts.map +0 -1
- package/lib/typescript/components/touchables/index.d.ts +0 -4
- package/lib/typescript/components/touchables/index.d.ts.map +0 -1
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +0 -29
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +0 -140
- package/lib/typescript/handlers/PanGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/TapGestureHandler.d.ts +0 -58
- package/lib/typescript/handlers/TapGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/createNativeWrapper.d.ts +0 -4
- package/lib/typescript/handlers/createNativeWrapper.d.ts.map +0 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -2
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts.map +0 -1
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -24
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts.map +0 -1
- package/lib/typescript/init.d.ts +0 -3
- package/lib/typescript/init.d.ts.map +0 -1
- package/src/components/GestureButtons.tsx +0 -334
- package/src/components/GestureHandlerButton.tsx +0 -5
- package/src/components/RNGestureHandlerButton.tsx +0 -23
- package/src/components/touchables/GenericTouchable.tsx +0 -301
- package/src/components/touchables/TouchableOpacity.tsx +0 -76
- package/src/components/touchables/TouchableWithoutFeedback.tsx +0 -14
- package/src/components/touchables/index.ts +0 -7
- package/src/handlers/NativeViewGestureHandler.ts +0 -55
- package/src/handlers/PanGestureHandler.ts +0 -327
- package/src/handlers/TapGestureHandler.ts +0 -95
- package/src/handlers/createNativeWrapper.tsx +0 -81
- package/src/handlers/gestureHandlerCommon.ts +0 -15
- package/src/handlers/gestures/GestureDetector.tsx +0 -823
- package/src/init.ts +0 -18
@@ -1,56 +1,53 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import {
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
55
|
-
}
|
1
|
+
import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
|
2
|
+
import { RNGestureHandlerRootView as RNC } from "./namespace/RNGestureHandlerRootView"
|
3
|
+
import { RNGHRootTouchHandlerArkTS as RNGHRootTouchHandler } from "./RNGHRootTouchHandlerArkTS"
|
4
|
+
import { RNGestureHandlerModule } from "./RNGestureHandlerModule"
|
5
|
+
|
6
|
+
|
7
|
+
export type RNGestureHandlerRootViewDescriptor = RNC.Descriptor
|
8
|
+
|
9
|
+
@Component
|
10
|
+
export struct RNGestureHandlerRootView {
|
11
|
+
static readonly NAME = RNC.NAME
|
12
|
+
ctx!: RNOHContext
|
13
|
+
tag: number = -1
|
14
|
+
@BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
|
15
|
+
@State descriptor: RNGestureHandlerRootViewDescriptor = {} as RNGestureHandlerRootViewDescriptor
|
16
|
+
private unsubscribes: (() => void)[] = []
|
17
|
+
private touchHandler: RNGHRootTouchHandler | undefined = undefined
|
18
|
+
|
19
|
+
aboutToAppear() {
|
20
|
+
const rnGestureHandlerModule = this.ctx.rnInstance.getTurboModule<RNGestureHandlerModule>(RNGestureHandlerModule.NAME)
|
21
|
+
const rootTag = this.ctx.descriptorRegistry.getDescriptorLineage(this.tag)[0].tag
|
22
|
+
this.touchHandler = new RNGHRootTouchHandler(rootTag, rnGestureHandlerModule.getViewRegistry(), rnGestureHandlerModule.getGestureHandlerRegistry(), rnGestureHandlerModule.getLogger())
|
23
|
+
this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerRootViewDescriptor>(this.tag))
|
24
|
+
this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
|
25
|
+
this.handleDescriptorChange(d as RNGestureHandlerRootViewDescriptor)
|
26
|
+
}))
|
27
|
+
}
|
28
|
+
|
29
|
+
aboutToDisappear() {
|
30
|
+
this.unsubscribes.forEach(unsubscribe => unsubscribe())
|
31
|
+
}
|
32
|
+
|
33
|
+
handleDescriptorChange(newDescriptor: RNGestureHandlerRootViewDescriptor) {
|
34
|
+
this.descriptor = newDescriptor
|
35
|
+
}
|
36
|
+
|
37
|
+
build() {
|
38
|
+
RNViewBase({ ctx: this.ctx, tag: this.tag }) {
|
39
|
+
ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
|
40
|
+
RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
|
41
|
+
})
|
42
|
+
Stack() {
|
43
|
+
}
|
44
|
+
.width("100%")
|
45
|
+
.height("100%")
|
46
|
+
.onTouch((e) => {
|
47
|
+
this.touchHandler?.handleTouch(e)
|
48
|
+
})
|
49
|
+
.hitTestBehavior(HitTestMode.Transparent)
|
50
|
+
|
51
|
+
}
|
52
|
+
}
|
56
53
|
}
|
@@ -1,11 +1,23 @@
|
|
1
|
-
import { RNInstance } from "rnoh/ts"
|
2
|
-
import { ScrollLocker } from "./GestureHandler"
|
3
|
-
|
4
|
-
export class
|
5
|
-
|
6
|
-
}
|
7
|
-
|
8
|
-
|
9
|
-
return this.rnInstance.blockComponentsGestures(viewTag)
|
10
|
-
}
|
11
|
-
}
|
1
|
+
import { RNInstance } from "@rnoh/react-native-openharmony/ts"
|
2
|
+
import { ScrollLocker } from "./GestureHandler"
|
3
|
+
|
4
|
+
export class RNOHScrollLockerArkTS implements ScrollLocker {
|
5
|
+
constructor(private rnInstance: RNInstance) {
|
6
|
+
}
|
7
|
+
|
8
|
+
lockScrollContainingViewTag(viewTag: number) {
|
9
|
+
return this.rnInstance.blockComponentsGestures(viewTag)
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
export class RNOHScrollLockerCAPI implements ScrollLocker {
|
14
|
+
constructor(private rnInstance: RNInstance) {
|
15
|
+
}
|
16
|
+
|
17
|
+
lockScrollContainingViewTag(viewTag: number) {
|
18
|
+
this.rnInstance.postMessageToCpp("RNGH::SET_NATIVE_RESPONDERS_BLOCK", { targetTag: viewTag, shouldBlock: true });
|
19
|
+
return () => {
|
20
|
+
this.rnInstance.postMessageToCpp("RNGH::SET_NATIVE_RESPONDERS_BLOCK", { targetTag: viewTag, shouldBlock: false });
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -1,47 +1,47 @@
|
|
1
|
-
export enum State {
|
2
|
-
/** This is the initial state of each handler and it goes into this state after it's done recognizing a gesture. */
|
3
|
-
UNDETERMINED,
|
4
|
-
|
5
|
-
/** A handler received some touches but for some reason didn't recognize them. For example, if a finger travels more
|
6
|
-
* distance than a defined maxDist property allows, then the handler won't become active but will fail instead.
|
7
|
-
* Afterwards, it's state will be reset to UNDETERMINED. */
|
8
|
-
FAILED,
|
9
|
-
|
10
|
-
/** Handler has started receiving touch stream but hasn't yet received enough data to either fail or activate. */
|
11
|
-
BEGAN,
|
12
|
-
|
13
|
-
/** The gesture recognizer has received a signal (possibly new touches or a command from the touch system controller)
|
14
|
-
* resulting in the cancellation of a continuous gesture. The gesture's state will become CANCELLED until it is
|
15
|
-
* finally reset to the initial state, UNDETERMINED. */
|
16
|
-
CANCELLED,
|
17
|
-
|
18
|
-
/** Handler has recognized a gesture. It will become and stay in the ACTIVE state until the gesture finishes
|
19
|
-
* (e.g. when user lifts the finger) or gets cancelled by the touch system. Under normal circumstances the state will
|
20
|
-
* then turn into END. In the case that a gesture is cancelled by the touch system, its state would then become
|
21
|
-
* CANCELLED. Learn about discrete and continuous handlers here to understand how long a handler can be kept in the
|
22
|
-
* ACTIVE state.
|
23
|
-
* */
|
24
|
-
ACTIVE,
|
25
|
-
|
26
|
-
/** The gesture recognizer has received touches signalling the end of a gesture. Its state will become END until it is
|
27
|
-
* reset to UNDETERMINED.
|
28
|
-
* */
|
29
|
-
END,
|
30
|
-
}
|
31
|
-
|
32
|
-
export function getStateName(state: State): string {
|
33
|
-
switch (state) {
|
34
|
-
case State.UNDETERMINED:
|
35
|
-
return "UNDETERMINED"
|
36
|
-
case State.FAILED:
|
37
|
-
return "FAILED"
|
38
|
-
case State.BEGAN:
|
39
|
-
return "BEGAN"
|
40
|
-
case State.CANCELLED:
|
41
|
-
return "CANCELLED"
|
42
|
-
case State.ACTIVE:
|
43
|
-
return "ACTIVE"
|
44
|
-
case State.END:
|
45
|
-
return "END"
|
46
|
-
}
|
1
|
+
export enum State {
|
2
|
+
/** This is the initial state of each handler and it goes into this state after it's done recognizing a gesture. */
|
3
|
+
UNDETERMINED,
|
4
|
+
|
5
|
+
/** A handler received some touches but for some reason didn't recognize them. For example, if a finger travels more
|
6
|
+
* distance than a defined maxDist property allows, then the handler won't become active but will fail instead.
|
7
|
+
* Afterwards, it's state will be reset to UNDETERMINED. */
|
8
|
+
FAILED,
|
9
|
+
|
10
|
+
/** Handler has started receiving touch stream but hasn't yet received enough data to either fail or activate. */
|
11
|
+
BEGAN,
|
12
|
+
|
13
|
+
/** The gesture recognizer has received a signal (possibly new touches or a command from the touch system controller)
|
14
|
+
* resulting in the cancellation of a continuous gesture. The gesture's state will become CANCELLED until it is
|
15
|
+
* finally reset to the initial state, UNDETERMINED. */
|
16
|
+
CANCELLED,
|
17
|
+
|
18
|
+
/** Handler has recognized a gesture. It will become and stay in the ACTIVE state until the gesture finishes
|
19
|
+
* (e.g. when user lifts the finger) or gets cancelled by the touch system. Under normal circumstances the state will
|
20
|
+
* then turn into END. In the case that a gesture is cancelled by the touch system, its state would then become
|
21
|
+
* CANCELLED. Learn about discrete and continuous handlers here to understand how long a handler can be kept in the
|
22
|
+
* ACTIVE state.
|
23
|
+
* */
|
24
|
+
ACTIVE,
|
25
|
+
|
26
|
+
/** The gesture recognizer has received touches signalling the end of a gesture. Its state will become END until it is
|
27
|
+
* reset to UNDETERMINED.
|
28
|
+
* */
|
29
|
+
END,
|
30
|
+
}
|
31
|
+
|
32
|
+
export function getStateName(state: State): string {
|
33
|
+
switch (state) {
|
34
|
+
case State.UNDETERMINED:
|
35
|
+
return "UNDETERMINED"
|
36
|
+
case State.FAILED:
|
37
|
+
return "FAILED"
|
38
|
+
case State.BEGAN:
|
39
|
+
return "BEGAN"
|
40
|
+
case State.CANCELLED:
|
41
|
+
return "CANCELLED"
|
42
|
+
case State.ACTIVE:
|
43
|
+
return "ACTIVE"
|
44
|
+
case State.END:
|
45
|
+
return "END"
|
46
|
+
}
|
47
47
|
}
|
@@ -1,206 +1,206 @@
|
|
1
|
-
import { GestureHandler, GestureHandlerDependencies } from "./GestureHandler"
|
2
|
-
import { AdaptedEvent, EventType } from "./Event"
|
3
|
-
import { State, getStateName } from "./State"
|
4
|
-
|
5
|
-
const DEFAULT_MAX_DURATION_MS = 500;
|
6
|
-
const DEFAULT_NUMBER_OF_TAPS = 1;
|
7
|
-
const DEFAULT_MAX_DELAY_MS = 500;
|
8
|
-
|
9
|
-
export class TapGestureHandler extends GestureHandler {
|
10
|
-
private startX = 0;
|
11
|
-
private startY = 0;
|
12
|
-
private offsetX = 0;
|
13
|
-
private offsetY = 0;
|
14
|
-
private lastX = 0;
|
15
|
-
private lastY = 0;
|
16
|
-
private maxNumberOfPointersSoFar = 0;
|
17
|
-
private numberOfTapsSoFar: number = 0;
|
18
|
-
private waitTimeout: number | undefined;
|
19
|
-
private delayTimeout: number | undefined;
|
20
|
-
|
21
|
-
constructor(deps: GestureHandlerDependencies) {
|
22
|
-
super({...deps, logger: deps.logger.cloneWithPrefix("TapGestureHandler")})
|
23
|
-
}
|
24
|
-
|
25
|
-
onPointerDown(event) {
|
26
|
-
this.tracker.addToTracker(event);
|
27
|
-
super.onPointerDown(event);
|
28
|
-
this.trySettingPosition(event);
|
29
|
-
this.lastX = event.x;
|
30
|
-
this.lastY = event.y;
|
31
|
-
this.updateState(event);
|
32
|
-
}
|
33
|
-
|
34
|
-
onAdditionalPointerAdd(event: AdaptedEvent): void {
|
35
|
-
super.onAdditionalPointerAdd(event);
|
36
|
-
this.tracker.addToTracker(event);
|
37
|
-
this.trySettingPosition(event);
|
38
|
-
|
39
|
-
this.offsetX += this.lastX - this.startX;
|
40
|
-
this.offsetY += this.lastY - this.startY;
|
41
|
-
|
42
|
-
this.lastX = this.tracker.getLastAvgX();
|
43
|
-
this.lastY = this.tracker.getLastAvgY();
|
44
|
-
|
45
|
-
this.startX = this.tracker.getLastAvgX();
|
46
|
-
this.startY = this.tracker.getLastAvgY();
|
47
|
-
|
48
|
-
this.updateState(event);
|
49
|
-
}
|
50
|
-
|
51
|
-
onPointerUp(event: AdaptedEvent): void {
|
52
|
-
super.onPointerUp(event);
|
53
|
-
this.lastX = this.tracker.getLastAvgX();
|
54
|
-
this.lastY = this.tracker.getLastAvgY();
|
55
|
-
|
56
|
-
this.tracker.removeFromTracker(event.pointerId);
|
57
|
-
|
58
|
-
this.updateState(event);
|
59
|
-
}
|
60
|
-
|
61
|
-
onAdditionalPointerRemove(event: AdaptedEvent): void {
|
62
|
-
super.onAdditionalPointerRemove(event);
|
63
|
-
this.tracker.removeFromTracker(event.pointerId);
|
64
|
-
|
65
|
-
this.offsetX += this.lastX - this.startX;
|
66
|
-
this.offsetY += this.lastY = this.startY;
|
67
|
-
|
68
|
-
this.lastX = this.tracker.getLastAvgX();
|
69
|
-
this.lastY = this.tracker.getLastAvgY();
|
70
|
-
|
71
|
-
this.startX = this.lastX;
|
72
|
-
this.startY = this.lastY;
|
73
|
-
|
74
|
-
this.updateState(event);
|
75
|
-
}
|
76
|
-
|
77
|
-
onPointerMove(event: AdaptedEvent): void {
|
78
|
-
this.trySettingPosition(event);
|
79
|
-
this.tracker.track(event);
|
80
|
-
|
81
|
-
this.lastX = this.tracker.getLastAvgX();
|
82
|
-
this.lastY = this.tracker.getLastAvgY();
|
83
|
-
|
84
|
-
this.updateState(event);
|
85
|
-
|
86
|
-
super.onPointerMove(event);
|
87
|
-
}
|
88
|
-
|
89
|
-
onPointerOutOfBounds(event: AdaptedEvent): void {
|
90
|
-
this.trySettingPosition(event);
|
91
|
-
this.tracker.track(event);
|
92
|
-
|
93
|
-
this.lastX = this.tracker.getLastAvgX();
|
94
|
-
this.lastY = this.tracker.getLastAvgY();
|
95
|
-
|
96
|
-
this.updateState(event);
|
97
|
-
|
98
|
-
super.onPointerOutOfBounds(event);
|
99
|
-
}
|
100
|
-
|
101
|
-
getDefaultConfig() {
|
102
|
-
return {}
|
103
|
-
}
|
104
|
-
|
105
|
-
private trySettingPosition(event: AdaptedEvent): void {
|
106
|
-
if (this.currentState !== State.UNDETERMINED) return;
|
107
|
-
this.offsetX = 0;
|
108
|
-
this.offsetY = 0;
|
109
|
-
this.startX = event.x;
|
110
|
-
this.startY = event.y;
|
111
|
-
}
|
112
|
-
|
113
|
-
private updateState(event: AdaptedEvent): void {
|
114
|
-
const logger = this.logger.cloneWithPrefix("updateState")
|
115
|
-
if (this.maxNumberOfPointersSoFar < this.tracker.getTrackedPointersCount()) {
|
116
|
-
this.maxNumberOfPointersSoFar = this.tracker.getTrackedPointersCount()
|
117
|
-
}
|
118
|
-
if (this.shouldFail()) {
|
119
|
-
logger.info("fail")
|
120
|
-
this.fail()
|
121
|
-
return;
|
122
|
-
}
|
123
|
-
switch (this.currentState) {
|
124
|
-
case State.UNDETERMINED:
|
125
|
-
if (event.eventType === EventType.DOWN) {
|
126
|
-
this.begin()
|
127
|
-
}
|
128
|
-
this.startTap();
|
129
|
-
break;
|
130
|
-
case State.BEGAN:
|
131
|
-
if (event.eventType === EventType.UP) {
|
132
|
-
logger.info("endTap")
|
133
|
-
this.endTap();
|
134
|
-
}
|
135
|
-
if (event.eventType === EventType.DOWN) {
|
136
|
-
this.startTap();
|
137
|
-
}
|
138
|
-
break;
|
139
|
-
default:
|
140
|
-
logger.info(`default case - currentState ${getStateName(this.currentState)}`)
|
141
|
-
break;
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
private shouldFail(): boolean {
|
146
|
-
const maxDeltaX = this.config.maxDeltaX ?? Number.MIN_SAFE_INTEGER
|
147
|
-
const maxDeltaY = this.config.maxDeltaY ?? Number.MIN_SAFE_INTEGER
|
148
|
-
const maxDistSq = this.config.maxDistSq ?? Number.MIN_SAFE_INTEGER
|
149
|
-
|
150
|
-
const dx = this.lastX - this.startX + this.offsetX;
|
151
|
-
if (
|
152
|
-
maxDeltaX !== Number.MIN_SAFE_INTEGER &&
|
153
|
-
Math.abs(dx) > maxDeltaX
|
154
|
-
) {
|
155
|
-
return true;
|
156
|
-
}
|
157
|
-
const dy = this.lastY - this.startY + this.offsetY;
|
158
|
-
if (
|
159
|
-
maxDeltaY !== Number.MIN_SAFE_INTEGER &&
|
160
|
-
Math.abs(dy) > maxDeltaY
|
161
|
-
) {
|
162
|
-
return true;
|
163
|
-
}
|
164
|
-
const distSq = dy * dy + dx * dx;
|
165
|
-
const result = maxDistSq !== Number.MIN_SAFE_INTEGER && distSq > maxDistSq
|
166
|
-
return result;
|
167
|
-
}
|
168
|
-
|
169
|
-
private startTap() {
|
170
|
-
this.clearTimeouts();
|
171
|
-
this.waitTimeout = setTimeout(() => this.fail(), this.config.maxDurationMs ?? DEFAULT_MAX_DURATION_MS);
|
172
|
-
}
|
173
|
-
|
174
|
-
private clearTimeouts() {
|
175
|
-
clearTimeout(this.waitTimeout);
|
176
|
-
clearTimeout(this.delayTimeout);
|
177
|
-
}
|
178
|
-
|
179
|
-
private endTap() {
|
180
|
-
this.clearTimeouts();
|
181
|
-
if (
|
182
|
-
++this.numberOfTapsSoFar === (this.config.numberOfTaps ?? DEFAULT_NUMBER_OF_TAPS) &&
|
183
|
-
this.maxNumberOfPointersSoFar >= (this.config.minNumberOfPointers ?? 0)
|
184
|
-
) {
|
185
|
-
this.activate();
|
186
|
-
} else {
|
187
|
-
this.delayTimeout = setTimeout(() => this.fail(), this.config.maxDelayMs ?? DEFAULT_MAX_DELAY_MS);
|
188
|
-
}
|
189
|
-
}
|
190
|
-
|
191
|
-
public activate(): void {
|
192
|
-
super.activate();
|
193
|
-
this.end();
|
194
|
-
}
|
195
|
-
|
196
|
-
protected onCancel() {
|
197
|
-
super.onCancel()
|
198
|
-
this.resetProgress()
|
199
|
-
}
|
200
|
-
|
201
|
-
protected resetProgress(): void {
|
202
|
-
this.clearTimeouts();
|
203
|
-
this.numberOfTapsSoFar = 0;
|
204
|
-
this.maxNumberOfPointersSoFar = 0;
|
205
|
-
}
|
1
|
+
import { GestureHandler, GestureHandlerDependencies } from "./GestureHandler"
|
2
|
+
import { AdaptedEvent, EventType } from "./Event"
|
3
|
+
import { State, getStateName } from "./State"
|
4
|
+
|
5
|
+
const DEFAULT_MAX_DURATION_MS = 500;
|
6
|
+
const DEFAULT_NUMBER_OF_TAPS = 1;
|
7
|
+
const DEFAULT_MAX_DELAY_MS = 500;
|
8
|
+
|
9
|
+
export class TapGestureHandler extends GestureHandler {
|
10
|
+
private startX = 0;
|
11
|
+
private startY = 0;
|
12
|
+
private offsetX = 0;
|
13
|
+
private offsetY = 0;
|
14
|
+
private lastX = 0;
|
15
|
+
private lastY = 0;
|
16
|
+
private maxNumberOfPointersSoFar = 0;
|
17
|
+
private numberOfTapsSoFar: number = 0;
|
18
|
+
private waitTimeout: number | undefined;
|
19
|
+
private delayTimeout: number | undefined;
|
20
|
+
|
21
|
+
constructor(deps: GestureHandlerDependencies) {
|
22
|
+
super({...deps, logger: deps.logger.cloneWithPrefix("TapGestureHandler")})
|
23
|
+
}
|
24
|
+
|
25
|
+
onPointerDown(event) {
|
26
|
+
this.tracker.addToTracker(event);
|
27
|
+
super.onPointerDown(event);
|
28
|
+
this.trySettingPosition(event);
|
29
|
+
this.lastX = event.x;
|
30
|
+
this.lastY = event.y;
|
31
|
+
this.updateState(event);
|
32
|
+
}
|
33
|
+
|
34
|
+
onAdditionalPointerAdd(event: AdaptedEvent): void {
|
35
|
+
super.onAdditionalPointerAdd(event);
|
36
|
+
this.tracker.addToTracker(event);
|
37
|
+
this.trySettingPosition(event);
|
38
|
+
|
39
|
+
this.offsetX += this.lastX - this.startX;
|
40
|
+
this.offsetY += this.lastY - this.startY;
|
41
|
+
|
42
|
+
this.lastX = this.tracker.getLastAvgX();
|
43
|
+
this.lastY = this.tracker.getLastAvgY();
|
44
|
+
|
45
|
+
this.startX = this.tracker.getLastAvgX();
|
46
|
+
this.startY = this.tracker.getLastAvgY();
|
47
|
+
|
48
|
+
this.updateState(event);
|
49
|
+
}
|
50
|
+
|
51
|
+
onPointerUp(event: AdaptedEvent): void {
|
52
|
+
super.onPointerUp(event);
|
53
|
+
this.lastX = this.tracker.getLastAvgX();
|
54
|
+
this.lastY = this.tracker.getLastAvgY();
|
55
|
+
|
56
|
+
this.tracker.removeFromTracker(event.pointerId);
|
57
|
+
|
58
|
+
this.updateState(event);
|
59
|
+
}
|
60
|
+
|
61
|
+
onAdditionalPointerRemove(event: AdaptedEvent): void {
|
62
|
+
super.onAdditionalPointerRemove(event);
|
63
|
+
this.tracker.removeFromTracker(event.pointerId);
|
64
|
+
|
65
|
+
this.offsetX += this.lastX - this.startX;
|
66
|
+
this.offsetY += this.lastY = this.startY;
|
67
|
+
|
68
|
+
this.lastX = this.tracker.getLastAvgX();
|
69
|
+
this.lastY = this.tracker.getLastAvgY();
|
70
|
+
|
71
|
+
this.startX = this.lastX;
|
72
|
+
this.startY = this.lastY;
|
73
|
+
|
74
|
+
this.updateState(event);
|
75
|
+
}
|
76
|
+
|
77
|
+
onPointerMove(event: AdaptedEvent): void {
|
78
|
+
this.trySettingPosition(event);
|
79
|
+
this.tracker.track(event);
|
80
|
+
|
81
|
+
this.lastX = this.tracker.getLastAvgX();
|
82
|
+
this.lastY = this.tracker.getLastAvgY();
|
83
|
+
|
84
|
+
this.updateState(event);
|
85
|
+
|
86
|
+
super.onPointerMove(event);
|
87
|
+
}
|
88
|
+
|
89
|
+
onPointerOutOfBounds(event: AdaptedEvent): void {
|
90
|
+
this.trySettingPosition(event);
|
91
|
+
this.tracker.track(event);
|
92
|
+
|
93
|
+
this.lastX = this.tracker.getLastAvgX();
|
94
|
+
this.lastY = this.tracker.getLastAvgY();
|
95
|
+
|
96
|
+
this.updateState(event);
|
97
|
+
|
98
|
+
super.onPointerOutOfBounds(event);
|
99
|
+
}
|
100
|
+
|
101
|
+
getDefaultConfig() {
|
102
|
+
return {}
|
103
|
+
}
|
104
|
+
|
105
|
+
private trySettingPosition(event: AdaptedEvent): void {
|
106
|
+
if (this.currentState !== State.UNDETERMINED) return;
|
107
|
+
this.offsetX = 0;
|
108
|
+
this.offsetY = 0;
|
109
|
+
this.startX = event.x;
|
110
|
+
this.startY = event.y;
|
111
|
+
}
|
112
|
+
|
113
|
+
private updateState(event: AdaptedEvent): void {
|
114
|
+
const logger = this.logger.cloneWithPrefix("updateState")
|
115
|
+
if (this.maxNumberOfPointersSoFar < this.tracker.getTrackedPointersCount()) {
|
116
|
+
this.maxNumberOfPointersSoFar = this.tracker.getTrackedPointersCount()
|
117
|
+
}
|
118
|
+
if (this.shouldFail()) {
|
119
|
+
logger.info("fail")
|
120
|
+
this.fail()
|
121
|
+
return;
|
122
|
+
}
|
123
|
+
switch (this.currentState) {
|
124
|
+
case State.UNDETERMINED:
|
125
|
+
if (event.eventType === EventType.DOWN) {
|
126
|
+
this.begin()
|
127
|
+
}
|
128
|
+
this.startTap();
|
129
|
+
break;
|
130
|
+
case State.BEGAN:
|
131
|
+
if (event.eventType === EventType.UP) {
|
132
|
+
logger.info("endTap")
|
133
|
+
this.endTap();
|
134
|
+
}
|
135
|
+
if (event.eventType === EventType.DOWN) {
|
136
|
+
this.startTap();
|
137
|
+
}
|
138
|
+
break;
|
139
|
+
default:
|
140
|
+
logger.info(`default case - currentState ${getStateName(this.currentState)}`)
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
private shouldFail(): boolean {
|
146
|
+
const maxDeltaX = this.config.maxDeltaX ?? Number.MIN_SAFE_INTEGER
|
147
|
+
const maxDeltaY = this.config.maxDeltaY ?? Number.MIN_SAFE_INTEGER
|
148
|
+
const maxDistSq = this.config.maxDistSq ?? Number.MIN_SAFE_INTEGER
|
149
|
+
|
150
|
+
const dx = this.lastX - this.startX + this.offsetX;
|
151
|
+
if (
|
152
|
+
maxDeltaX !== Number.MIN_SAFE_INTEGER &&
|
153
|
+
Math.abs(dx) > maxDeltaX
|
154
|
+
) {
|
155
|
+
return true;
|
156
|
+
}
|
157
|
+
const dy = this.lastY - this.startY + this.offsetY;
|
158
|
+
if (
|
159
|
+
maxDeltaY !== Number.MIN_SAFE_INTEGER &&
|
160
|
+
Math.abs(dy) > maxDeltaY
|
161
|
+
) {
|
162
|
+
return true;
|
163
|
+
}
|
164
|
+
const distSq = dy * dy + dx * dx;
|
165
|
+
const result = maxDistSq !== Number.MIN_SAFE_INTEGER && distSq > maxDistSq
|
166
|
+
return result;
|
167
|
+
}
|
168
|
+
|
169
|
+
private startTap() {
|
170
|
+
this.clearTimeouts();
|
171
|
+
this.waitTimeout = setTimeout(() => this.fail(), this.config.maxDurationMs ?? DEFAULT_MAX_DURATION_MS);
|
172
|
+
}
|
173
|
+
|
174
|
+
private clearTimeouts() {
|
175
|
+
clearTimeout(this.waitTimeout);
|
176
|
+
clearTimeout(this.delayTimeout);
|
177
|
+
}
|
178
|
+
|
179
|
+
private endTap() {
|
180
|
+
this.clearTimeouts();
|
181
|
+
if (
|
182
|
+
++this.numberOfTapsSoFar === (this.config.numberOfTaps ?? DEFAULT_NUMBER_OF_TAPS) &&
|
183
|
+
this.maxNumberOfPointersSoFar >= (this.config.minNumberOfPointers ?? 0)
|
184
|
+
) {
|
185
|
+
this.activate();
|
186
|
+
} else {
|
187
|
+
this.delayTimeout = setTimeout(() => this.fail(), this.config.maxDelayMs ?? DEFAULT_MAX_DELAY_MS);
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
public activate(): void {
|
192
|
+
super.activate();
|
193
|
+
this.end();
|
194
|
+
}
|
195
|
+
|
196
|
+
protected onCancel() {
|
197
|
+
super.onCancel()
|
198
|
+
this.resetProgress()
|
199
|
+
}
|
200
|
+
|
201
|
+
protected resetProgress(): void {
|
202
|
+
this.clearTimeouts();
|
203
|
+
this.numberOfTapsSoFar = 0;
|
204
|
+
this.maxNumberOfPointersSoFar = 0;
|
205
|
+
}
|
206
206
|
}
|