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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. package/DrawerLayout/index.ts +2 -0
  2. package/Swipeable/index.ts +2 -0
  3. package/harmony/gesture_handler.har +0 -0
  4. package/lib/commonjs/RNGestureHandlerModule.js +2 -3
  5. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  6. package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
  7. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  8. package/lib/commonjs/handlers/createHandler.js +15 -18
  9. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  10. package/lib/commonjs/index.js +94 -137
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +1 -2
  13. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  14. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +2 -3
  15. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  16. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +2 -3
  17. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  18. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  19. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  20. package/lib/module/handlers/createHandler.js +12 -15
  21. package/lib/module/handlers/createHandler.js.map +1 -1
  22. package/lib/module/index.js +10 -141
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  25. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  26. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  27. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  28. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  29. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  30. package/lib/typescript/index.d.ts +42 -9
  31. package/lib/typescript/index.d.ts.map +1 -1
  32. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  33. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  34. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  35. package/package.json +70 -66
  36. package/src/RNGestureHandlerModule.ts +4 -4
  37. package/src/components/GestureHandlerRootView.tsx +23 -23
  38. package/src/handlers/createHandler.tsx +534 -534
  39. package/src/index.ts +172 -172
  40. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  41. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  42. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
  43. package/harmony/gesture_handler/BuildProfile.ets +0 -5
  44. package/harmony/gesture_handler/build-profile.json5 +0 -19
  45. package/harmony/gesture_handler/hvigorfile.ts +0 -2
  46. package/harmony/gesture_handler/index.ets +0 -3
  47. package/harmony/gesture_handler/oh-package-lock.json5 +0 -17
  48. package/harmony/gesture_handler/oh-package.json5 +0 -12
  49. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
  50. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +0 -103
  51. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -21
  52. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +0 -36
  53. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +0 -27
  54. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +0 -32
  55. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +0 -22
  56. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +0 -15
  57. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
  58. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +0 -36
  59. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -78
  60. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +0 -25
  61. package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +0 -42
  62. package/harmony/gesture_handler/src/main/ets/Event.ts +0 -68
  63. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
  64. package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +0 -663
  65. package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
  66. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
  67. package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +0 -280
  68. package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +0 -22
  69. package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +0 -28
  70. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
  71. package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +0 -182
  72. package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +0 -115
  73. package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +0 -34
  74. package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +0 -328
  75. package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +0 -239
  76. package/harmony/gesture_handler/src/main/ets/RNGHError.ts +0 -5
  77. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
  78. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
  79. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
  80. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +0 -38
  81. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +0 -183
  82. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +0 -53
  83. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
  84. package/harmony/gesture_handler/src/main/ets/State.ts +0 -47
  85. package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +0 -206
  86. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
  87. package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +0 -98
  88. package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
  89. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
  90. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +0 -140
  91. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +0 -25
  92. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +0 -101
  93. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +0 -3
  94. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
  95. package/harmony/gesture_handler/src/main/ets/types.ts +0 -25
  96. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
  97. package/harmony/gesture_handler/src/main/module.json5 +0 -7
  98. package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
  99. package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
  100. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  101. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +0 -5
  102. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
  103. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
  104. package/harmony/gesture_handler/ts.ts +0 -2
@@ -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,280 +0,0 @@
1
- import { GestureHandler } from "./GestureHandler"
2
- import { State } from "./State"
3
- import { PointerType } from "./Event"
4
- import { RNGHLogger } from "./RNGHLogger"
5
-
6
- export class GestureHandlerOrchestrator {
7
- private awaitingHandlers: Set<GestureHandler> = new Set()
8
- private gestureHandlers: GestureHandler[] = []
9
- private handlersToCancel: GestureHandler[] = []
10
- private activationIndex: number = 0
11
-
12
- constructor(private logger: RNGHLogger) {
13
- }
14
-
15
- public onHandlerStateChange(handler: GestureHandler, newState: State, oldState: State, sendIfDisabled?: boolean) {
16
- this.logger.info("onHandlerStateChange")
17
- if (this.shouldCancelStateChange(handler, sendIfDisabled)) return;
18
- if (this.isFinishedState(newState)) {
19
- this.handleChangingToFinishedState(handler, newState)
20
- }
21
- if (newState === State.ACTIVE) {
22
- this.tryActivate(handler)
23
- } else if (oldState === State.ACTIVE || oldState === State.END) {
24
- if (handler.isActive()) {
25
- handler.sendEvent({ newState, oldState })
26
- } else if (oldState === State.ACTIVE && (newState === State.CANCELLED || newState === State.FAILED)) {
27
- // Handle edge case where handler awaiting for another one tries to activate but finishes
28
- // before the other would not send state change event upon ending. Note that we only want
29
- // to do this if the newState is either CANCELLED or FAILED, if it is END we still want to
30
- // wait for the other handler to finish as in that case synthetic events will be sent by the
31
- // makeActive method.
32
- handler.sendEvent({ newState, oldState: State.BEGAN })
33
- }
34
- } else if (newState !== State.CANCELLED || oldState !== State.UNDETERMINED) {
35
- // If handler is changing state from UNDETERMINED to CANCELLED, the state change event shouldn't
36
- // be sent. Handler hasn't yet began so it may not be initialized which results in crashes.
37
- // If it doesn't crash, there may be some weird behavior on JS side, as `onFinalize` will be
38
- // called without calling `onBegin` first.
39
- handler.sendEvent({ newState, oldState })
40
- }
41
- this.cleanUpHandlers(handler)
42
- }
43
-
44
- private isFinishedState(state: State) {
45
- return [State.END, State.FAILED, State.CANCELLED].includes(state)
46
- }
47
-
48
- private shouldCancelStateChange(handler: GestureHandler, sendIfDisabled?: boolean) {
49
- const isHandlerDisabled = !handler.isEnabled()
50
- return!sendIfDisabled && isHandlerDisabled
51
- }
52
-
53
- private handleChangingToFinishedState(handler: GestureHandler, newState: State) {
54
- this.awaitingHandlers.forEach(awaitingHandler => {
55
- if (handler.shouldWaitFor(awaitingHandler)) {
56
- if (newState === State.END) {
57
- awaitingHandler.cancel()
58
- if (awaitingHandler.getState() === State.END) {
59
- // Handle edge case, where discrete gestures end immediately after activation thus
60
- // their state is set to END and when the gesture they are waiting for activates they
61
- // should be cancelled, however `cancel` was never sent as gestures were already in the END state.
62
- // Send synthetic BEGAN -> CANCELLED to properly handle JS logic
63
- awaitingHandler.sendEvent({ newState: State.CANCELLED, oldState: State.BEGAN })
64
- }
65
- awaitingHandler.setAwaiting(false)
66
- } else {
67
- this.tryActivate(awaitingHandler)
68
- }
69
- }
70
- })
71
- }
72
-
73
- private tryActivate(handler: GestureHandler): void {
74
- if (this.hasOtherHandlerToWaitFor(handler)) {
75
- this.addAwaitingHandler(handler)
76
- } else if (handler.getState() !== State.CANCELLED && handler.getState() !== State.FAILED) {
77
- if (this.shouldActivate(handler)) {
78
- this.makeActive(handler);
79
- } else {
80
- switch (handler.getState()) {
81
- case State.ACTIVE:
82
- handler.fail();
83
- break;
84
- case State.BEGAN:
85
- handler.cancel();
86
- break;
87
- }
88
- }
89
- }
90
- }
91
-
92
- private hasOtherHandlerToWaitFor(handler: GestureHandler): boolean {
93
- for (const otherHandler of this.gestureHandlers) {
94
- if (!this.isFinishedState(otherHandler.getState()) && otherHandler.shouldWaitFor(handler)) {
95
- return true
96
- }
97
- }
98
- return false;
99
- }
100
-
101
- private addAwaitingHandler(handler: GestureHandler) {
102
- if (!this.awaitingHandlers.has(handler)) {
103
- this.awaitingHandlers.add(handler)
104
- handler.setAwaiting(true)
105
- handler.setActivationIndex(this.activationIndex++)
106
- }
107
- }
108
-
109
- private shouldActivate(handler: GestureHandler) {
110
- for (const otherHandler of this.gestureHandlers) {
111
- if (this.shouldHandlerBeCancelledByOtherHandler({ handler, otherHandler })) {
112
- return false
113
- }
114
- }
115
- return true
116
- }
117
-
118
- private shouldHandlerBeCancelledByOtherHandler({handler, otherHandler}: {
119
- handler: GestureHandler,
120
- otherHandler: GestureHandler
121
- }): boolean {
122
- if (this.canRunSimultaneously(handler, otherHandler))
123
- return false;
124
- if (handler !== otherHandler && (handler.isAwaiting() || handler.getState() === State.ACTIVE))
125
- return handler.shouldBeCancelledByOther(otherHandler)
126
- return this.checkOverlap(handler, otherHandler)
127
- }
128
-
129
- private canRunSimultaneously(handlerA: GestureHandler, handlerB: GestureHandler) {
130
- return handlerA === handlerB
131
- || handlerA.shouldRecognizeSimultaneously(handlerB)
132
- || handlerB.shouldRecognizeSimultaneously(handlerA)
133
- }
134
-
135
- private checkOverlap(
136
- handler: GestureHandler,
137
- otherHandler: GestureHandler
138
- ): boolean {
139
- // If handlers don't have common pointers, default return value is false.
140
- // However, if at least on pointer overlaps with both handlers, we return true
141
- // This solves issue in overlapping parents example
142
-
143
- // TODO: Find better way to handle that issue, for example by activation order and handler cancelling
144
-
145
- const handlerPointers: number[] = handler.getTrackedPointersID();
146
- const otherPointers: number[] = otherHandler.getTrackedPointersID();
147
- let overlap = false;
148
- handlerPointers.forEach((pointer: number) => {
149
- const handlerX: number = handler.getTracker().getLastX(pointer);
150
- const handlerY: number = handler.getTracker().getLastY(pointer);
151
- if (
152
- handler.getView().isPositionInBounds({ x: handlerX, y: handlerY }) &&
153
- otherHandler.getView().isPositionInBounds({ x: handlerX, y: handlerY })
154
- ) {
155
- overlap = true;
156
- }
157
- });
158
- otherPointers.forEach((pointer: number) => {
159
- const otherX: number = otherHandler.getTracker().getLastX(pointer);
160
- const otherY: number = otherHandler.getTracker().getLastY(pointer);
161
- if (
162
- handler.getView().isPositionInBounds({ x: otherX, y: otherY }) &&
163
- otherHandler.getView().isPositionInBounds({ x: otherX, y: otherY })
164
- ) {
165
- overlap = true;
166
- }
167
- });
168
- return overlap;
169
- }
170
-
171
- private makeActive(handler: GestureHandler): void {
172
- handler.setActive(true)
173
- handler.setShouldResetProgress(true)
174
- handler.setActivationIndex(this.activationIndex++)
175
- for (const otherHandler of this.gestureHandlers) {
176
- if (this.shouldHandlerBeCancelledByOtherHandler({ handler: otherHandler, otherHandler: handler })) {
177
- this.handlersToCancel.push(otherHandler)
178
- }
179
- }
180
- for (let i = this.handlersToCancel.length - 1; i >= 0; --i) {
181
- this.handlersToCancel[i]?.cancel();
182
- }
183
- this.handlersToCancel = []
184
- for (const awaitingHandler of this.awaitingHandlers) {
185
- if (this.shouldHandlerBeCancelledByOtherHandler({ handler: awaitingHandler, otherHandler: handler })) {
186
- awaitingHandler.cancel();
187
- awaitingHandler.setAwaiting(true);
188
- }
189
- }
190
- const currentState = handler.getState()
191
- handler.sendEvent({ newState: State.ACTIVE, oldState: State.BEGAN })
192
- if (currentState !== State.ACTIVE) {
193
- handler.sendEvent({ newState: State.END, oldState: State.ACTIVE })
194
- if (currentState !== State.END) {
195
- handler.sendEvent({ newState: State.UNDETERMINED, oldState: State.END })
196
- }
197
- }
198
- if (handler.isAwaiting()) {
199
- handler.setAwaiting(false)
200
- this.awaitingHandlers.delete(handler)
201
- }
202
- }
203
-
204
- private cleanUpHandlers(handler: GestureHandler) {
205
- this.cleanUpFinishedHandlers()
206
- if (this.awaitingHandlers.has(handler)) {
207
- this.cleanupAwaitingHandlers(handler);
208
- }
209
- }
210
-
211
- private cleanUpFinishedHandlers(): void {
212
- for (let i = this.gestureHandlers.length - 1; i >= 0; --i) {
213
- const handler = this.gestureHandlers[i];
214
- if (!handler) {
215
- continue;
216
- }
217
- if (this.isFinishedState(handler.getState()) && !handler.isAwaiting()) {
218
- this.gestureHandlers.splice(i, 1);
219
- this.cleanUpHandler(handler);
220
- }
221
- }
222
- }
223
-
224
- private cleanupAwaitingHandlers(handler: GestureHandler): void {
225
- for (const awaitingHandler of this.awaitingHandlers) {
226
- if (
227
- awaitingHandler.isAwaiting() &&
228
- awaitingHandler.shouldWaitFor(handler)
229
- ) {
230
- this.cleanUpHandler(awaitingHandler);
231
- this.awaitingHandlers.delete(awaitingHandler)
232
- }
233
- }
234
- }
235
-
236
- private cleanUpHandler(handler: GestureHandler) {
237
- handler.reset();
238
- handler.setActive(false);
239
- handler.setAwaiting(false);
240
- handler.setActivationIndex(Number.MAX_VALUE);
241
- }
242
-
243
- public registerHandlerIfNotPresent(handler: GestureHandler) {
244
- this.logger.info("registerHandlerIfNotPresent")
245
- if (this.gestureHandlers.includes(handler)) return;
246
- this.gestureHandlers.push(handler);
247
- handler.setActive(false);
248
- handler.setAwaiting(false);
249
- handler.setActivationIndex(Number.MAX_SAFE_INTEGER);
250
- }
251
-
252
- /**
253
- This function is called when handler receives touchdown event
254
- If handler is using mouse or pen as a pointer and any handler receives touch event,
255
- mouse/pen event disappears - it doesn't send onPointerCancel nor onPointerUp (and others)
256
- This became a problem because handler was left at active state without any signal to end or fail
257
- To handle this, when new touch event is received, we loop through active handlers and check which type of
258
- pointer they're using. If there are any handler with mouse/pen as a pointer, we cancel them
259
- */
260
- public cancelMouseAndPenGestures(currentHandler: GestureHandler): void {
261
- this.logger.info("cancelMouseAndPenGestures")
262
- this.gestureHandlers.forEach((handler: GestureHandler) => {
263
- if (handler.getPointerType() !== PointerType.MOUSE && handler.getPointerType() !== PointerType.PEN) return;
264
-
265
- if (handler !== currentHandler) {
266
- handler.cancel();
267
- } else {
268
- // Handler that received touch event should have its pointer tracker reset
269
- // This allows handler to smoothly change from mouse/pen to touch
270
- // The drawback is, that when we try to use mouse/pen one more time, it doesn't send onPointerDown at the first time
271
- // so it is required to click two times to get handler to work
272
- //
273
- // However, handler will receive manually created onPointerEnter that is triggered in EventManager in onPointerMove method.
274
- // There may be possibility to use that fact to make handler respond properly to first mouse click
275
- handler.getTracker().resetTracker();
276
- }
277
- });
278
- }
279
- }
280
-
@@ -1,22 +0,0 @@
1
- import {RNPackage, TurboModuleContext, TurboModulesFactory} from '@rnoh/react-native-openharmony/ts';
2
- import type {TurboModule} from '@rnoh/react-native-openharmony/ts';
3
- import {RNGestureHandlerModule} from './RNGestureHandlerModule';
4
-
5
- class GestureHandlerTurboModulesFactory extends TurboModulesFactory {
6
- createTurboModule(name: string): TurboModule | null {
7
- if (name === RNGestureHandlerModule.NAME) {
8
- return new RNGestureHandlerModule(this.ctx);
9
- }
10
- return null;
11
- }
12
-
13
- hasTurboModule(name: string): boolean {
14
- return name === 'RNGestureHandlerModule';
15
- }
16
- }
17
-
18
- export class GestureHandlerPackage extends RNPackage {
19
- createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
20
- return new GestureHandlerTurboModulesFactory(ctx);
21
- }
22
- }
@@ -1,28 +0,0 @@
1
- import { GestureHandler } from "./GestureHandler"
2
- import { View } from "./View"
3
-
4
- export class GestureHandlerRegistry {
5
- private gestureHandlerByHandlerTag: Map<number, GestureHandler> = new Map()
6
- private gestureHandlersByViewTag: Map<number, Set<GestureHandler>> = new Map()
7
-
8
- public addGestureHandler(gestureHandler: GestureHandler) {
9
- this.gestureHandlerByHandlerTag.set(gestureHandler.getTag(), gestureHandler)
10
- }
11
-
12
- public bindGestureHandlerWithView(gestureHandlerTag: number, view: View) {
13
- const viewTag = view.getTag()
14
- if (!this.gestureHandlersByViewTag.has(viewTag))
15
- this.gestureHandlersByViewTag.set(viewTag, new Set())
16
- const gestureHandler = this.gestureHandlerByHandlerTag.get(gestureHandlerTag)
17
- this.gestureHandlersByViewTag.get(viewTag).add(gestureHandler)
18
- gestureHandler.onViewAttached(view)
19
- }
20
-
21
- public getGestureHandlersByViewTag(viewTag: number): GestureHandler[] {
22
- return Array.from(this.gestureHandlersByViewTag.get(viewTag) ?? [])
23
- }
24
-
25
- public getGestureHandlerByHandlerTag(handlerTag: number): GestureHandler {
26
- return this.gestureHandlerByHandlerTag.get(handlerTag)
27
- }
28
- }
@@ -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
- }