@react-native-oh-tpl/react-native-gesture-handler 2.12.9-1 → 2.14.1-2.14.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/DrawerLayout/index.ts +2 -0
  2. package/Swipeable/index.ts +2 -0
  3. package/harmony/gesture_handler/BuildProfile.ets +15 -4
  4. package/harmony/gesture_handler/hvigorfile.ts +1 -1
  5. package/harmony/gesture_handler/index.ets +2 -2
  6. package/harmony/gesture_handler/oh-package-lock.json5 +4 -4
  7. package/harmony/gesture_handler/oh-package.json5 +4 -4
  8. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +64 -18
  9. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +3 -3
  10. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +2 -2
  11. package/harmony/gesture_handler/src/main/cpp/{RNGestureHandlerButtonComponentInstance.h → componentInstances/RNGestureHandlerButtonComponentInstance.h} +2 -2
  12. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +242 -0
  13. package/harmony/gesture_handler/src/main/ets/{GestureHandler.ts → core/GestureHandler.ts} +46 -25
  14. package/harmony/gesture_handler/src/main/ets/{GestureHandlerOrchestrator.ts → core/GestureHandlerOrchestrator.ts} +122 -67
  15. package/harmony/gesture_handler/src/main/ets/{GestureHandlerRegistry.ts → core/GestureHandlerRegistry.ts} +7 -0
  16. package/harmony/gesture_handler/src/main/ets/{Event.ts → core/IncomingEvent.ts} +30 -20
  17. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
  18. package/harmony/gesture_handler/src/main/ets/{OutgoingEvent.ts → core/OutgoingEvent.ts} +1 -1
  19. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
  20. package/harmony/gesture_handler/src/main/ets/{PointerTracker.ts → core/PointerTracker.ts} +4 -4
  21. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
  22. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
  23. package/harmony/gesture_handler/src/main/ets/{VelocityTracker.ts → core/VelocityTracker.ts} +13 -5
  24. package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
  25. package/harmony/gesture_handler/src/main/ets/core/index.ts +13 -0
  26. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  27. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
  28. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
  29. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
  30. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
  31. package/harmony/gesture_handler/src/main/ets/{NativeViewGestureHandler.ts → gesture-handlers/NativeViewGestureHandler.ts} +15 -15
  32. package/harmony/gesture_handler/src/main/ets/{PanGestureHandler.ts → gesture-handlers/PanGestureHandler.ts} +27 -13
  33. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
  34. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
  35. package/harmony/gesture_handler/src/main/ets/{TapGestureHandler.ts → gesture-handlers/TapGestureHandler.ts} +11 -11
  36. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  37. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  38. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +8 -9
  39. package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerButton.ts → components/RNGestureHandlerButton.ts} +35 -36
  40. package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerRootView.ts → components/RNGestureHandlerRootView.ts} +23 -23
  41. package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
  42. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -3
  43. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
  44. package/harmony/gesture_handler/src/main/ets/{GestureHandlerPackage.ts → rnoh/GestureHandlerPackage.ts} +4 -4
  45. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
  46. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
  47. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +108 -0
  48. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
  49. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerButton.ets → rnoh/RNGestureHandlerButton.ets} +3 -3
  50. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerModule.ts → rnoh/RNGestureHandlerModule.ts} +76 -27
  51. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerRootView.ets → rnoh/RNGestureHandlerRootView.ets} +3 -3
  52. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
  53. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
  54. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +134 -0
  55. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +95 -0
  56. package/harmony/gesture_handler/src/main/module.json5 +8 -6
  57. package/harmony/gesture_handler/ts.ts +2 -2
  58. package/harmony/gesture_handler.har +0 -0
  59. package/lib/commonjs/index.js +126 -141
  60. package/lib/commonjs/index.js.map +1 -1
  61. package/lib/module/index.js +13 -146
  62. package/lib/module/index.js.map +1 -1
  63. package/lib/typescript/index.d.ts +39 -1
  64. package/lib/typescript/index.d.ts.map +1 -1
  65. package/package.json +13 -10
  66. package/src/index.ts +140 -140
  67. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
  68. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -123
  69. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
  70. package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
  71. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
  72. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
  73. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
  74. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
  75. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
  76. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
  77. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
  78. package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
  79. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
  80. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
  81. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
  82. /package/harmony/gesture_handler/src/main/ets/{CircularBuffer.ts → core/CircularBuffer.ts} +0 -0
  83. /package/harmony/gesture_handler/src/main/ets/{LeastSquareSolver.ts → core/LeastSquareSolver.ts} +0 -0
  84. /package/harmony/gesture_handler/src/main/ets/{RNGHError.ts → core/RNGHError.ts} +0 -0
  85. /package/harmony/gesture_handler/src/main/ets/{State.ts → core/State.ts} +0 -0
  86. /package/harmony/gesture_handler/src/main/ets/{types.ts → rnoh/types.ts} +0 -0
@@ -25,89 +25,89 @@ export namespace RNGestureHandlerButton {
25
25
  rippleRadius?: number;
26
26
  touchSoundDisabled?: boolean;
27
27
  }
28
-
28
+
29
29
  export interface Props extends ViewBaseProps {}
30
-
30
+
31
31
  export interface State {}
32
-
32
+
33
33
  export interface RawProps extends ViewRawProps, DirectRawProps {}
34
-
34
+
35
35
  export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
36
36
  get exclusive() {
37
37
  return this.rawProps.exclusive ?? true;
38
38
  }
39
-
39
+
40
40
  get foreground() {
41
41
  return this.rawProps.foreground ?? false;
42
42
  }
43
-
43
+
44
44
  get borderless() {
45
45
  return this.rawProps.borderless ?? false;
46
46
  }
47
-
47
+
48
48
  get enabled() {
49
49
  return this.rawProps.enabled ?? true;
50
50
  }
51
-
51
+
52
52
  get rippleRadius() {
53
53
  return this.rawProps.rippleRadius ?? 0;
54
54
  }
55
-
55
+
56
56
  get touchSoundDisabled() {
57
57
  return this.rawProps.touchSoundDisabled ?? false;
58
58
  }
59
-
60
-
59
+
60
+
61
61
  get rippleColor() {
62
- if (this.rawProps.rippleColor) {
63
- return Color.fromColorValue(this.rawProps.rippleColor)
64
- } else {
65
- return new Color({ r: 0, g: 0, b: 0, a: 255})
66
- }
62
+ if (this.rawProps.rippleColor) {
63
+ return Color.fromColorValue(this.rawProps.rippleColor)
64
+ } else {
65
+ return new Color({ r: 0, g: 0, b: 0, a: 255})
66
+ }
67
67
  }
68
-
68
+
69
69
  }
70
70
 
71
71
  export type Descriptor = ComponentDescriptor<
72
- typeof NAME,
73
- Props,
74
- State,
75
- RawProps
72
+ typeof NAME,
73
+ Props,
74
+ State,
75
+ RawProps
76
76
  >;
77
-
77
+
78
78
  export class DescriptorWrapper extends ViewDescriptorWrapperBase<
79
- typeof NAME,
80
- Props,
81
- State,
82
- RawProps,
83
- PropsSelector
79
+ typeof NAME,
80
+ Props,
81
+ State,
82
+ RawProps,
83
+ PropsSelector
84
84
  > {
85
85
  protected createPropsSelector() {
86
86
  return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
87
87
  }
88
88
  }
89
-
89
+
90
90
  export interface EventPayloadByName {
91
91
  }
92
-
92
+
93
93
  export class EventEmitter {
94
94
  constructor(private rnInstance: RNInstance, private tag: Tag) {}
95
-
95
+
96
96
  emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
97
97
  this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
98
98
  }
99
99
  }
100
-
100
+
101
101
  export interface CommandArgvByName {
102
102
  }
103
-
103
+
104
104
  export class CommandReceiver {
105
105
  private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
106
106
  private cleanUp: (() => void) | undefined = undefined
107
-
107
+
108
108
  constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
109
109
  }
110
-
110
+
111
111
  subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
112
112
  if (!this.listenersByCommandName.has(commandName)) {
113
113
  this.listenersByCommandName.set(commandName, new Set())
@@ -124,7 +124,7 @@ export namespace RNGestureHandlerButton {
124
124
  }
125
125
  })
126
126
  }
127
-
127
+
128
128
  return () => {
129
129
  this.listenersByCommandName.get(commandName)?.delete(listener)
130
130
  if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
@@ -136,5 +136,4 @@ export namespace RNGestureHandlerButton {
136
136
  }
137
137
  }
138
138
  }
139
-
140
139
  }
@@ -18,57 +18,57 @@ export namespace RNGestureHandlerRootView {
18
18
 
19
19
  export interface DirectRawProps {
20
20
  }
21
-
21
+
22
22
  export interface Props extends ViewBaseProps {}
23
-
23
+
24
24
  export interface State {}
25
-
25
+
26
26
  export interface RawProps extends ViewRawProps, DirectRawProps {}
27
-
27
+
28
28
  export class PropsSelector extends ViewPropsSelector<Props, RawProps> {
29
-
29
+
30
30
  }
31
31
 
32
32
  export type Descriptor = ComponentDescriptor<
33
- typeof NAME,
34
- Props,
35
- State,
36
- RawProps
33
+ typeof NAME,
34
+ Props,
35
+ State,
36
+ RawProps
37
37
  >;
38
-
38
+
39
39
  export class DescriptorWrapper extends ViewDescriptorWrapperBase<
40
- typeof NAME,
41
- Props,
42
- State,
43
- RawProps,
44
- PropsSelector
40
+ typeof NAME,
41
+ Props,
42
+ State,
43
+ RawProps,
44
+ PropsSelector
45
45
  > {
46
46
  protected createPropsSelector() {
47
47
  return new PropsSelector(this.descriptor.props, this.descriptor.rawProps)
48
48
  }
49
49
  }
50
-
50
+
51
51
  export interface EventPayloadByName {
52
52
  }
53
-
53
+
54
54
  export class EventEmitter {
55
55
  constructor(private rnInstance: RNInstance, private tag: Tag) {}
56
-
56
+
57
57
  emit<TEventName extends keyof EventPayloadByName>(eventName: TEventName, payload: EventPayloadByName[TEventName]) {
58
58
  this.rnInstance.emitComponentEvent(this.tag, eventName, payload)
59
59
  }
60
60
  }
61
-
61
+
62
62
  export interface CommandArgvByName {
63
63
  }
64
-
64
+
65
65
  export class CommandReceiver {
66
66
  private listenersByCommandName = new Map<string, Set<(...args: any[]) => void>>()
67
67
  private cleanUp: (() => void) | undefined = undefined
68
-
68
+
69
69
  constructor(private componentCommandReceiver: RNComponentCommandReceiver, private tag: Tag) {
70
70
  }
71
-
71
+
72
72
  subscribe<TCommandName extends keyof CommandArgvByName>(commandName: TCommandName, listener: (argv: CommandArgvByName[TCommandName]) => void) {
73
73
  if (!this.listenersByCommandName.has(commandName)) {
74
74
  this.listenersByCommandName.set(commandName, new Set())
@@ -85,7 +85,7 @@ export namespace RNGestureHandlerRootView {
85
85
  }
86
86
  })
87
87
  }
88
-
88
+
89
89
  return () => {
90
90
  this.listenersByCommandName.get(commandName)?.delete(listener)
91
91
  if (this.listenersByCommandName.get(commandName)?.size ?? 0 === 0) {
@@ -0,0 +1,2 @@
1
+ export * from "./RNGestureHandlerButton"
2
+ export * from "./RNGestureHandlerRootView"
@@ -1,3 +1,2 @@
1
- export * from "./RNGestureHandlerButton"
2
- export * from "./RNGestureHandlerRootView"
3
- export * from "./RNGestureHandlerModule"
1
+ export * as RNC from "./components/ts"
2
+ export * as TM from "./RNGestureHandlerModule"
@@ -0,0 +1,240 @@
1
+ import { Point } from '@rnoh/react-native-openharmony/ts';
2
+ import {
3
+ GestureHandler,
4
+ IncomingEvent,
5
+ EventType,
6
+ PointerType,
7
+ TouchEventType,
8
+ Touch,
9
+ RNGHLogger,
10
+ View
11
+ } from '../core';
12
+ import { TouchEvent, TouchType, TouchObject } from './types';
13
+
14
+ export class GestureHandlerArkUIAdapter {
15
+ private activePointerIds = new Set<number>();
16
+ private pointersIdInBounds = new Set<number>();
17
+ private gestureHandlers = new Set<GestureHandler>();
18
+ private view: View;
19
+ private logger: RNGHLogger;
20
+
21
+ constructor(view: View, logger: RNGHLogger) {
22
+ this.logger = logger.cloneWithPrefix(`ArkUIAdapter(viewTag: ${view.getTag()})`)
23
+ this.view = view;
24
+ }
25
+
26
+ attachGestureHandler(gestureHandler: GestureHandler) {
27
+ this.gestureHandlers.add(gestureHandler)
28
+ }
29
+
30
+ handleTouch(e: TouchEvent) {
31
+ for (const changedTouch of e.changedTouches) {
32
+ if (this.shouldSkipTouch(changedTouch)) continue;
33
+ const wasInBounds = this.pointersIdInBounds.has(changedTouch.id);
34
+ const isInBounds = this.isInBounds({
35
+ x: changedTouch.windowX,
36
+ y: changedTouch.windowY,
37
+ });
38
+ this.logger.info(
39
+ `handleTouch: ${JSON.stringify({
40
+ type: changedTouch.type,
41
+ wasInBounds,
42
+ isInBounds,
43
+ })}`,
44
+ );
45
+ const adaptedEvent = this.adaptTouchEvent(e, changedTouch);
46
+ this.gestureHandlers.forEach(gh => {
47
+ switch (adaptedEvent.eventType) {
48
+ case EventType.DOWN:
49
+ gh.onPointerDown(adaptedEvent);
50
+ break;
51
+ case EventType.ADDITIONAL_POINTER_DOWN:
52
+ gh.onAdditionalPointerAdd(adaptedEvent);
53
+ break;
54
+ case EventType.UP:
55
+ gh.onPointerUp(adaptedEvent);
56
+ break;
57
+ case EventType.ADDITIONAL_POINTER_UP:
58
+ gh.onAdditionalPointerRemove(adaptedEvent);
59
+ break;
60
+ case EventType.MOVE:
61
+ if (!wasInBounds && !isInBounds)
62
+ gh.onPointerOutOfBounds(adaptedEvent);
63
+ else gh.onPointerMove(adaptedEvent);
64
+ break;
65
+ case EventType.ENTER:
66
+ gh.onPointerEnter(adaptedEvent);
67
+ break;
68
+ case EventType.OUT:
69
+ gh.onPointerOut(adaptedEvent);
70
+ break;
71
+ case EventType.CANCEL:
72
+ gh.onPointerCancel(adaptedEvent);
73
+ break;
74
+ }
75
+ })
76
+ }
77
+ }
78
+
79
+ private shouldSkipTouch(changedTouch: TouchObject): boolean {
80
+ return (
81
+ changedTouch.type === TouchType.Down &&
82
+ !this.isInBounds({
83
+ x: changedTouch.windowX,
84
+ y: changedTouch.windowY,
85
+ })
86
+ );
87
+ }
88
+
89
+ private adaptTouchEvent(
90
+ e: TouchEvent,
91
+ changedTouch: TouchObject,
92
+ ): IncomingEvent {
93
+ const xAbsolute = changedTouch.windowX;
94
+ const yAbsolute = changedTouch.windowY;
95
+
96
+ const eventType = this.mapTouchTypeToEventType(
97
+ changedTouch.type,
98
+ this.isInBounds({ x: xAbsolute, y: yAbsolute }),
99
+ changedTouch.id,
100
+ this.pointersIdInBounds.has(changedTouch.id),
101
+ );
102
+ this.logger.cloneWithPrefix("adaptTouchEvent").debug({ eventType, activePointersCount: this.activePointerIds.size })
103
+ this.updateIsInBoundsByPointerId(
104
+ changedTouch.type,
105
+ changedTouch.id,
106
+ xAbsolute,
107
+ yAbsolute,
108
+ );
109
+ this.updateActivePointers(changedTouch.type, changedTouch.id);
110
+ return {
111
+ x: xAbsolute,
112
+ y: yAbsolute,
113
+ offsetX: xAbsolute - this.view.getBoundingRect().x,
114
+ offsetY: yAbsolute - this.view.getBoundingRect().y,
115
+ pointerId: changedTouch.id,
116
+ eventType: eventType,
117
+ pointerType: PointerType.TOUCH,
118
+ buttons: 0,
119
+ time: e.timestamp,
120
+ allTouches: e.touches.map(touch => this.mapTouchObjectToTouch(touch)),
121
+ changedTouches: e.changedTouches.map(touch =>
122
+ this.mapTouchObjectToTouch(touch),
123
+ ),
124
+ touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type),
125
+ };
126
+ }
127
+
128
+ private updateIsInBoundsByPointerId(
129
+ touchType: TouchType,
130
+ pointerId: number,
131
+ x: number,
132
+ y: number,
133
+ ) {
134
+ switch (touchType) {
135
+ case TouchType.Down:
136
+ if (this.isInBounds({ x, y })) this.pointersIdInBounds.add(pointerId);
137
+ break;
138
+ case TouchType.Move:
139
+ if (this.isInBounds({ x, y })) this.pointersIdInBounds.add(pointerId);
140
+ else this.pointersIdInBounds.delete(pointerId);
141
+ break;
142
+ case TouchType.Up:
143
+ this.pointersIdInBounds.delete(pointerId);
144
+ break;
145
+ case TouchType.Cancel:
146
+ this.pointersIdInBounds.delete(pointerId);
147
+ break;
148
+ }
149
+ }
150
+
151
+ private isInBounds(point: Point): boolean {
152
+ const x = point.x;
153
+ const y = point.y;
154
+ const rect = this.view.getBoundingRect();
155
+ this.logger.cloneWithPrefix("isInBounds").debug({ rect })
156
+ const result =
157
+ x >= rect.x &&
158
+ x <= rect.x + rect.width &&
159
+ y >= rect.y &&
160
+ y <= rect.y + rect.height;
161
+ return result;
162
+ }
163
+
164
+ private updateActivePointers(touchType: TouchType, pointerId: number): void {
165
+ switch (touchType) {
166
+ case TouchType.Down:
167
+ this.activePointerIds.add(pointerId);
168
+ break;
169
+ case TouchType.Up:
170
+ this.activePointerIds.delete(pointerId);
171
+ break;
172
+ case TouchType.Cancel:
173
+ this.activePointerIds.clear();
174
+ break;
175
+ default:
176
+ return;
177
+ }
178
+ }
179
+
180
+ private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
181
+ return {
182
+ id: touchObject.id,
183
+ x: touchObject.x,
184
+ y: touchObject.y,
185
+ absoluteX: touchObject.windowX,
186
+ absoluteY: touchObject.windowY,
187
+ };
188
+ }
189
+
190
+ private mapTouchTypeToEventType(
191
+ touchType: TouchType,
192
+ isCurrentlyInBounds: boolean,
193
+ pointerId: number,
194
+ wasInBounds: boolean,
195
+ ): EventType {
196
+ /**
197
+ * If user manages to drag finger out of GestureHandlerRootView,
198
+ * we don't receive UP event.
199
+ */
200
+ let activePointersCount = this.activePointerIds.size
201
+ if (this.activePointerIds.has(pointerId)) {
202
+ activePointersCount--;
203
+ }
204
+
205
+ switch (touchType) {
206
+ case TouchType.Down:
207
+ if (activePointersCount > 0) return EventType.ADDITIONAL_POINTER_DOWN;
208
+ else return EventType.DOWN;
209
+ case TouchType.Up:
210
+ if (activePointersCount > 1) return EventType.ADDITIONAL_POINTER_UP;
211
+ else return EventType.UP;
212
+ case TouchType.Move:
213
+ if (isCurrentlyInBounds) {
214
+ return wasInBounds ? EventType.MOVE : EventType.ENTER;
215
+ } else {
216
+ return wasInBounds ? EventType.OUT : EventType.MOVE;
217
+ }
218
+ case TouchType.Cancel:
219
+ return EventType.CANCEL;
220
+ default:
221
+ console.error('RNGH', 'Unknown touchType:', touchType);
222
+ throw new Error('Unknown touchType');
223
+ }
224
+ }
225
+
226
+ private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
227
+ switch (touchType) {
228
+ case TouchType.Down:
229
+ return TouchEventType.DOWN;
230
+ case TouchType.Up:
231
+ return TouchEventType.UP;
232
+ case TouchType.Move:
233
+ return TouchEventType.MOVE;
234
+ case TouchType.Cancel:
235
+ return TouchEventType.CANCELLED;
236
+ default:
237
+ return TouchEventType.UNDETERMINED;
238
+ }
239
+ }
240
+ }
@@ -1,5 +1,5 @@
1
- import {RNPackage, TurboModuleContext, TurboModulesFactory} from '@rnoh/react-native-openharmony/ts';
2
- import type {TurboModule} from '@rnoh/react-native-openharmony/ts';
1
+ import {RNPackage, TurboModulesFactory} from "@rnoh/react-native-openharmony/ts";
2
+ import type {TurboModule, TurboModuleContext} from "@rnoh/react-native-openharmony/ts";
3
3
  import {RNGestureHandlerModule} from './RNGestureHandlerModule';
4
4
 
5
5
  class GestureHandlerTurboModulesFactory extends TurboModulesFactory {
@@ -11,7 +11,7 @@ class GestureHandlerTurboModulesFactory extends TurboModulesFactory {
11
11
  }
12
12
 
13
13
  hasTurboModule(name: string): boolean {
14
- return name === 'RNGestureHandlerModule';
14
+ return name === RNGestureHandlerModule.NAME;
15
15
  }
16
16
  }
17
17
 
@@ -19,4 +19,4 @@ export class GestureHandlerPackage extends RNPackage {
19
19
  createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
20
20
  return new GestureHandlerTurboModulesFactory(ctx);
21
21
  }
22
- }
22
+ }
@@ -0,0 +1,49 @@
1
+ import { RNOHContext } from '@rnoh/react-native-openharmony/ts';
2
+ import { RNGHLogger, RNGHLoggerMessage } from "../core"
3
+
4
+ export class StandardRNGHLogger implements RNGHLogger {
5
+ constructor(
6
+ private rnohLogger: RNOHContext['logger'],
7
+ private prefix: string,
8
+ ) {
9
+ }
10
+
11
+ error(msg: string) {
12
+ this.rnohLogger.error(`${this.prefix}::${msg}`);
13
+ }
14
+
15
+ info(msg: string) {
16
+ this.rnohLogger.info(`${this.prefix}::${msg}`);
17
+ }
18
+
19
+ debug(msg: RNGHLoggerMessage) {
20
+ this.rnohLogger.debug(`${this.prefix}::${this.stringifyMsg(msg)}`);
21
+ }
22
+
23
+ private stringifyMsg(msg: RNGHLoggerMessage): string {
24
+ if (typeof msg === "string") {
25
+ return msg
26
+ } else {
27
+ return JSON.stringify(msg)
28
+ }
29
+ }
30
+
31
+ cloneWithPrefix(prefix: string) {
32
+ return new StandardRNGHLogger(this.rnohLogger, `${this.prefix}::${prefix}`);
33
+ }
34
+ }
35
+
36
+ export class FakeRNGHLogger implements RNGHLogger {
37
+ info(msg: string) {
38
+ }
39
+
40
+ debug(msg: string) {
41
+ }
42
+
43
+ error(msg: string): void {
44
+ }
45
+
46
+ cloneWithPrefix(prefix: string) {
47
+ return new FakeRNGHLogger();
48
+ }
49
+ }
@@ -0,0 +1,71 @@
1
+ import { RNInstance } from '@rnoh/react-native-openharmony/ts';
2
+ import { OutgoingEventDispatcher, GestureStateChangeEvent, GestureUpdateEvent, GestureTouchEvent, RNGHLogger } from "../core"
3
+
4
+ export class JSEventDispatcher implements OutgoingEventDispatcher {
5
+ constructor(private rnInstance: RNInstance, private logger: RNGHLogger) {
6
+ }
7
+
8
+ public onGestureHandlerStateChange(event: GestureStateChangeEvent) {
9
+ this.logger.info(`onGestureHandlerStateChange`);
10
+ this.rnInstance.emitDeviceEvent('onGestureHandlerStateChange', event);
11
+ }
12
+
13
+ public onGestureHandlerEvent(
14
+ event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent,
15
+ ) {
16
+ this.logger.info(`onGestureHandlerEvent`);
17
+ this.rnInstance.emitDeviceEvent('onGestureHandlerEvent', event);
18
+ }
19
+ }
20
+
21
+ export class AnimatedEventDispatcher implements OutgoingEventDispatcher {
22
+ constructor(
23
+ private rnInstance: RNInstance,
24
+ private logger: RNGHLogger,
25
+ private viewTag: number,
26
+ ) {}
27
+
28
+ public onGestureHandlerStateChange(event: GestureStateChangeEvent) {
29
+ this.logger.info(`onGestureHandlerStateChange`);
30
+ this.rnInstance.emitDeviceEvent('onGestureHandlerStateChange', event);
31
+ }
32
+
33
+ public onGestureHandlerEvent(
34
+ event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent,
35
+ ) {
36
+ this.logger.info(`onGestureHandlerEvent`);
37
+ this.rnInstance.emitComponentEvent(
38
+ this.viewTag,
39
+ 'onGestureHandlerEvent',
40
+ event,
41
+ );
42
+ }
43
+ }
44
+
45
+ export class ReanimatedEventDispatcher implements OutgoingEventDispatcher {
46
+ constructor(
47
+ private rnInstance: RNInstance,
48
+ private logger: RNGHLogger,
49
+ private viewTag: number,
50
+ ) {}
51
+
52
+ public onGestureHandlerStateChange(event: GestureStateChangeEvent) {
53
+ this.logger.info(`onGestureHandlerStateChange`);
54
+ this.rnInstance.emitComponentEvent(
55
+ this.viewTag,
56
+ 'onGestureHandlerStateChange',
57
+ event,
58
+ );
59
+ }
60
+
61
+ public onGestureHandlerEvent(
62
+ event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent,
63
+ ) {
64
+ this.logger.info(`onGestureHandlerEvent`);
65
+ this.rnInstance.emitComponentEvent(
66
+ this.viewTag,
67
+ 'onGestureHandlerEvent',
68
+ event,
69
+ );
70
+ }
71
+ }