@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.6-2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. package/harmony/gesture_handler/LICENSE +21 -0
  2. package/harmony/gesture_handler/OAT.xml +44 -0
  3. package/harmony/gesture_handler/README.OpenSource +11 -0
  4. package/harmony/gesture_handler/README.md +1 -0
  5. package/harmony/gesture_handler/build-profile.json5 +7 -7
  6. package/harmony/gesture_handler/hvigorfile.ts +2 -2
  7. package/harmony/gesture_handler/index.ets +2 -2
  8. package/harmony/gesture_handler/oh-package.json5 +13 -11
  9. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
  10. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +33 -33
  11. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +14 -14
  12. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +60 -60
  13. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +17 -17
  14. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +11 -11
  15. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +60 -60
  16. package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +42 -42
  17. package/harmony/gesture_handler/src/main/ets/Event.ts +67 -67
  18. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +37 -37
  19. package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
  20. package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ets +201 -201
  21. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +44 -44
  22. package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +280 -280
  23. package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +22 -22
  24. package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +27 -27
  25. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +108 -108
  26. package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +182 -182
  27. package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +114 -114
  28. package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +33 -33
  29. package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +327 -327
  30. package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +239 -239
  31. package/harmony/gesture_handler/src/main/ets/RNGHError.ts +4 -4
  32. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +28 -28
  33. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandler.ets +57 -57
  34. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +36 -36
  35. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +125 -125
  36. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +56 -55
  37. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +10 -10
  38. package/harmony/gesture_handler/src/main/ets/State.ts +46 -46
  39. package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +205 -205
  40. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +36 -36
  41. package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +98 -98
  42. package/harmony/gesture_handler/src/main/ets/View.ts +70 -70
  43. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +42 -42
  44. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
  45. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
  46. package/harmony/gesture_handler/src/main/module.json5 +6 -6
  47. package/harmony/gesture_handler/src/main/resources/base/element/color.json +7 -7
  48. package/harmony/gesture_handler/src/main/resources/base/element/string.json +15 -15
  49. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -5
  50. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +15 -15
  51. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +15 -15
  52. package/harmony/gesture_handler.har +0 -0
  53. package/lib/commonjs/components/touchables/GenericTouchable.js +9 -9
  54. package/lib/commonjs/components/touchables/TouchableOpacity.js +2 -2
  55. package/lib/commonjs/handlers/createNativeWrapper.js +6 -6
  56. package/lib/commonjs/handlers/gestures/GestureDetector.js +3 -3
  57. package/lib/module/components/touchables/GenericTouchable.js +9 -9
  58. package/lib/module/components/touchables/TouchableOpacity.js +2 -2
  59. package/lib/module/handlers/createNativeWrapper.js +6 -6
  60. package/lib/module/handlers/gestures/GestureDetector.js +3 -3
  61. package/package.json +70 -70
  62. package/src/RNGestureHandlerModule.ts +6 -6
  63. package/src/components/GestureButtons.tsx +334 -334
  64. package/src/components/GestureHandlerButton.tsx +5 -5
  65. package/src/components/GestureHandlerRootView.tsx +34 -34
  66. package/src/components/RNGestureHandlerButton.tsx +23 -23
  67. package/src/components/touchables/GenericTouchable.tsx +301 -301
  68. package/src/components/touchables/TouchableOpacity.tsx +76 -76
  69. package/src/components/touchables/TouchableWithoutFeedback.tsx +14 -14
  70. package/src/components/touchables/index.ts +7 -7
  71. package/src/handlers/NativeViewGestureHandler.ts +55 -55
  72. package/src/handlers/PanGestureHandler.ts +327 -327
  73. package/src/handlers/TapGestureHandler.ts +95 -95
  74. package/src/handlers/createHandler.tsx +535 -535
  75. package/src/handlers/createNativeWrapper.tsx +81 -81
  76. package/src/handlers/gestureHandlerCommon.ts +15 -15
  77. package/src/handlers/gestures/GestureDetector.tsx +823 -823
  78. package/src/index.ts +172 -172
  79. package/src/init.ts +18 -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,29 @@
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
- export class StandardRNGHLogger implements RNGHLogger {
10
- constructor(private rnohLogger: RNOHContext["logger"], private prefix: string) {
11
- }
12
-
13
- info(msg: string) {
14
- this.rnohLogger.info(`${this.prefix}::${msg}`)
15
- }
16
-
17
- cloneWithPrefix(prefix: string) {
18
- return new StandardRNGHLogger(this.rnohLogger, `${this.prefix}::${prefix}`)
19
- }
20
- }
21
-
22
- export class FakeRNGHLogger implements RNGHLogger {
23
- info(msg: string) {
24
- }
25
-
26
- cloneWithPrefix(prefix: string) {
27
- return new FakeRNGHLogger()
28
- }
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
+ export class StandardRNGHLogger implements RNGHLogger {
10
+ constructor(private rnohLogger: RNOHContext["logger"], private prefix: string) {
11
+ }
12
+
13
+ info(msg: string) {
14
+ this.rnohLogger.info(`${this.prefix}::${msg}`)
15
+ }
16
+
17
+ cloneWithPrefix(prefix: string) {
18
+ return new StandardRNGHLogger(this.rnohLogger, `${this.prefix}::${prefix}`)
19
+ }
20
+ }
21
+
22
+ export class FakeRNGHLogger implements RNGHLogger {
23
+ info(msg: string) {
24
+ }
25
+
26
+ cloneWithPrefix(prefix: string) {
27
+ return new FakeRNGHLogger()
28
+ }
29
29
  }
@@ -1,58 +1,58 @@
1
- import { Tag } from "rnoh"
2
- import { GestureHandlerRegistry } from "./GestureHandlerRegistry"
3
- import { GestureHandlerArkUIAdapter } from "./GestureHandlerArkUIAdapter"
4
- import { ViewRegistry } from "./ViewRegistry"
5
- import { RNGHLogger } from './RNGHLogger'
6
-
7
-
8
- export class RNGHRootTouchHandler {
9
- private adapterByViewTag: Map<number, GestureHandlerArkUIAdapter> = new Map() // TODO: remove an adapter when a view or gesture handler is removed
10
- private activeViewTags: number[] = []
11
- private viewRegistry: ViewRegistry
12
- private gestureHandlerRegistry: GestureHandlerRegistry
13
- private logger: RNGHLogger
14
- private rootTag: Tag
15
-
16
- constructor(rootTag: Tag, viewRegistry: ViewRegistry, gestureHandlerRegistry: GestureHandlerRegistry, logger: RNGHLogger) {
17
- this.rootTag = rootTag
18
- this.viewRegistry = viewRegistry
19
- this.gestureHandlerRegistry = gestureHandlerRegistry
20
- this.logger = logger
21
- }
22
-
23
- public handleTouch(e: TouchEvent) {
24
- if (e.type === TouchType.Down) {
25
- this.activeViewTags = []
26
- }
27
- for (const changedTouch of e.changedTouches) {
28
- const views = this.viewRegistry.getTouchableViewsAt({
29
- x: changedTouch.windowX,
30
- y: changedTouch.windowY
31
- }, this.rootTag)
32
- for (const view of views) {
33
- for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag())) {
34
- this.logger.info(`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`)
35
- if (!this.adapterByViewTag.has(view.getTag()))
36
- this.adapterByViewTag.set(view.getTag(), new GestureHandlerArkUIAdapter(handler, view, this.logger.cloneWithPrefix("ArkUIAdapter")))
37
- if (!this.activeViewTags.includes(view.getTag())) {
38
- const adapter = this.adapterByViewTag.get(view.getTag())
39
- if (adapter) {
40
- adapter.handleTouch(e)
41
- } else {
42
- console.warn("RNGH: Couldn't find adapter")
43
- }
44
- }
45
- if (e.type === TouchType.Down) {
46
- this.activeViewTags.push(view.getTag())
47
- }
48
- }
49
- }
50
- for (const viewTag of this.activeViewTags) {
51
- const adapter = this.adapterByViewTag.get(viewTag)
52
- if (adapter) {
53
- adapter.handleTouch(e)
54
- }
55
- }
56
- }
57
- }
1
+ import { Tag } from "rnoh"
2
+ import { GestureHandlerRegistry } from "./GestureHandlerRegistry"
3
+ import { GestureHandlerArkUIAdapter } from "./GestureHandlerArkUIAdapter"
4
+ import { ViewRegistry } from "./ViewRegistry"
5
+ import { RNGHLogger } from './RNGHLogger'
6
+
7
+
8
+ export class RNGHRootTouchHandler {
9
+ private adapterByViewTag: Map<number, GestureHandlerArkUIAdapter> = new Map() // TODO: remove an adapter when a view or gesture handler is removed
10
+ private activeViewTags: number[] = []
11
+ private viewRegistry: ViewRegistry
12
+ private gestureHandlerRegistry: GestureHandlerRegistry
13
+ private logger: RNGHLogger
14
+ private rootTag: Tag
15
+
16
+ constructor(rootTag: Tag, viewRegistry: ViewRegistry, gestureHandlerRegistry: GestureHandlerRegistry, logger: RNGHLogger) {
17
+ this.rootTag = rootTag
18
+ this.viewRegistry = viewRegistry
19
+ this.gestureHandlerRegistry = gestureHandlerRegistry
20
+ this.logger = logger
21
+ }
22
+
23
+ public handleTouch(e: TouchEvent) {
24
+ if (e.type === TouchType.Down) {
25
+ this.activeViewTags = []
26
+ }
27
+ for (const changedTouch of e.changedTouches) {
28
+ const views = this.viewRegistry.getTouchableViewsAt({
29
+ x: changedTouch.windowX,
30
+ y: changedTouch.windowY
31
+ }, this.rootTag)
32
+ for (const view of views) {
33
+ for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag())) {
34
+ this.logger.info(`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`)
35
+ if (!this.adapterByViewTag.has(view.getTag()))
36
+ this.adapterByViewTag.set(view.getTag(), new GestureHandlerArkUIAdapter(handler, view, this.logger.cloneWithPrefix("ArkUIAdapter")))
37
+ if (!this.activeViewTags.includes(view.getTag())) {
38
+ const adapter = this.adapterByViewTag.get(view.getTag())
39
+ if (adapter) {
40
+ adapter.handleTouch(e)
41
+ } else {
42
+ console.warn("RNGH: Couldn't find adapter")
43
+ }
44
+ }
45
+ if (e.type === TouchType.Down) {
46
+ this.activeViewTags.push(view.getTag())
47
+ }
48
+ }
49
+ }
50
+ for (const viewTag of this.activeViewTags) {
51
+ const adapter = this.adapterByViewTag.get(viewTag)
52
+ if (adapter) {
53
+ adapter.handleTouch(e)
54
+ }
55
+ }
56
+ }
57
+ }
58
58
  }