@react-native-oh-tpl/react-native-gesture-handler 2.12.9-1 → 2.14.1-2.14.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DrawerLayout/index.ts +2 -0
- package/Swipeable/index.ts +2 -0
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js +2 -3
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +15 -18
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +94 -137
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +1 -2
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +2 -3
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +2 -3
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js +12 -15
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js +10 -141
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/index.d.ts +42 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
- package/package.json +70 -66
- package/src/RNGestureHandlerModule.ts +4 -4
- package/src/components/GestureHandlerRootView.tsx +23 -23
- package/src/handlers/createHandler.tsx +534 -534
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
- package/harmony/gesture_handler/BuildProfile.ets +0 -6
- package/harmony/gesture_handler/build-profile.json5 +0 -19
- package/harmony/gesture_handler/hvigorfile.ts +0 -2
- package/harmony/gesture_handler/index.ets +0 -3
- package/harmony/gesture_handler/oh-package-lock.json5 +0 -18
- package/harmony/gesture_handler/oh-package.json5 +0 -12
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +0 -103
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -21
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +0 -36
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +0 -27
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +0 -32
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +0 -22
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +0 -15
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +0 -36
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -123
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +0 -25
- package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +0 -42
- package/harmony/gesture_handler/src/main/ets/Event.ts +0 -68
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
- package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +0 -663
- package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
- package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
- package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +0 -280
- package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +0 -22
- package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +0 -28
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
- package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +0 -182
- package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +0 -115
- package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +0 -34
- package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +0 -328
- package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +0 -239
- package/harmony/gesture_handler/src/main/ets/RNGHError.ts +0 -5
- package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +0 -38
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +0 -183
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +0 -53
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
- package/harmony/gesture_handler/src/main/ets/State.ts +0 -47
- package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +0 -206
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
- package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +0 -98
- package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
- package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +0 -140
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +0 -25
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +0 -101
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +0 -3
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
- package/harmony/gesture_handler/src/main/ets/types.ts +0 -25
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
- package/harmony/gesture_handler/src/main/module.json5 +0 -7
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
- package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +0 -5
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
- package/harmony/gesture_handler/ts.ts +0 -2
@@ -1,239 +0,0 @@
|
|
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,48 +0,0 @@
|
|
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
|
-
}
|
48
|
-
}
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import { Tag } from "@rnoh/react-native-openharmony/ts"
|
2
|
-
import { GestureHandlerRegistry } from "./GestureHandlerRegistry"
|
3
|
-
import { GestureHandlerArkUIAdapter } from "./GestureHandlerArkUIAdapter"
|
4
|
-
import { ViewRegistry } from "./ViewRegistry"
|
5
|
-
import { RNGHLogger } from './RNGHLogger'
|
6
|
-
import { TouchEvent, TouchType } from "./types"
|
7
|
-
|
8
|
-
|
9
|
-
export class RNGHRootTouchHandlerArkTS {
|
10
|
-
private adapterByViewTag: Map<number, GestureHandlerArkUIAdapter> = new Map() // TODO: remove an adapter when a view or gesture handler is removed
|
11
|
-
private activeViewTags: number[] = []
|
12
|
-
private viewRegistry: ViewRegistry
|
13
|
-
private gestureHandlerRegistry: GestureHandlerRegistry
|
14
|
-
private logger: RNGHLogger
|
15
|
-
private rootTag: Tag
|
16
|
-
|
17
|
-
constructor(rootTag: Tag, viewRegistry: ViewRegistry, gestureHandlerRegistry: GestureHandlerRegistry, logger: RNGHLogger) {
|
18
|
-
this.rootTag = rootTag
|
19
|
-
this.viewRegistry = viewRegistry
|
20
|
-
this.gestureHandlerRegistry = gestureHandlerRegistry
|
21
|
-
this.logger = logger
|
22
|
-
}
|
23
|
-
|
24
|
-
public handleTouch(touchEvent: any) {
|
25
|
-
const e = touchEvent as TouchEvent
|
26
|
-
if (e.type === TouchType.Down) {
|
27
|
-
this.activeViewTags = []
|
28
|
-
}
|
29
|
-
for (const changedTouch of e.changedTouches) {
|
30
|
-
const views = this.viewRegistry.getTouchableViewsAt({
|
31
|
-
x: changedTouch.windowX,
|
32
|
-
y: changedTouch.windowY
|
33
|
-
}, this.rootTag)
|
34
|
-
for (const view of views) {
|
35
|
-
for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag())) {
|
36
|
-
this.logger.info(`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`)
|
37
|
-
if (!this.adapterByViewTag.has(view.getTag()))
|
38
|
-
this.adapterByViewTag.set(view.getTag(), new GestureHandlerArkUIAdapter(handler, view, this.logger.cloneWithPrefix("ArkUIAdapter")))
|
39
|
-
if (!this.activeViewTags.includes(view.getTag())) {
|
40
|
-
const adapter = this.adapterByViewTag.get(view.getTag())
|
41
|
-
if (adapter) {
|
42
|
-
adapter.handleTouch(e)
|
43
|
-
} else {
|
44
|
-
console.warn("RNGH: Couldn't find adapter")
|
45
|
-
}
|
46
|
-
}
|
47
|
-
if (e.type === TouchType.Down) {
|
48
|
-
this.activeViewTags.push(view.getTag())
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
for (const viewTag of this.activeViewTags) {
|
53
|
-
const adapter = this.adapterByViewTag.get(viewTag)
|
54
|
-
if (adapter) {
|
55
|
-
adapter.handleTouch(e)
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
}
|
@@ -1,87 +0,0 @@
|
|
1
|
-
import { RNGHRootTouchHandlerArkTS } from "./RNGHRootTouchHandlerArkTS"
|
2
|
-
import { TouchEvent as TouchEventArkTS, TouchType, TouchObject } from "./types"
|
3
|
-
import { RNGHLogger } from "./RNGHLogger"
|
4
|
-
|
5
|
-
type RawTouchPoint = {
|
6
|
-
contactAreaHeight: number
|
7
|
-
contactAreaWidth: number
|
8
|
-
id: number
|
9
|
-
nodeX: number
|
10
|
-
nodeY: number
|
11
|
-
pressedTime: number
|
12
|
-
pressure: number
|
13
|
-
rawX: number
|
14
|
-
rawY: number
|
15
|
-
screenX: number
|
16
|
-
screenY: number
|
17
|
-
tiltX: number
|
18
|
-
tiltY: number
|
19
|
-
toolHeight: number
|
20
|
-
toolType: number
|
21
|
-
toolWidth: number
|
22
|
-
toolX: number
|
23
|
-
toolY: number
|
24
|
-
windowX: number
|
25
|
-
windowY: number
|
26
|
-
}
|
27
|
-
|
28
|
-
export type RawTouchEvent = {
|
29
|
-
action: number,
|
30
|
-
actionTouch: RawTouchPoint,
|
31
|
-
touchPoints: RawTouchPoint[],
|
32
|
-
sourceType: number,
|
33
|
-
timestamp: number
|
34
|
-
}
|
35
|
-
|
36
|
-
class TouchEvent {
|
37
|
-
constructor(private raw: RawTouchEvent) {
|
38
|
-
}
|
39
|
-
|
40
|
-
asTouchEventArkTS(): TouchEventArkTS {
|
41
|
-
const touchType = this.touchTypeFromAction(this.raw.action)
|
42
|
-
return {
|
43
|
-
type: this.touchTypeFromAction(this.raw.action),
|
44
|
-
touches: this.raw.touchPoints.map(tp => this.touchObjectFromTouchPoint(tp, touchType)),
|
45
|
-
changedTouches: [this.touchObjectFromTouchPoint(this.raw.actionTouch, touchType)],
|
46
|
-
timestamp: this.raw.timestamp
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
private touchTypeFromAction(action: number): TouchType {
|
51
|
-
switch (action) {
|
52
|
-
case 1:
|
53
|
-
return TouchType.Down
|
54
|
-
case 2:
|
55
|
-
return TouchType.Move
|
56
|
-
case 3:
|
57
|
-
return TouchType.Up
|
58
|
-
default:
|
59
|
-
return TouchType.Cancel
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
private touchObjectFromTouchPoint(touchPoint: RawTouchPoint, touchType: TouchType): TouchObject {
|
64
|
-
return {
|
65
|
-
id: touchPoint.id,
|
66
|
-
windowX: touchPoint.windowX,
|
67
|
-
windowY: touchPoint.windowY,
|
68
|
-
x: touchPoint.windowX,
|
69
|
-
y: touchPoint.windowY,
|
70
|
-
type: touchType
|
71
|
-
}
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
export class RNGHRootTouchHandlerCAPI {
|
76
|
-
private logger: RNGHLogger
|
77
|
-
|
78
|
-
constructor(logger: RNGHLogger, private touchHandlerArkTS: RNGHRootTouchHandlerArkTS) {
|
79
|
-
this.logger = logger.cloneWithPrefix("RNGHRootTouchHandlerCAPI")
|
80
|
-
}
|
81
|
-
|
82
|
-
handleTouch(rawTouchEvent: RawTouchEvent) {
|
83
|
-
this.logger.cloneWithPrefix("handleTouch").debug(JSON.stringify(rawTouchEvent))
|
84
|
-
this.touchHandlerArkTS.handleTouch(new TouchEvent(rawTouchEvent).asTouchEventArkTS())
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
@@ -1,38 +0,0 @@
|
|
1
|
-
import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
|
2
|
-
import { RNGestureHandlerButton as RNC } from "./namespace/RNGestureHandlerButton"
|
3
|
-
|
4
|
-
export type RNGestureHandlerButtonDescriptor = RNC.Descriptor
|
5
|
-
|
6
|
-
@Component
|
7
|
-
export struct RNGestureHandlerButton {
|
8
|
-
static readonly NAME = RNC.NAME
|
9
|
-
public ctx!: RNOHContext
|
10
|
-
public tag: number = -1
|
11
|
-
@BuilderParam public buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
|
12
|
-
|
13
|
-
@State private descriptor: RNGestureHandlerButtonDescriptor = {} as RNGestureHandlerButtonDescriptor
|
14
|
-
private unsubscribes: (() => void)[] = []
|
15
|
-
|
16
|
-
aboutToAppear() {
|
17
|
-
this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerButtonDescriptor>(this.tag))
|
18
|
-
this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
|
19
|
-
this.handleDescriptorChange(d as RNGestureHandlerButtonDescriptor)
|
20
|
-
}))
|
21
|
-
}
|
22
|
-
|
23
|
-
aboutToDisappear() {
|
24
|
-
this.unsubscribes.forEach(unsubscribe => unsubscribe())
|
25
|
-
}
|
26
|
-
|
27
|
-
handleDescriptorChange(newDescriptor: RNGestureHandlerButtonDescriptor) {
|
28
|
-
this.descriptor = newDescriptor
|
29
|
-
}
|
30
|
-
|
31
|
-
build() {
|
32
|
-
RNViewBase({ ctx: this.ctx, tag: this.tag }) {
|
33
|
-
ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
|
34
|
-
RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
|
35
|
-
})
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
@@ -1,183 +0,0 @@
|
|
1
|
-
import { TurboModule, TurboModuleContext, Tag } from '@rnoh/react-native-openharmony/ts';
|
2
|
-
// import { TM } from "rnoh/generated/ts"
|
3
|
-
import { GestureHandlerRegistry } from './GestureHandlerRegistry';
|
4
|
-
import { GestureHandlerFactory } from "./GestureHandlerFactory"
|
5
|
-
import { ViewRegistry } from './ViewRegistry';
|
6
|
-
import { RNGHLogger, StandardRNGHLogger, FakeRNGHLogger } from './RNGHLogger';
|
7
|
-
import {
|
8
|
-
EventDispatcher,
|
9
|
-
JSEventDispatcher,
|
10
|
-
AnimatedEventDispatcher,
|
11
|
-
ReanimatedEventDispatcher
|
12
|
-
} from './EventDispatcher'
|
13
|
-
import { RNOHScrollLockerArkTS, RNOHScrollLockerCAPI } from "./RNOHScrollLocker"
|
14
|
-
import { State } from './State';
|
15
|
-
import { RNGHRootTouchHandlerCAPI, RawTouchEvent } from "./RNGHRootTouchHandlerCAPI"
|
16
|
-
import { RNGHRootTouchHandlerArkTS } from './RNGHRootTouchHandlerArkTS';
|
17
|
-
|
18
|
-
export enum ActionType {
|
19
|
-
REANIMATED_WORKLET = 1,
|
20
|
-
NATIVE_ANIMATED_EVENT = 2,
|
21
|
-
JS_FUNCTION_OLD_API = 3,
|
22
|
-
JS_FUNCTION_NEW_API = 4,
|
23
|
-
}
|
24
|
-
|
25
|
-
|
26
|
-
export class RNGestureHandlerModule extends TurboModule {
|
27
|
-
// implements TM.RNGestureHandlerModule.Spec {
|
28
|
-
static NAME = "RNGestureHandlerModule"
|
29
|
-
|
30
|
-
private gestureHandlerRegistry = new GestureHandlerRegistry()
|
31
|
-
private gestureHandlerFactory: GestureHandlerFactory | undefined = undefined
|
32
|
-
private viewRegistry: ViewRegistry | undefined = undefined
|
33
|
-
private logger: RNGHLogger
|
34
|
-
private touchHandlerByRootTag = new Map<Tag, RNGHRootTouchHandlerCAPI>()
|
35
|
-
|
36
|
-
constructor(ctx: TurboModuleContext) {
|
37
|
-
super(ctx)
|
38
|
-
const debug = false
|
39
|
-
this.logger = debug ? new StandardRNGHLogger(ctx.logger, "RNGH") : new FakeRNGHLogger()
|
40
|
-
if (this.ctx.rnInstance.getArchitecture() === "C_API") {
|
41
|
-
this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::TOUCH_EVENT", (e: any) => {
|
42
|
-
this.onTouch(e)
|
43
|
-
})
|
44
|
-
this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::ROOT_CREATED", (rootTag: any) => {
|
45
|
-
this.onGHRootCreated(rootTag)
|
46
|
-
})
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
private onGHRootCreated(rootTag: Tag) {
|
51
|
-
this.touchHandlerByRootTag.set(rootTag, new RNGHRootTouchHandlerCAPI(this.logger, new RNGHRootTouchHandlerArkTS(rootTag, this.viewRegistry, this.gestureHandlerRegistry, this.logger)));
|
52
|
-
}
|
53
|
-
|
54
|
-
private onTouch(e: RawTouchEvent & { rootTag: Tag }) {
|
55
|
-
const touchHandler = this.touchHandlerByRootTag.get(e.rootTag)
|
56
|
-
if (touchHandler) {
|
57
|
-
touchHandler.handleTouch(e);
|
58
|
-
} else {
|
59
|
-
this.logger.info(`Couldn't find touch handler for root tag: ${e.rootTag}`)
|
60
|
-
}
|
61
|
-
|
62
|
-
}
|
63
|
-
|
64
|
-
public install() {
|
65
|
-
this.viewRegistry = new ViewRegistry(this.ctx.descriptorRegistry, this.ctx.componentManagerRegistry)
|
66
|
-
const scrollLocker = this.ctx.rnInstance.getArchitecture() === "ARK_TS" ? new RNOHScrollLockerArkTS(this.ctx.rnInstance) : new RNOHScrollLockerCAPI(this.ctx.rnInstance);
|
67
|
-
this.gestureHandlerFactory = new GestureHandlerFactory(this.logger, scrollLocker)
|
68
|
-
return true
|
69
|
-
}
|
70
|
-
|
71
|
-
public createGestureHandler(
|
72
|
-
handlerName: string,
|
73
|
-
handlerTag: number,
|
74
|
-
config: Readonly<Record<string, unknown>>
|
75
|
-
) {
|
76
|
-
if (!this.gestureHandlerFactory) {
|
77
|
-
this.ctx.logger.error("Trying to create a gesture handler before creating gesture handler factory")
|
78
|
-
return
|
79
|
-
}
|
80
|
-
const gestureHandler = this.gestureHandlerFactory.create(handlerName, handlerTag)
|
81
|
-
this.gestureHandlerRegistry.addGestureHandler(gestureHandler)
|
82
|
-
gestureHandler.updateGestureConfig(config)
|
83
|
-
}
|
84
|
-
|
85
|
-
public attachGestureHandler(
|
86
|
-
handlerTag: number,
|
87
|
-
viewTag: number,
|
88
|
-
actionType: ActionType
|
89
|
-
) {
|
90
|
-
const eventDispatcher = this.createEventDispatcher(actionType, viewTag)
|
91
|
-
if (!eventDispatcher) {
|
92
|
-
this.ctx.logger.error("RNGH: Couldn't create EventDispatcher")
|
93
|
-
return
|
94
|
-
}
|
95
|
-
const view = this.viewRegistry.getViewByTag(viewTag)
|
96
|
-
if (!view) {
|
97
|
-
this.ctx.logger.error(`RNGH: Couldn't attachGestureHandler to view ${viewTag}`)
|
98
|
-
return;
|
99
|
-
}
|
100
|
-
this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
|
101
|
-
this.gestureHandlerRegistry
|
102
|
-
.getGestureHandlerByHandlerTag(handlerTag)
|
103
|
-
.setEventDispatcher(eventDispatcher)
|
104
|
-
}
|
105
|
-
|
106
|
-
private createEventDispatcher(actionType: ActionType, viewTag: number): EventDispatcher | null {
|
107
|
-
switch (actionType) {
|
108
|
-
case ActionType.REANIMATED_WORKLET:
|
109
|
-
return new ReanimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('ReanimatedEventDispatcher'), viewTag)
|
110
|
-
case ActionType.NATIVE_ANIMATED_EVENT:
|
111
|
-
return new AnimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('AnimatedEventDispatcher'), viewTag)
|
112
|
-
case ActionType.JS_FUNCTION_OLD_API:
|
113
|
-
case ActionType.JS_FUNCTION_NEW_API:
|
114
|
-
return new JSEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('JSEventDispatcher'));
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
public updateGestureHandler(
|
119
|
-
handlerTag: number,
|
120
|
-
newConfig: Readonly<Record<string, unknown>>
|
121
|
-
) {
|
122
|
-
const gestureHandler = this.gestureHandlerRegistry.getGestureHandlerByHandlerTag(handlerTag)
|
123
|
-
gestureHandler.updateGestureConfig(newConfig)
|
124
|
-
}
|
125
|
-
|
126
|
-
public dropGestureHandler(handlerTag: number) {
|
127
|
-
this.warn("dropGestureHandler is not implemented")
|
128
|
-
}
|
129
|
-
|
130
|
-
public handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
|
131
|
-
this.warn("handleSetJSResponder is not implemented")
|
132
|
-
}
|
133
|
-
|
134
|
-
public handleClearJSResponder() {
|
135
|
-
this.warn("handleClearJSResponder is not implemented")
|
136
|
-
}
|
137
|
-
|
138
|
-
public flushOperations() {
|
139
|
-
this.warn("flushOperations is not implemented")
|
140
|
-
}
|
141
|
-
|
142
|
-
// -------------------------------------------------------------------------------------------------------------------
|
143
|
-
protected warn(message: string) {
|
144
|
-
this.ctx.logger.warn("RNGH: " + message)
|
145
|
-
}
|
146
|
-
|
147
|
-
public getGestureHandlerRegistry() {
|
148
|
-
return this.gestureHandlerRegistry
|
149
|
-
}
|
150
|
-
|
151
|
-
public getLogger() {
|
152
|
-
return this.logger
|
153
|
-
}
|
154
|
-
|
155
|
-
public getViewRegistry() {
|
156
|
-
if (!this.viewRegistry) {
|
157
|
-
this.logger.info("Tried to get viewRegistry before it was initialized")
|
158
|
-
throw new Error("Tried to get viewRegistry before it was initialized")
|
159
|
-
}
|
160
|
-
return this.viewRegistry
|
161
|
-
}
|
162
|
-
|
163
|
-
public setGestureHandlerState(handlerTag: number, newState: State) {
|
164
|
-
const handler = this.getGestureHandlerRegistry().getGestureHandlerByHandlerTag(handlerTag);
|
165
|
-
switch (newState) {
|
166
|
-
case State.ACTIVE:
|
167
|
-
handler.activate();
|
168
|
-
break;
|
169
|
-
case State.BEGAN:
|
170
|
-
handler.begin();
|
171
|
-
break;
|
172
|
-
case State.END:
|
173
|
-
handler.end();
|
174
|
-
break;
|
175
|
-
case State.FAILED:
|
176
|
-
handler.fail();
|
177
|
-
break;
|
178
|
-
case State.CANCELLED:
|
179
|
-
handler.cancel();
|
180
|
-
break;
|
181
|
-
}
|
182
|
-
}
|
183
|
-
}
|