@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.9
Sign up to get free protection for your applications and to get access to all the features.
- package/harmony/gesture_handler/BuildProfile.ets +5 -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 +17 -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 +78 -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,239 +1,239 @@
|
|
1
|
-
import VelocityTracker from './VelocityTracker';
|
2
|
-
import { TrackerElement, AdaptedEvent } from "./Event"
|
3
|
-
import { Vector2D } from './Vector2D';
|
4
|
-
|
5
|
-
const MAX_POINTERS = 20;
|
6
|
-
|
7
|
-
export class PointerTracker {
|
8
|
-
private velocityTracker = new VelocityTracker();
|
9
|
-
private trackedPointers: Map<number, TrackerElement> = new Map<
|
10
|
-
number,
|
11
|
-
TrackerElement
|
12
|
-
>();
|
13
|
-
|
14
|
-
private touchEventsIds: Map<number, number> = new Map<number, number>();
|
15
|
-
|
16
|
-
private lastMovedPointerId: number;
|
17
|
-
|
18
|
-
private cachedAverages: { x: number; y: number } = { x: 0, y: 0 };
|
19
|
-
|
20
|
-
public constructor() {
|
21
|
-
this.lastMovedPointerId = NaN;
|
22
|
-
|
23
|
-
for (let i = 0; i < MAX_POINTERS; ++i) {
|
24
|
-
this.touchEventsIds.set(i, NaN);
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
public addToTracker(event: AdaptedEvent): void {
|
29
|
-
if (this.trackedPointers.has(event.pointerId)) {
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
|
33
|
-
this.lastMovedPointerId = event.pointerId;
|
34
|
-
|
35
|
-
const newElement: TrackerElement = {
|
36
|
-
lastX: event.x,
|
37
|
-
lastY: event.y,
|
38
|
-
timeStamp: event.time,
|
39
|
-
velocityX: 0,
|
40
|
-
velocityY: 0,
|
41
|
-
};
|
42
|
-
|
43
|
-
this.trackedPointers.set(event.pointerId, newElement);
|
44
|
-
this.mapTouchEventId(event.pointerId);
|
45
|
-
|
46
|
-
this.cachedAverages = {
|
47
|
-
x: this.getLastAvgX(),
|
48
|
-
y: this.getLastAvgY(),
|
49
|
-
};
|
50
|
-
}
|
51
|
-
|
52
|
-
public removeFromTracker(pointerId: number): void {
|
53
|
-
this.trackedPointers.delete(pointerId);
|
54
|
-
this.removeMappedTouchId(pointerId);
|
55
|
-
}
|
56
|
-
|
57
|
-
public track(event: AdaptedEvent): void {
|
58
|
-
const element: TrackerElement = this.trackedPointers.get(
|
59
|
-
event.pointerId
|
60
|
-
) as TrackerElement;
|
61
|
-
|
62
|
-
if (!element) {
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
|
66
|
-
this.lastMovedPointerId = event.pointerId;
|
67
|
-
|
68
|
-
this.velocityTracker.add(event);
|
69
|
-
const [velocityX, velocityY] = this.velocityTracker.getVelocity();
|
70
|
-
|
71
|
-
element.velocityX = velocityX;
|
72
|
-
element.velocityY = velocityY;
|
73
|
-
|
74
|
-
element.lastX = event.x;
|
75
|
-
element.lastY = event.y;
|
76
|
-
|
77
|
-
this.trackedPointers.set(event.pointerId, element);
|
78
|
-
|
79
|
-
const avgX: number = this.getLastAvgX();
|
80
|
-
const avgY: number = this.getLastAvgY();
|
81
|
-
|
82
|
-
this.cachedAverages = {
|
83
|
-
x: avgX,
|
84
|
-
y: avgY,
|
85
|
-
};
|
86
|
-
}
|
87
|
-
|
88
|
-
//Mapping TouchEvents ID
|
89
|
-
private mapTouchEventId(id: number): void {
|
90
|
-
for (const [mappedId, touchId] of this.touchEventsIds) {
|
91
|
-
if (isNaN(touchId)) {
|
92
|
-
this.touchEventsIds.set(mappedId, id);
|
93
|
-
break;
|
94
|
-
}
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
private removeMappedTouchId(id: number): void {
|
99
|
-
const mappedId: number = this.getMappedTouchEventId(id);
|
100
|
-
if (!isNaN(mappedId)) {
|
101
|
-
this.touchEventsIds.set(mappedId, NaN);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
public getMappedTouchEventId(touchEventId: number): number {
|
106
|
-
for (const [key, value] of this.touchEventsIds.entries()) {
|
107
|
-
if (value === touchEventId) {
|
108
|
-
return key;
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
return NaN;
|
113
|
-
}
|
114
|
-
|
115
|
-
public getVelocity(pointerId: number) {
|
116
|
-
return new Vector2D({x: this.getVelocityX(pointerId), y: this.getVelocityY(pointerId)})
|
117
|
-
}
|
118
|
-
|
119
|
-
public getVelocityX(pointerId: number): number {
|
120
|
-
return this.trackedPointers.get(pointerId)?.velocityX as number;
|
121
|
-
}
|
122
|
-
public getVelocityY(pointerId: number): number {
|
123
|
-
return this.trackedPointers.get(pointerId)?.velocityY as number;
|
124
|
-
}
|
125
|
-
|
126
|
-
/**
|
127
|
-
* Returns X coordinate of last moved pointer
|
128
|
-
*/
|
129
|
-
public getLastX(): number;
|
130
|
-
|
131
|
-
/**
|
132
|
-
*
|
133
|
-
* @param pointerId
|
134
|
-
* Returns X coordinate of given pointer
|
135
|
-
*/
|
136
|
-
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
137
|
-
public getLastX(pointerId: number): number;
|
138
|
-
|
139
|
-
public getLastX(pointerId?: number): number {
|
140
|
-
if (pointerId !== undefined) {
|
141
|
-
return this.trackedPointers.get(pointerId)?.lastX as number;
|
142
|
-
} else {
|
143
|
-
return this.trackedPointers.get(this.lastMovedPointerId)?.lastX as number;
|
144
|
-
}
|
145
|
-
}
|
146
|
-
|
147
|
-
/**
|
148
|
-
* Returns Y coordinate of last moved pointer
|
149
|
-
*/
|
150
|
-
public getLastY(): number;
|
151
|
-
|
152
|
-
/**
|
153
|
-
*
|
154
|
-
* @param pointerId
|
155
|
-
* Returns Y coordinate of given pointer
|
156
|
-
*/
|
157
|
-
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
158
|
-
public getLastY(pointerId: number): number;
|
159
|
-
|
160
|
-
public getLastY(pointerId?: number): number {
|
161
|
-
if (pointerId !== undefined) {
|
162
|
-
return this.trackedPointers.get(pointerId)?.lastY as number;
|
163
|
-
} else {
|
164
|
-
return this.trackedPointers.get(this.lastMovedPointerId)?.lastY as number;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
public getLastAvgPos() {
|
169
|
-
return new Vector2D({x: this.getLastAvgX(), y: this.getLastAvgY()})
|
170
|
-
}
|
171
|
-
|
172
|
-
// Some handlers use these methods to send average values in native event.
|
173
|
-
// This may happen when pointers have already been removed from tracker (i.e. pointerup event).
|
174
|
-
// In situation when NaN would be sent as a response, we return cached value.
|
175
|
-
// That prevents handlers from crashing
|
176
|
-
public getLastAvgX(): number {
|
177
|
-
const avgX: number = this.getSumX() / this.trackedPointers.size;
|
178
|
-
return isNaN(avgX) ? this.cachedAverages.x : avgX;
|
179
|
-
}
|
180
|
-
public getLastAvgY(): number {
|
181
|
-
const avgY: number = this.getSumY() / this.trackedPointers.size;
|
182
|
-
return isNaN(avgY) ? this.cachedAverages.y : avgY;
|
183
|
-
}
|
184
|
-
public getSumX(ignoredPointer?: number): number {
|
185
|
-
let sumX = 0;
|
186
|
-
|
187
|
-
this.trackedPointers.forEach((value, key) => {
|
188
|
-
if (key !== ignoredPointer) {
|
189
|
-
sumX += value.lastX;
|
190
|
-
}
|
191
|
-
});
|
192
|
-
|
193
|
-
return sumX;
|
194
|
-
}
|
195
|
-
public getSumY(ignoredPointer?: number): number {
|
196
|
-
let sumY = 0;
|
197
|
-
|
198
|
-
this.trackedPointers.forEach((value, key) => {
|
199
|
-
if (key !== ignoredPointer) {
|
200
|
-
sumY += value.lastY;
|
201
|
-
}
|
202
|
-
});
|
203
|
-
|
204
|
-
return sumY;
|
205
|
-
}
|
206
|
-
public getTrackedPointersCount(): number {
|
207
|
-
return this.trackedPointers.size;
|
208
|
-
}
|
209
|
-
public getTrackedPointersID(): number[] {
|
210
|
-
const keys: number[] = [];
|
211
|
-
|
212
|
-
this.trackedPointers.forEach((_value, key) => {
|
213
|
-
keys.push(key);
|
214
|
-
});
|
215
|
-
|
216
|
-
return keys;
|
217
|
-
}
|
218
|
-
|
219
|
-
public getData(): Map<number, TrackerElement> {
|
220
|
-
return this.trackedPointers;
|
221
|
-
}
|
222
|
-
|
223
|
-
public resetTracker(): void {
|
224
|
-
this.velocityTracker.reset();
|
225
|
-
this.trackedPointers.clear();
|
226
|
-
this.lastMovedPointerId = NaN;
|
227
|
-
|
228
|
-
for (let i = 0; i < MAX_POINTERS; ++i) {
|
229
|
-
this.touchEventsIds.set(i, NaN);
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
public static shareCommonPointers(
|
234
|
-
stPointers: number[],
|
235
|
-
ndPointers: number[]
|
236
|
-
): boolean {
|
237
|
-
return stPointers.some((pointerId) => ndPointers.includes(pointerId));
|
238
|
-
}
|
239
|
-
}
|
1
|
+
import VelocityTracker from './VelocityTracker';
|
2
|
+
import { TrackerElement, AdaptedEvent } from "./Event"
|
3
|
+
import { Vector2D } from './Vector2D';
|
4
|
+
|
5
|
+
const MAX_POINTERS = 20;
|
6
|
+
|
7
|
+
export class PointerTracker {
|
8
|
+
private velocityTracker = new VelocityTracker();
|
9
|
+
private trackedPointers: Map<number, TrackerElement> = new Map<
|
10
|
+
number,
|
11
|
+
TrackerElement
|
12
|
+
>();
|
13
|
+
|
14
|
+
private touchEventsIds: Map<number, number> = new Map<number, number>();
|
15
|
+
|
16
|
+
private lastMovedPointerId: number;
|
17
|
+
|
18
|
+
private cachedAverages: { x: number; y: number } = { x: 0, y: 0 };
|
19
|
+
|
20
|
+
public constructor() {
|
21
|
+
this.lastMovedPointerId = NaN;
|
22
|
+
|
23
|
+
for (let i = 0; i < MAX_POINTERS; ++i) {
|
24
|
+
this.touchEventsIds.set(i, NaN);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
public addToTracker(event: AdaptedEvent): void {
|
29
|
+
if (this.trackedPointers.has(event.pointerId)) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
|
33
|
+
this.lastMovedPointerId = event.pointerId;
|
34
|
+
|
35
|
+
const newElement: TrackerElement = {
|
36
|
+
lastX: event.x,
|
37
|
+
lastY: event.y,
|
38
|
+
timeStamp: event.time,
|
39
|
+
velocityX: 0,
|
40
|
+
velocityY: 0,
|
41
|
+
};
|
42
|
+
|
43
|
+
this.trackedPointers.set(event.pointerId, newElement);
|
44
|
+
this.mapTouchEventId(event.pointerId);
|
45
|
+
|
46
|
+
this.cachedAverages = {
|
47
|
+
x: this.getLastAvgX(),
|
48
|
+
y: this.getLastAvgY(),
|
49
|
+
};
|
50
|
+
}
|
51
|
+
|
52
|
+
public removeFromTracker(pointerId: number): void {
|
53
|
+
this.trackedPointers.delete(pointerId);
|
54
|
+
this.removeMappedTouchId(pointerId);
|
55
|
+
}
|
56
|
+
|
57
|
+
public track(event: AdaptedEvent): void {
|
58
|
+
const element: TrackerElement = this.trackedPointers.get(
|
59
|
+
event.pointerId
|
60
|
+
) as TrackerElement;
|
61
|
+
|
62
|
+
if (!element) {
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
|
66
|
+
this.lastMovedPointerId = event.pointerId;
|
67
|
+
|
68
|
+
this.velocityTracker.add(event);
|
69
|
+
const [velocityX, velocityY] = this.velocityTracker.getVelocity();
|
70
|
+
|
71
|
+
element.velocityX = velocityX;
|
72
|
+
element.velocityY = velocityY;
|
73
|
+
|
74
|
+
element.lastX = event.x;
|
75
|
+
element.lastY = event.y;
|
76
|
+
|
77
|
+
this.trackedPointers.set(event.pointerId, element);
|
78
|
+
|
79
|
+
const avgX: number = this.getLastAvgX();
|
80
|
+
const avgY: number = this.getLastAvgY();
|
81
|
+
|
82
|
+
this.cachedAverages = {
|
83
|
+
x: avgX,
|
84
|
+
y: avgY,
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
//Mapping TouchEvents ID
|
89
|
+
private mapTouchEventId(id: number): void {
|
90
|
+
for (const [mappedId, touchId] of this.touchEventsIds) {
|
91
|
+
if (isNaN(touchId)) {
|
92
|
+
this.touchEventsIds.set(mappedId, id);
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
private removeMappedTouchId(id: number): void {
|
99
|
+
const mappedId: number = this.getMappedTouchEventId(id);
|
100
|
+
if (!isNaN(mappedId)) {
|
101
|
+
this.touchEventsIds.set(mappedId, NaN);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
public getMappedTouchEventId(touchEventId: number): number {
|
106
|
+
for (const [key, value] of this.touchEventsIds.entries()) {
|
107
|
+
if (value === touchEventId) {
|
108
|
+
return key;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
return NaN;
|
113
|
+
}
|
114
|
+
|
115
|
+
public getVelocity(pointerId: number) {
|
116
|
+
return new Vector2D({x: this.getVelocityX(pointerId), y: this.getVelocityY(pointerId)})
|
117
|
+
}
|
118
|
+
|
119
|
+
public getVelocityX(pointerId: number): number {
|
120
|
+
return this.trackedPointers.get(pointerId)?.velocityX as number;
|
121
|
+
}
|
122
|
+
public getVelocityY(pointerId: number): number {
|
123
|
+
return this.trackedPointers.get(pointerId)?.velocityY as number;
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Returns X coordinate of last moved pointer
|
128
|
+
*/
|
129
|
+
public getLastX(): number;
|
130
|
+
|
131
|
+
/**
|
132
|
+
*
|
133
|
+
* @param pointerId
|
134
|
+
* Returns X coordinate of given pointer
|
135
|
+
*/
|
136
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
137
|
+
public getLastX(pointerId: number): number;
|
138
|
+
|
139
|
+
public getLastX(pointerId?: number): number {
|
140
|
+
if (pointerId !== undefined) {
|
141
|
+
return this.trackedPointers.get(pointerId)?.lastX as number;
|
142
|
+
} else {
|
143
|
+
return this.trackedPointers.get(this.lastMovedPointerId)?.lastX as number;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Returns Y coordinate of last moved pointer
|
149
|
+
*/
|
150
|
+
public getLastY(): number;
|
151
|
+
|
152
|
+
/**
|
153
|
+
*
|
154
|
+
* @param pointerId
|
155
|
+
* Returns Y coordinate of given pointer
|
156
|
+
*/
|
157
|
+
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
158
|
+
public getLastY(pointerId: number): number;
|
159
|
+
|
160
|
+
public getLastY(pointerId?: number): number {
|
161
|
+
if (pointerId !== undefined) {
|
162
|
+
return this.trackedPointers.get(pointerId)?.lastY as number;
|
163
|
+
} else {
|
164
|
+
return this.trackedPointers.get(this.lastMovedPointerId)?.lastY as number;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
public getLastAvgPos() {
|
169
|
+
return new Vector2D({x: this.getLastAvgX(), y: this.getLastAvgY()})
|
170
|
+
}
|
171
|
+
|
172
|
+
// Some handlers use these methods to send average values in native event.
|
173
|
+
// This may happen when pointers have already been removed from tracker (i.e. pointerup event).
|
174
|
+
// In situation when NaN would be sent as a response, we return cached value.
|
175
|
+
// That prevents handlers from crashing
|
176
|
+
public getLastAvgX(): number {
|
177
|
+
const avgX: number = this.getSumX() / this.trackedPointers.size;
|
178
|
+
return isNaN(avgX) ? this.cachedAverages.x : avgX;
|
179
|
+
}
|
180
|
+
public getLastAvgY(): number {
|
181
|
+
const avgY: number = this.getSumY() / this.trackedPointers.size;
|
182
|
+
return isNaN(avgY) ? this.cachedAverages.y : avgY;
|
183
|
+
}
|
184
|
+
public getSumX(ignoredPointer?: number): number {
|
185
|
+
let sumX = 0;
|
186
|
+
|
187
|
+
this.trackedPointers.forEach((value, key) => {
|
188
|
+
if (key !== ignoredPointer) {
|
189
|
+
sumX += value.lastX;
|
190
|
+
}
|
191
|
+
});
|
192
|
+
|
193
|
+
return sumX;
|
194
|
+
}
|
195
|
+
public getSumY(ignoredPointer?: number): number {
|
196
|
+
let sumY = 0;
|
197
|
+
|
198
|
+
this.trackedPointers.forEach((value, key) => {
|
199
|
+
if (key !== ignoredPointer) {
|
200
|
+
sumY += value.lastY;
|
201
|
+
}
|
202
|
+
});
|
203
|
+
|
204
|
+
return sumY;
|
205
|
+
}
|
206
|
+
public getTrackedPointersCount(): number {
|
207
|
+
return this.trackedPointers.size;
|
208
|
+
}
|
209
|
+
public getTrackedPointersID(): number[] {
|
210
|
+
const keys: number[] = [];
|
211
|
+
|
212
|
+
this.trackedPointers.forEach((_value, key) => {
|
213
|
+
keys.push(key);
|
214
|
+
});
|
215
|
+
|
216
|
+
return keys;
|
217
|
+
}
|
218
|
+
|
219
|
+
public getData(): Map<number, TrackerElement> {
|
220
|
+
return this.trackedPointers;
|
221
|
+
}
|
222
|
+
|
223
|
+
public resetTracker(): void {
|
224
|
+
this.velocityTracker.reset();
|
225
|
+
this.trackedPointers.clear();
|
226
|
+
this.lastMovedPointerId = NaN;
|
227
|
+
|
228
|
+
for (let i = 0; i < MAX_POINTERS; ++i) {
|
229
|
+
this.touchEventsIds.set(i, NaN);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
public static shareCommonPointers(
|
234
|
+
stPointers: number[],
|
235
|
+
ndPointers: number[]
|
236
|
+
): boolean {
|
237
|
+
return stPointers.some((pointerId) => ndPointers.includes(pointerId));
|
238
|
+
}
|
239
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
export class RNGHError extends Error {
|
2
|
-
constructor(message: string) {
|
3
|
-
super("rnoh-gesture-handler: " + message)
|
4
|
-
}
|
1
|
+
export class RNGHError extends Error {
|
2
|
+
constructor(message: string) {
|
3
|
+
super("rnoh-gesture-handler: " + message)
|
4
|
+
}
|
5
5
|
}
|
@@ -1,29 +1,48 @@
|
|
1
|
-
import { RNOHContext } from "rnoh/ts"
|
2
|
-
|
3
|
-
export interface RNGHLogger {
|
4
|
-
info(msg: string): void
|
5
|
-
|
6
|
-
cloneWithPrefix(prefix: string): RNGHLogger
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
import { RNOHContext } from "@rnoh/react-native-openharmony/ts"
|
2
|
+
|
3
|
+
export interface RNGHLogger {
|
4
|
+
info(msg: string): void
|
5
|
+
|
6
|
+
cloneWithPrefix(prefix: string): RNGHLogger
|
7
|
+
|
8
|
+
debug(msg: string)
|
9
|
+
|
10
|
+
error(msg: string)
|
11
|
+
}
|
12
|
+
|
13
|
+
export class StandardRNGHLogger implements RNGHLogger {
|
14
|
+
constructor(private rnohLogger: RNOHContext["logger"], private prefix: string) {
|
15
|
+
}
|
16
|
+
|
17
|
+
error(msg: string) {
|
18
|
+
this.rnohLogger.error(`${this.prefix}::${msg}`)
|
19
|
+
}
|
20
|
+
|
21
|
+
info(msg: string) {
|
22
|
+
this.rnohLogger.info(`${this.prefix}::${msg}`)
|
23
|
+
}
|
24
|
+
|
25
|
+
debug(msg: string) {
|
26
|
+
this.rnohLogger.debug(`${this.prefix}::${msg}`)
|
27
|
+
}
|
28
|
+
|
29
|
+
cloneWithPrefix(prefix: string) {
|
30
|
+
return new StandardRNGHLogger(this.rnohLogger, `${this.prefix}::${prefix}`)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export class FakeRNGHLogger implements RNGHLogger {
|
35
|
+
info(msg: string) {
|
36
|
+
}
|
37
|
+
|
38
|
+
debug(msg: string) {
|
39
|
+
|
40
|
+
}
|
41
|
+
|
42
|
+
error(msg: string): void {
|
43
|
+
}
|
44
|
+
|
45
|
+
cloneWithPrefix(prefix: string) {
|
46
|
+
return new FakeRNGHLogger()
|
47
|
+
}
|
29
48
|
}
|