@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
@@ -1,53 +0,0 @@
1
- import { RNInstance } from "@rnoh/react-native-openharmony/ts"
2
- import { GestureStateChangeEvent, GestureUpdateEvent, GestureTouchEvent } from "./OutgoingEvent"
3
- import { RNGHLogger } from './RNGHLogger'
4
-
5
- export interface EventDispatcher {
6
- onGestureHandlerStateChange(event: GestureStateChangeEvent): void
7
- onGestureHandlerEvent(event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent): void
8
- }
9
-
10
- export class JSEventDispatcher implements EventDispatcher {
11
- constructor(private rnInstance: RNInstance, private logger: RNGHLogger) {
12
- }
13
-
14
- public onGestureHandlerStateChange(event: GestureStateChangeEvent) {
15
- this.logger.info(`onGestureHandlerStateChange`)
16
- this.rnInstance.emitDeviceEvent("onGestureHandlerStateChange", event)
17
- }
18
-
19
- public onGestureHandlerEvent(event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent) {
20
- this.logger.info(`onGestureHandlerEvent`)
21
- this.rnInstance.emitDeviceEvent("onGestureHandlerEvent", event)
22
- }
23
- }
24
-
25
- export class AnimatedEventDispatcher implements EventDispatcher {
26
- constructor(private rnInstance: RNInstance, private logger: RNGHLogger, private viewTag: number) {
27
- }
28
-
29
- public onGestureHandlerStateChange(event: GestureStateChangeEvent) {
30
- this.logger.info(`onGestureHandlerStateChange`)
31
- this.rnInstance.emitDeviceEvent("onGestureHandlerStateChange", event)
32
- }
33
-
34
- public onGestureHandlerEvent(event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent) {
35
- this.logger.info(`onGestureHandlerEvent`)
36
- this.rnInstance.emitComponentEvent(this.viewTag, "onGestureHandlerEvent", event)
37
- }
38
- }
39
-
40
- export class ReanimatedEventDispatcher implements EventDispatcher {
41
- constructor(private rnInstance: RNInstance, private logger: RNGHLogger, private viewTag: number) {
42
- }
43
-
44
- public onGestureHandlerStateChange(event: GestureStateChangeEvent) {
45
- this.logger.info(`onGestureHandlerStateChange`)
46
- this.rnInstance.emitComponentEvent(this.viewTag, "onGestureHandlerStateChange", event)
47
- }
48
-
49
- public onGestureHandlerEvent(event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent) {
50
- this.logger.info(`onGestureHandlerEvent`)
51
- this.rnInstance.emitComponentEvent(this.viewTag, "onGestureHandlerEvent", event)
52
- }
53
- }
@@ -1,203 +0,0 @@
1
- import { Point } from "@rnoh/react-native-openharmony/ts"
2
- import { GestureHandler } from "./GestureHandler"
3
- import { AdaptedEvent, EventType, PointerType, TouchEventType, Touch } from "./Event"
4
- import { View } from "./View"
5
- import { RNGHLogger } from "./RNGHLogger"
6
- import { TouchEvent, TouchType, TouchObject } from "./types"
7
-
8
- export class GestureHandlerArkUIAdapter {
9
- private activePointerIds = new Set<number>()
10
- private pointersIdInBounds = new Set<number>()
11
- private gestureHandler: GestureHandler
12
- private view: View
13
- private logger: RNGHLogger
14
-
15
- constructor(gestureHandler: GestureHandler, view: View, logger: RNGHLogger) {
16
- logger.info("constructor")
17
- this.gestureHandler = gestureHandler
18
- this.view = view
19
- this.logger = logger
20
- }
21
-
22
- handleTouch(e: TouchEvent) {
23
- for (const changedTouch of e.changedTouches) {
24
- if (this.shouldSkipTouch(changedTouch)) continue;
25
- const wasInBounds = this.pointersIdInBounds.has(changedTouch.id)
26
- const isInBounds = this.isInBounds({ x: changedTouch.windowX, y: changedTouch.windowY })
27
- this.logger.info(`handleTouch: ${JSON.stringify({ type: changedTouch.type, wasInBounds, isInBounds })}`)
28
- const adaptedEvent = this.adaptTouchEvent(e, changedTouch)
29
- switch (adaptedEvent.eventType) {
30
- case EventType.DOWN:
31
- this.gestureHandler.onPointerDown(adaptedEvent)
32
- break;
33
- case EventType.ADDITIONAL_POINTER_DOWN:
34
- this.gestureHandler.onAdditionalPointerAdd(adaptedEvent)
35
- break;
36
- case EventType.UP:
37
- this.gestureHandler.onPointerUp(adaptedEvent)
38
- break;
39
- case EventType.ADDITIONAL_POINTER_UP:
40
- this.gestureHandler.onAdditionalPointerRemove(adaptedEvent)
41
- break;
42
- case EventType.MOVE:
43
- if (!wasInBounds && !isInBounds)
44
- this.gestureHandler.onPointerOutOfBounds(adaptedEvent)
45
- else
46
- this.gestureHandler.onPointerMove(adaptedEvent)
47
- break;
48
- case EventType.ENTER:
49
- this.gestureHandler.onPointerEnter(adaptedEvent)
50
- break;
51
- case EventType.OUT:
52
- this.gestureHandler.onPointerOut(adaptedEvent)
53
- break;
54
- case EventType.CANCEL:
55
- this.gestureHandler.onPointerCancel(adaptedEvent)
56
- break;
57
- }
58
- }
59
- }
60
-
61
- private shouldSkipTouch(changedTouch: TouchObject): boolean {
62
- return changedTouch.type === TouchType.Down && !this.isInBounds({
63
- x: changedTouch.windowX,
64
- y: changedTouch.windowY
65
- })
66
- }
67
-
68
- private adaptTouchEvent(e: TouchEvent, changedTouch: TouchObject): AdaptedEvent {
69
- const xAbsolute = changedTouch.windowX
70
- const yAbsolute = changedTouch.windowY
71
-
72
- const eventType = this.mapTouchTypeToEventType(
73
- changedTouch.type,
74
- this.activePointerIds.size,
75
- this.isInBounds({ x: xAbsolute, y: yAbsolute }),
76
- this.pointersIdInBounds.has(changedTouch.id)
77
- )
78
- this.updateIsInBoundsByPointerId(
79
- changedTouch.type,
80
- changedTouch.id,
81
- xAbsolute,
82
- yAbsolute
83
- )
84
- this.updateActivePointers(changedTouch.type, changedTouch.id)
85
- return {
86
- x: xAbsolute,
87
- y: yAbsolute,
88
- offsetX: xAbsolute - this.view.getBoundingRect().x,
89
- offsetY: yAbsolute - this.view.getBoundingRect().y,
90
- pointerId: changedTouch.id,
91
- eventType: eventType,
92
- pointerType: PointerType.TOUCH,
93
- buttons: 0,
94
- time: e.timestamp,
95
- allTouches: e.touches.map((touch) => this.mapTouchObjectToTouch(touch)),
96
- changedTouches: e.changedTouches.map((touch) => this.mapTouchObjectToTouch(touch)),
97
- touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type)
98
- }
99
- }
100
-
101
- private updateIsInBoundsByPointerId(
102
- touchType: TouchType,
103
- pointerId: number,
104
- x: number,
105
- y: number
106
- ) {
107
- switch (touchType) {
108
- case TouchType.Down:
109
- if (this.isInBounds({ x, y }))
110
- this.pointersIdInBounds.add(pointerId)
111
- break;
112
- case TouchType.Move:
113
- if (this.isInBounds({ x, y }))
114
- this.pointersIdInBounds.add(pointerId)
115
- else
116
- this.pointersIdInBounds.delete(pointerId)
117
- break;
118
- case TouchType.Up:
119
- this.pointersIdInBounds.delete(pointerId)
120
- break;
121
- case TouchType.Cancel:
122
- this.pointersIdInBounds.delete(pointerId)
123
- break;
124
- }
125
- }
126
-
127
- private isInBounds(point: Point): boolean {
128
- const x = point.x
129
- const y = point.y
130
- const rect = this.view.getBoundingRect()
131
- const result = x >= rect.x && x <= (rect.x + rect.width) && y >= rect.y && y <= (rect.y + rect.height)
132
- return result;
133
- }
134
-
135
- private updateActivePointers(touchType: TouchType, pointerId: number): void {
136
- switch (touchType) {
137
- case TouchType.Down:
138
- this.activePointerIds.add(pointerId)
139
- case TouchType.Up:
140
- this.activePointerIds.delete(pointerId)
141
- case TouchType.Cancel:
142
- this.activePointerIds.clear()
143
- default:
144
- return
145
- }
146
- }
147
-
148
- private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
149
- return {
150
- id: touchObject.id,
151
- x: touchObject.x,
152
- y: touchObject.y,
153
- absoluteX: touchObject.windowX,
154
- absoluteY: touchObject.windowY
155
- }
156
- }
157
-
158
- private mapTouchTypeToEventType(
159
- touchType: TouchType,
160
- activePointersCounter: number,
161
- isCurrentlyInBounds: boolean,
162
- wasInBounds: boolean
163
- ): EventType {
164
- switch (touchType) {
165
- case TouchType.Down:
166
- if (activePointersCounter > 0)
167
- return EventType.ADDITIONAL_POINTER_DOWN
168
- else
169
- return EventType.DOWN
170
- case TouchType.Up:
171
- if (activePointersCounter > 1)
172
- return EventType.ADDITIONAL_POINTER_UP
173
- else
174
- return EventType.UP
175
- case TouchType.Move:
176
- if (isCurrentlyInBounds) {
177
- return wasInBounds ? EventType.MOVE : EventType.ENTER
178
- } else {
179
- return wasInBounds ? EventType.OUT : EventType.MOVE
180
- }
181
- case TouchType.Cancel:
182
- return EventType.CANCEL
183
- default:
184
- console.error("RNGH", "Unknown touchType:", touchType)
185
- throw new Error("Unknown touchType")
186
- }
187
- }
188
-
189
- private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
190
- switch (touchType) {
191
- case TouchType.Down:
192
- return TouchEventType.DOWN
193
- case TouchType.Up:
194
- return TouchEventType.UP
195
- case TouchType.Move:
196
- return TouchEventType.MOVE
197
- case TouchType.Cancel:
198
- return TouchEventType.CANCELLED
199
- default:
200
- return TouchEventType.UNDETERMINED
201
- }
202
- }
203
- }
@@ -1,45 +0,0 @@
1
- import { GestureHandlerOrchestrator } from './GestureHandlerOrchestrator';
2
- import { GestureHandler, GestureHandlerDependencies, ScrollLocker } from "./GestureHandler"
3
- import { PointerTracker } from './PointerTracker';
4
- import { RNGHError } from "./RNGHError"
5
- import { InteractionManager } from './InteractionManager';
6
- import { RNGHLogger } from './RNGHLogger';
7
- import { TapGestureHandler } from './TapGestureHandler';
8
- import { PanGestureHandler } from "./PanGestureHandler"
9
- import { NativeViewGestureHandler } from "./NativeViewGestureHandler"
10
-
11
-
12
- export class GestureHandlerFactory {
13
- private orchestrator: GestureHandlerOrchestrator
14
- private interactionManager = new InteractionManager()
15
- private factoryLogger: RNGHLogger
16
-
17
- constructor(private logger: RNGHLogger, private scrollLocker: ScrollLocker) {
18
- this.factoryLogger = logger.cloneWithPrefix("Factory")
19
- this.orchestrator = new GestureHandlerOrchestrator(logger.cloneWithPrefix("Orchestrator"))
20
- }
21
-
22
- create(handlerName: string, handlerTag: number): GestureHandler {
23
- this.factoryLogger.info(`create ${handlerName} with handlerTag: ${handlerTag}`)
24
- const deps: GestureHandlerDependencies = {
25
- tracker: new PointerTracker(),
26
- orchestrator: this.orchestrator,
27
- handlerTag,
28
- interactionManager: this.interactionManager,
29
- logger: this.logger.cloneWithPrefix("GestureHandler"),
30
- scrollLocker: this.scrollLocker,
31
- }
32
- switch (handlerName) {
33
- case "TapGestureHandler":
34
- return new TapGestureHandler(deps)
35
- case "PanGestureHandler":
36
- return new PanGestureHandler(deps)
37
- case "NativeViewGestureHandler":
38
- return new NativeViewGestureHandler(deps)
39
- default:
40
- const msg = `Unknown handler type: ${handlerName}`
41
- this.factoryLogger.info(msg)
42
- throw new RNGHError(msg)
43
- }
44
- }
45
- }
@@ -1,109 +0,0 @@
1
- import { GestureHandler, Handler, GestureConfig as Config } from "./GestureHandler"
2
-
3
- export class InteractionManager {
4
- private readonly waitForRelations: Map<number, number[]> = new Map()
5
- private readonly simultaneousRelations: Map<number, number[]> = new Map()
6
-
7
- public configureInteractions(handler: GestureHandler, config: Config) {
8
- this.dropRelationsForHandlerWithTag(handler.getTag());
9
-
10
- if (config.waitFor) {
11
- const waitFor: number[] = [];
12
- config.waitFor.forEach((otherHandler: Handler): void => {
13
- // New API reference
14
- if (typeof otherHandler === 'number') {
15
- waitFor.push(otherHandler);
16
- } else {
17
- // Old API reference
18
- waitFor.push(otherHandler.handlerTag);
19
- }
20
- });
21
-
22
- this.waitForRelations.set(handler.getTag(), waitFor);
23
- }
24
-
25
- if (config.simultaneousHandlers) {
26
- const simultaneousHandlers: number[] = [];
27
- config.simultaneousHandlers.forEach((otherHandler: Handler): void => {
28
- if (typeof otherHandler === 'number') {
29
- simultaneousHandlers.push(otherHandler);
30
- } else {
31
- simultaneousHandlers.push(otherHandler.handlerTag);
32
- }
33
- });
34
-
35
- this.simultaneousRelations.set(handler.getTag(), simultaneousHandlers);
36
- }
37
- }
38
-
39
- public shouldWaitForHandlerFailure(
40
- handler: GestureHandler,
41
- otherHandler: GestureHandler
42
- ): boolean {
43
- const waitFor: number[] | undefined = this.waitForRelations.get(
44
- handler.getTag()
45
- );
46
- if (!waitFor) {
47
- return false;
48
- }
49
-
50
- let shouldWait = false;
51
-
52
- waitFor.forEach((tag: number): void => {
53
- if (tag === otherHandler.getTag()) {
54
- shouldWait = true;
55
- return; //Returns from callback
56
- }
57
- });
58
-
59
- return shouldWait;
60
- }
61
-
62
- public shouldRecognizeSimultaneously(
63
- handler: GestureHandler,
64
- otherHandler: GestureHandler
65
- ): boolean {
66
- const simultaneousHandlers: number[] | undefined =
67
- this.simultaneousRelations.get(handler.getTag());
68
- if (!simultaneousHandlers) {
69
- return false;
70
- }
71
-
72
- let shouldRecognizeSimultaneously = false;
73
-
74
- simultaneousHandlers.forEach((tag: number): void => {
75
- if (tag === otherHandler.getTag()) {
76
- shouldRecognizeSimultaneously = true;
77
- return;
78
- }
79
- });
80
-
81
- return shouldRecognizeSimultaneously;
82
- }
83
-
84
- public shouldRequireHandlerToWaitForFailure(
85
- _handler: GestureHandler,
86
- _otherHandler: GestureHandler
87
- ): boolean {
88
- //TODO: Implement logic
89
- return false;
90
- }
91
-
92
- public shouldHandlerBeCancelledBy(
93
- _handler: GestureHandler,
94
- _otherHandler: GestureHandler
95
- ): boolean {
96
- //TODO: Implement logic
97
- return false;
98
- }
99
-
100
- public dropRelationsForHandlerWithTag(handlerTag: number): void {
101
- this.waitForRelations.delete(handlerTag);
102
- this.simultaneousRelations.delete(handlerTag);
103
- }
104
-
105
- public reset() {
106
- this.waitForRelations.clear();
107
- this.simultaneousRelations.clear();
108
- }
109
- }
@@ -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,23 +0,0 @@
1
- import { RNInstance } from "@rnoh/react-native-openharmony/ts"
2
- import { ScrollLocker } from "./GestureHandler"
3
-
4
- export class RNOHScrollLockerArkTS implements ScrollLocker {
5
- constructor(private rnInstance: RNInstance) {
6
- }
7
-
8
- lockScrollContainingViewTag(viewTag: number) {
9
- return this.rnInstance.blockComponentsGestures(viewTag)
10
- }
11
- }
12
-
13
- export class RNOHScrollLockerCAPI implements ScrollLocker {
14
- constructor(private rnInstance: RNInstance) {
15
- }
16
-
17
- lockScrollContainingViewTag(viewTag: number) {
18
- this.rnInstance.postMessageToCpp("RNGH::SET_NATIVE_RESPONDERS_BLOCK", { targetTag: viewTag, shouldBlock: true });
19
- return () => {
20
- this.rnInstance.postMessageToCpp("RNGH::SET_NATIVE_RESPONDERS_BLOCK", { targetTag: viewTag, shouldBlock: false });
21
- }
22
- }
23
- }
@@ -1,36 +0,0 @@
1
- export class Vector2D {
2
- constructor(
3
- private val: {
4
- x: number;
5
- y: number;
6
- } = {x: 0, y: 0},
7
- ) {}
8
-
9
- get x() {
10
- return this.val.x;
11
- }
12
-
13
- get y() {
14
- return this.val.y;
15
- }
16
-
17
- get value() {
18
- return {...this.val};
19
- }
20
-
21
- public clone() {
22
- return new Vector2D({...this.val});
23
- }
24
-
25
- public subtract(vec: Vector2D) {
26
- this.val.x -= vec.x;
27
- this.val.y -= vec.y;
28
- return this;
29
- }
30
-
31
- public add(vec: Vector2D) {
32
- this.val.x += vec.x;
33
- this.val.y += vec.y;
34
- return this;
35
- }
36
- }