@react-native-oh-tpl/react-native-gesture-handler 2.14.16 → 2.14.17-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/DrawerLayout/index.ts +2 -2
  2. package/Swipeable/index.ts +2 -2
  3. package/harmony/gesture_handler.har +0 -0
  4. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  5. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  6. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  9. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  10. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  11. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  12. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  13. package/lib/module/handlers/createHandler.js.map +1 -1
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  16. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  17. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  18. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  19. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  20. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  21. package/lib/typescript/index.d.ts +47 -47
  22. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  23. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  24. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  25. package/package.json +79 -78
  26. package/src/RNGestureHandlerModule.ts +4 -4
  27. package/src/components/GestureHandlerRootView.tsx +23 -23
  28. package/src/handlers/createHandler.tsx +534 -534
  29. package/src/index.ts +172 -172
  30. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  31. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  32. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
  33. package/harmony/gesture_handler/BuildProfile.ets +0 -17
  34. package/harmony/gesture_handler/build-profile.json5 +0 -12
  35. package/harmony/gesture_handler/hvigorfile.ts +0 -2
  36. package/harmony/gesture_handler/index.ets +0 -2
  37. package/harmony/gesture_handler/oh-package-lock.json5 +0 -19
  38. package/harmony/gesture_handler/oh-package.json5 +0 -12
  39. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
  40. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -12
  41. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +0 -123
  42. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +0 -15
  43. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +0 -27
  44. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +0 -245
  45. package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +0 -17
  46. package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +0 -42
  47. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +0 -739
  48. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +0 -344
  49. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +0 -63
  50. package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +0 -78
  51. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +0 -144
  52. package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +0 -182
  53. package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +0 -26
  54. package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +0 -34
  55. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +0 -12
  56. package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +0 -239
  57. package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +0 -5
  58. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +0 -16
  59. package/harmony/gesture_handler/src/main/ets/core/State.ts +0 -47
  60. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +0 -80
  61. package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +0 -106
  62. package/harmony/gesture_handler/src/main/ets/core/View.ts +0 -21
  63. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +0 -7
  64. package/harmony/gesture_handler/src/main/ets/core/index.ts +0 -15
  65. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +0 -169
  66. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +0 -219
  67. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +0 -67
  68. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +0 -139
  69. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +0 -50
  70. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +0 -124
  71. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +0 -375
  72. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +0 -174
  73. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +0 -172
  74. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +0 -216
  75. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +0 -167
  76. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +0 -1
  77. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +0 -25
  78. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +0 -107
  79. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +0 -94
  80. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +0 -196
  81. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +0 -89
  82. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +0 -255
  83. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +0 -19
  84. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +0 -267
  85. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -15
  86. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +0 -25
  87. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +0 -25
  88. package/harmony/gesture_handler/src/main/module.json5 +0 -9
  89. package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
  90. package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
  91. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  92. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +0 -5
  93. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
  94. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
  95. package/harmony/gesture_handler/ts.ts +0 -2
@@ -1,255 +0,0 @@
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
-
15
- export class RNGHViewController {
16
- private activePointerIds = new Set<number>();
17
- private pointerIdsInBounds = new Set<number>();
18
- private gestureHandlers = new Set<GestureHandler>();
19
- private view: View;
20
- private logger: RNGHLogger;
21
-
22
- constructor(view: View, logger: RNGHLogger) {
23
- this.logger = logger.cloneAndJoinPrefix(`RNGHViewTouchHandler`)
24
- this.view = view;
25
- }
26
-
27
- attachGestureHandler(gestureHandler: GestureHandler) {
28
- this.gestureHandlers.add(gestureHandler)
29
- }
30
-
31
- handleTouch(e: TouchEvent) {
32
- const logger = this.logger.cloneAndJoinPrefix("handleTouch")
33
- for (const changedTouch of e.changedTouches) {
34
- if (this.shouldSkipTouch(changedTouch)) {
35
- continue;
36
- }
37
- const wasInBounds = this.pointerIdsInBounds.has(changedTouch.id);
38
- const isInBounds = this.isInBounds({
39
- x: changedTouch.windowX,
40
- y: changedTouch.windowY,
41
- });
42
- logger.debug(
43
- {
44
- viewTag: this.view.getTag(),
45
- type: changedTouch.type,
46
- wasInBounds,
47
- isInBounds,
48
- },
49
- );
50
- const adaptedEvent = this.adaptTouchEvent(e, changedTouch);
51
- this.gestureHandlers.forEach(gh => {
52
- switch (adaptedEvent.eventType) {
53
- case EventType.DOWN:
54
- gh.onPointerDown(adaptedEvent);
55
- break;
56
- case EventType.ADDITIONAL_POINTER_DOWN:
57
- gh.onAdditionalPointerAdd(adaptedEvent);
58
- break;
59
- case EventType.UP:
60
- gh.onPointerUp(adaptedEvent);
61
- break;
62
- case EventType.ADDITIONAL_POINTER_UP:
63
- gh.onAdditionalPointerRemove(adaptedEvent);
64
- break;
65
- case EventType.MOVE:
66
- if (!wasInBounds && !isInBounds) {
67
- gh.onPointerOutOfBounds(adaptedEvent);
68
- } else {
69
- gh.onPointerMove(adaptedEvent);
70
- }
71
- break;
72
- case EventType.ENTER:
73
- gh.onPointerEnter(adaptedEvent);
74
- break;
75
- case EventType.OUT:
76
- gh.onPointerOut(adaptedEvent);
77
- break;
78
- case EventType.CANCEL:
79
- gh.onPointerCancel(adaptedEvent);
80
- break;
81
- }
82
- })
83
- }
84
- }
85
-
86
- private shouldSkipTouch(changedTouch: TouchObject): boolean {
87
- return (
88
- changedTouch.type === TouchType.Down &&
89
- !this.isInBounds({
90
- x: changedTouch.windowX,
91
- y: changedTouch.windowY,
92
- })
93
- );
94
- }
95
-
96
- private adaptTouchEvent(
97
- e: TouchEvent,
98
- changedTouch: TouchObject,
99
- ): IncomingEvent {
100
- const xAbsolute = changedTouch.windowX;
101
- const yAbsolute = changedTouch.windowY;
102
-
103
- const eventType = this.mapTouchTypeToEventType(
104
- changedTouch.type,
105
- this.isInBounds({ x: xAbsolute, y: yAbsolute }),
106
- changedTouch.id,
107
- this.pointerIdsInBounds.has(changedTouch.id),
108
- );
109
- this.logger.cloneAndJoinPrefix("adaptTouchEvent")
110
- .debug({ eventType, activePointersCount: this.activePointerIds.size })
111
- this.updateIsInBoundsByPointerId(
112
- changedTouch.type,
113
- changedTouch.id,
114
- xAbsolute,
115
- yAbsolute,
116
- );
117
- this.updateActivePointers(changedTouch.type, changedTouch.id);
118
- return {
119
- x: xAbsolute,
120
- y: yAbsolute,
121
- offsetX: xAbsolute - this.view.getBoundingRect().x,
122
- offsetY: yAbsolute - this.view.getBoundingRect().y,
123
- pointerId: changedTouch.id,
124
- eventType: eventType,
125
- pointerType: PointerType.TOUCH,
126
- buttons: 0,
127
- time: e.timestamp,
128
- allTouches: e.touches.map(touch => this.mapTouchObjectToTouch(touch)),
129
- changedTouches: e.changedTouches.map(touch =>
130
- this.mapTouchObjectToTouch(touch),
131
- ),
132
- touchEventType: this.mapTouchTypeToTouchEventType(changedTouch.type),
133
- };
134
- }
135
-
136
- private updateIsInBoundsByPointerId(
137
- touchType: TouchType,
138
- pointerId: number,
139
- x: number,
140
- y: number,
141
- ) {
142
- switch (touchType) {
143
- case TouchType.Down:
144
- if (this.isInBounds({ x, y })) {
145
- this.pointerIdsInBounds.add(pointerId);
146
- }
147
- break;
148
- case TouchType.Move:
149
- if (this.isInBounds({
150
- x,
151
- y
152
- })) {
153
- this.pointerIdsInBounds.add(pointerId);
154
- } else {
155
- this.pointerIdsInBounds.delete(pointerId);
156
- }
157
- break;
158
- case TouchType.Up:
159
- this.pointerIdsInBounds.delete(pointerId);
160
- break;
161
- case TouchType.Cancel:
162
- this.pointerIdsInBounds.delete(pointerId);
163
- break;
164
- }
165
- }
166
-
167
- private isInBounds(point: Point): boolean {
168
- const rect = this.view.getBoundingRect();
169
- this.logger.cloneAndJoinPrefix("isInBounds").debug({ rect })
170
- return this.view.isPositionInBounds(point);
171
- }
172
-
173
- private updateActivePointers(touchType: TouchType, pointerId: number): void {
174
- switch (touchType) {
175
- case TouchType.Down:
176
- this.activePointerIds.add(pointerId);
177
- break;
178
- case TouchType.Up:
179
- this.activePointerIds.delete(pointerId);
180
- break;
181
- case TouchType.Cancel:
182
- this.activePointerIds.clear();
183
- break;
184
- default:
185
- return;
186
- }
187
- }
188
-
189
- private mapTouchObjectToTouch(touchObject: TouchObject): Touch {
190
- return {
191
- id: touchObject.id,
192
- x: touchObject.x,
193
- y: touchObject.y,
194
- absoluteX: touchObject.windowX,
195
- absoluteY: touchObject.windowY,
196
- };
197
- }
198
-
199
- private mapTouchTypeToEventType(
200
- touchType: TouchType,
201
- isCurrentlyInBounds: boolean,
202
- pointerId: number,
203
- wasInBounds: boolean,
204
- ): EventType {
205
- /**
206
- * If user manages to drag finger out of GestureHandlerRootView,
207
- * we don't receive UP event.
208
- */
209
- let activePointersCount = this.activePointerIds.size
210
- if (this.activePointerIds.has(pointerId)) {
211
- activePointersCount--;
212
- }
213
-
214
- switch (touchType) {
215
- case TouchType.Down:
216
- if (activePointersCount > 0) {
217
- return EventType.ADDITIONAL_POINTER_DOWN;
218
- } else {
219
- return EventType.DOWN;
220
- }
221
- case TouchType.Up:
222
- if (activePointersCount > 1) {
223
- return EventType.ADDITIONAL_POINTER_UP;
224
- } else {
225
- return EventType.UP;
226
- }
227
- case TouchType.Move:
228
- if (isCurrentlyInBounds) {
229
- return wasInBounds ? EventType.MOVE : EventType.ENTER;
230
- } else {
231
- return wasInBounds ? EventType.OUT : EventType.MOVE;
232
- }
233
- case TouchType.Cancel:
234
- return EventType.CANCEL;
235
- default:
236
- console.error('RNGH', 'Unknown touchType:', touchType);
237
- throw new Error('Unknown touchType');
238
- }
239
- }
240
-
241
- private mapTouchTypeToTouchEventType(touchType: TouchType): TouchEventType {
242
- switch (touchType) {
243
- case TouchType.Down:
244
- return TouchEventType.DOWN;
245
- case TouchType.Up:
246
- return TouchEventType.UP;
247
- case TouchType.Move:
248
- return TouchEventType.MOVE;
249
- case TouchType.Cancel:
250
- return TouchEventType.CANCELLED;
251
- default:
252
- return TouchEventType.UNDETERMINED;
253
- }
254
- }
255
- }
@@ -1,19 +0,0 @@
1
- import { Tag, } from '@rnoh/react-native-openharmony/ts';
2
- import { View, ViewRegistry } from '../core';
3
-
4
-
5
- export class RNGHViewRegistry implements ViewRegistry {
6
- private viewByTag = new Map<Tag, View>()
7
-
8
- save(view: View) {
9
- this.viewByTag.set(view.getTag(), view)
10
- }
11
-
12
- deleteByTag(viewTag: Tag) {
13
- this.viewByTag.delete(viewTag)
14
- }
15
-
16
- getViewByTag(viewTag: Tag) {
17
- return this.viewByTag.get(viewTag);
18
- }
19
- }
@@ -1,267 +0,0 @@
1
- import { TurboModule, TurboModuleContext, Tag } from "@rnoh/react-native-openharmony/ts";
2
- import { TM } from "@rnoh/react-native-openharmony/generated/ts"
3
- import {
4
- GestureHandlerRegistry,
5
- State,
6
- OutgoingEventDispatcher,
7
- RNGHLogger,
8
- InteractionManager,
9
- ViewRegistry
10
- } from '../core';
11
- import { GestureHandlerFactory } from "../gesture-handlers"
12
- import { RNGHViewRegistry } from './RNGHViewRegistry';
13
- import { DevelopmentRNGHLogger, ProductionRNGHLogger } from './Logger';
14
- import { JSEventDispatcher, AnimatedEventDispatcher, ReanimatedEventDispatcher } from './OutgoingEventDispatchers'
15
- import { RNOHScrollLockerCAPI } from "./RNOHScrollLocker"
16
- import { RNGHRootViewController, RawTouchEvent } from "./RNGHRootViewController"
17
- import { RNGHView } from "./RNGHView"
18
- import { RNOHGestureResponder } from "./RNOHGestureResponder"
19
-
20
- export enum ActionType {
21
- REANIMATED_WORKLET = 1,
22
- NATIVE_ANIMATED_EVENT = 2,
23
- JS_FUNCTION_OLD_API = 3,
24
- JS_FUNCTION_NEW_API = 4,
25
- }
26
-
27
-
28
- export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureHandlerModule.Spec {
29
- static readonly NAME = "RNGestureHandlerModule"
30
-
31
- private gestureHandlerRegistry: GestureHandlerRegistry
32
- private gestureHandlerFactory: GestureHandlerFactory | undefined = undefined
33
- private viewRegistry: ViewRegistry | undefined = undefined
34
- private logger: RNGHLogger
35
- private cleanLogger: RNGHLogger
36
- private rootViewControllerByRootTag = new Map<Tag, RNGHRootViewController>()
37
- private interactionManager: InteractionManager
38
-
39
- constructor(ctx: TurboModuleContext, isDevModeEnabled: boolean = false) {
40
- super(ctx)
41
- this.cleanLogger =
42
- isDevModeEnabled && ctx.isDebugModeEnabled ? new DevelopmentRNGHLogger(ctx.logger, "RNGH") :
43
- new ProductionRNGHLogger(ctx.logger, "RNGH")
44
- this.logger = this.cleanLogger.cloneAndJoinPrefix("RNGestureHandlerModule")
45
- const logger = this.logger.cloneAndJoinPrefix("constructor")
46
- const stopTracing = logger.startTracing()
47
- this.interactionManager = new InteractionManager(this.cleanLogger)
48
- this.gestureHandlerRegistry = new GestureHandlerRegistry(this.viewRegistry, this.cleanLogger)
49
- if (this.ctx.rnInstance.getArchitecture() === "C_API") {
50
- this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::TOUCH_EVENT", (e: any) => {
51
- this.onTouch(e)
52
- })
53
- this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::ROOT_CREATED", (rootTag: any) => {
54
- this.onGHRootCreated(rootTag)
55
- })
56
- this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::CANCEL_TOUCHES", (rootTag: any) => {
57
- const touchHandler = this.rootViewControllerByRootTag.get(rootTag)
58
- touchHandler?.cancelTouches()
59
- })
60
- }
61
- stopTracing()
62
- }
63
-
64
- /**
65
- * Called from C++.
66
- */
67
- private onGHRootCreated(rootTag: Tag) {
68
- const stopTracing = this.logger.cloneAndJoinPrefix("onGHRootCreated").startTracing()
69
- this.rootViewControllerByRootTag.set(rootTag, new RNGHRootViewController(this.logger, this.gestureHandlerRegistry));
70
- stopTracing()
71
- }
72
-
73
- /**
74
- * Called from C++.
75
- */
76
- private onTouch(e: RawTouchEvent & { rootTag: Tag }) {
77
- const logger = this.logger.cloneAndJoinPrefix("onTouch")
78
- const stopTracing = logger.startTracing();
79
- (() => {
80
- if (!(this.viewRegistry instanceof RNGHViewRegistry)) {
81
- logger.error("Expected ViewRegistryCAPI")
82
- return;
83
- }
84
- const rootViewController = this.rootViewControllerByRootTag.get(e.rootTag)
85
- if (!rootViewController) {
86
- logger.error(`Couldn't find a rootViewController for a gesture root tag: ${e.rootTag}`)
87
- return;
88
- }
89
- // update view registry
90
- e.touchableViews.forEach(touchableView => {
91
- const view = this.viewRegistry.getViewByTag(touchableView.tag)
92
- if (view) {
93
- if (!(view instanceof RNGHView)) {
94
- logger.error(`Expected ViewCAPI`)
95
- return
96
- }
97
- view.updateBoundingBox(touchableView)
98
- view.setButtonRole(touchableView.buttonRole)
99
- } else {
100
- this.viewRegistry.save(new RNGHView(touchableView))
101
- }
102
- })
103
- rootViewController.handleTouch(e, e.touchableViews.map(({ tag }) => this.viewRegistry.getViewByTag(tag)));
104
- })()
105
- stopTracing()
106
- }
107
-
108
- // -------------------------------------------------------------------------------------------------------------------
109
-
110
- public install() {
111
- const stopTracing = this.ctx.logger.clone("install").startTracing()
112
- this.viewRegistry = new RNGHViewRegistry()
113
- const scrollLocker = new RNOHScrollLockerCAPI(this.ctx.rnInstance, this.cleanLogger);
114
- const rnGestureResponder = new RNOHGestureResponder(this.ctx.rnInstance)
115
- this.gestureHandlerFactory =
116
- new GestureHandlerFactory(this.cleanLogger, scrollLocker, this.interactionManager, rnGestureResponder)
117
- stopTracing()
118
- return true
119
- }
120
-
121
- public createGestureHandler(
122
- handlerName: string,
123
- handlerTag: number,
124
- config: Readonly<Record<string, unknown>>
125
- ) {
126
- const logger = this.logger.cloneAndJoinPrefix("createGestureHandler")
127
- const stopTracing = logger.startTracing();
128
- (() => {
129
- if (!this.gestureHandlerFactory) {
130
- logger.error("Trying to create a gesture handler before creating gesture handler factory")
131
- return
132
- }
133
- logger.debug({ handlerName, handlerTag, config })
134
- const gestureHandler = this.gestureHandlerFactory.create(handlerName, handlerTag)
135
- this.gestureHandlerRegistry.addGestureHandler(gestureHandler)
136
- this.interactionManager.configureInteractions(gestureHandler, config);
137
- gestureHandler.updateGestureConfig(config)
138
- })()
139
- stopTracing()
140
- }
141
-
142
- public attachGestureHandler(
143
- handlerTag: number,
144
- viewTag: number,
145
- actionType: ActionType
146
- ) {
147
- const logger = this.logger.cloneAndJoinPrefix("attachGestureHandler")
148
- const stopTracing = logger.startTracing();
149
- (() => {
150
- const eventDispatcher = this.createEventDispatcher(actionType, viewTag)
151
- if (!eventDispatcher) {
152
- logger.error("RNGH: Couldn't create EventDispatcher")
153
- return
154
- }
155
- const viewRegistry = this.viewRegistry
156
- let view = this.viewRegistry.getViewByTag(viewTag)
157
- if (!view && viewRegistry instanceof RNGHViewRegistry) {
158
- view = new RNGHView({
159
- tag: viewTag,
160
- x: 0,
161
- y: 0,
162
- width: 0,
163
- height: 0,
164
- buttonRole: false
165
- })
166
- viewRegistry.save(view)
167
- }
168
- if (!view) {
169
- logger.error("Expected view")
170
- return;
171
- }
172
- this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
173
- this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag()).forEach((handler) => {
174
- if (handler.isGestureContinuous() && eventDispatcher instanceof JSEventDispatcher) {
175
- logger.warn(`Using JSEventDispatcher for a continuous gesture (${handler.getName()}). Gesture-driven animations may not be smooth. Consider using Animated.event.`)
176
- }
177
- })
178
- this.gestureHandlerRegistry
179
- .getGestureHandlerByHandlerTag(handlerTag)
180
- .setEventDispatcher(eventDispatcher)
181
- })()
182
- stopTracing()
183
- }
184
-
185
- private createEventDispatcher(actionType: ActionType, viewTag: number): OutgoingEventDispatcher | null {
186
- switch (actionType) {
187
- case ActionType.REANIMATED_WORKLET:
188
- return new ReanimatedEventDispatcher(this.ctx.rnInstance,
189
- this.cleanLogger, viewTag)
190
- case ActionType.NATIVE_ANIMATED_EVENT:
191
- return new AnimatedEventDispatcher(this.ctx.rnInstance,
192
- this.cleanLogger, viewTag)
193
- case ActionType.JS_FUNCTION_OLD_API:
194
- case ActionType.JS_FUNCTION_NEW_API:
195
- return new JSEventDispatcher(this.ctx.rnInstance, this.cleanLogger);
196
- }
197
- }
198
-
199
- public updateGestureHandler(
200
- handlerTag: number,
201
- newConfig: Readonly<Record<string, unknown>>
202
- ) {
203
- const stopTracing = this.logger.cloneAndJoinPrefix("updateGestureHandler").startTracing()
204
- const gestureHandler = this.gestureHandlerRegistry.getGestureHandlerByHandlerTag(handlerTag)
205
- this.interactionManager.configureInteractions(gestureHandler, newConfig);
206
- gestureHandler.updateGestureConfig(newConfig)
207
- stopTracing()
208
- }
209
-
210
- public dropGestureHandler(handlerTag: number) {
211
- const stopTracing = this.logger.cloneAndJoinPrefix("dropGestureHandler").startTracing()
212
- this.interactionManager.dropRelationsForHandlerWithTag(handlerTag)
213
- this.gestureHandlerRegistry.removeGestureHandlerByHandlerTag(handlerTag)
214
- stopTracing()
215
- }
216
-
217
- public handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
218
- this.logger.cloneAndJoinPrefix("handleSetJSResponder").warn("not implemented")
219
- }
220
-
221
- public handleClearJSResponder() {
222
- this.logger.cloneAndJoinPrefix("handleClearJSResponder").warn("not implemented")
223
- }
224
-
225
- public flushOperations() {
226
- // no-op
227
- }
228
-
229
- // -------------------------------------------------------------------------------------------------------------------
230
-
231
- public getGestureHandlerRegistry() {
232
- return this.gestureHandlerRegistry
233
- }
234
-
235
- public getLogger() {
236
- return this.logger
237
- }
238
-
239
- public getViewRegistry() {
240
- if (!this.viewRegistry) {
241
- this.logger.error("Tried to get viewRegistry before it was initialized")
242
- throw new Error("Tried to get viewRegistry before it was initialized")
243
- }
244
- return this.viewRegistry
245
- }
246
-
247
- public setGestureHandlerState(handlerTag: number, newState: State) {
248
- const handler = this.getGestureHandlerRegistry().getGestureHandlerByHandlerTag(handlerTag);
249
- switch (newState) {
250
- case State.ACTIVE:
251
- handler.activate();
252
- break;
253
- case State.BEGAN:
254
- handler.begin();
255
- break;
256
- case State.END:
257
- handler.end();
258
- break;
259
- case State.FAILED:
260
- handler.fail();
261
- break;
262
- case State.CANCELLED:
263
- handler.cancel();
264
- break;
265
- }
266
- }
267
- }
@@ -1,15 +0,0 @@
1
- import { RNInstance } from "@rnoh/react-native-openharmony/ts"
2
- import { RNGestureResponder } from "../core"
3
-
4
-
5
- export class RNOHGestureResponder implements RNGestureResponder {
6
- constructor(private rnInstance: RNInstance) {
7
- }
8
-
9
- lock(viewTag: number): () => void {
10
- this.rnInstance.postMessageToCpp("RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES", { descendantViewTag: viewTag, isHandlingTouches: true })
11
- return () => {
12
- this.rnInstance.postMessageToCpp("RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES", { descendantViewTag: viewTag, isHandlingTouches: false })
13
- }
14
- }
15
- }
@@ -1,25 +0,0 @@
1
- import { RNInstance } from '@rnoh/react-native-openharmony/ts';
2
- import { ScrollLocker, RNGHLogger } from '../core';
3
-
4
-
5
-
6
- export class RNOHScrollLockerCAPI implements ScrollLocker {
7
- private logger: RNGHLogger
8
-
9
- constructor(private rnInstance: RNInstance, logger: RNGHLogger) {
10
- this.logger = logger.cloneAndJoinPrefix("RNOHScrollLockerCAPI")
11
- }
12
-
13
- lockScrollContainingViewTag(viewTag: number) {
14
- this.rnInstance.postMessageToCpp('RNGH::SET_NATIVE_RESPONDERS_BLOCK', {
15
- targetTag: viewTag,
16
- shouldBlock: true,
17
- });
18
- return () => {
19
- this.rnInstance.postMessageToCpp('RNGH::SET_NATIVE_RESPONDERS_BLOCK', {
20
- targetTag: viewTag,
21
- shouldBlock: false,
22
- });
23
- };
24
- }
25
- }
@@ -1,25 +0,0 @@
1
- export enum TouchType {
2
- Down,
3
- Up,
4
- Move,
5
- Cancel
6
- }
7
-
8
- interface BaseEvent {
9
- timestamp: number;
10
- }
11
-
12
- export interface TouchObject {
13
- type: TouchType;
14
- id: number;
15
- windowX: number;
16
- windowY: number;
17
- x: number;
18
- y: number;
19
- }
20
-
21
- export interface TouchEvent extends BaseEvent {
22
- type: TouchType;
23
- touches: TouchObject[];
24
- changedTouches: TouchObject[];
25
- }
@@ -1,9 +0,0 @@
1
- {
2
- "module": {
3
- "name": "gesture_handler",
4
- "type": "har",
5
- "deviceTypes": [
6
- "default"
7
- ],
8
- }
9
- }
@@ -1,8 +0,0 @@
1
- {
2
- "color": [
3
- {
4
- "name": "start_window_background",
5
- "value": "#FFFFFF"
6
- }
7
- ]
8
- }
@@ -1,16 +0,0 @@
1
- {
2
- "string": [
3
- {
4
- "name": "module_desc",
5
- "value": "module description"
6
- },
7
- {
8
- "name": "WebviewAbility_desc",
9
- "value": "description"
10
- },
11
- {
12
- "name": "WebviewAbility_label",
13
- "value": "label"
14
- }
15
- ]
16
- }
@@ -1,5 +0,0 @@
1
- {
2
- "src": [
3
- "pages/Index"
4
- ]
5
- }
@@ -1,16 +0,0 @@
1
- {
2
- "string": [
3
- {
4
- "name": "module_desc",
5
- "value": "module description"
6
- },
7
- {
8
- "name": "WebviewAbility_desc",
9
- "value": "description"
10
- },
11
- {
12
- "name": "WebviewAbility_label",
13
- "value": "label"
14
- }
15
- ]
16
- }
@@ -1,16 +0,0 @@
1
- {
2
- "string": [
3
- {
4
- "name": "module_desc",
5
- "value": "模块描述"
6
- },
7
- {
8
- "name": "WebviewAbility_desc",
9
- "value": "description"
10
- },
11
- {
12
- "name": "WebviewAbility_label",
13
- "value": "label"
14
- }
15
- ]
16
- }
@@ -1,2 +0,0 @@
1
- export * from "./src/main/ets/rnoh/GestureHandlerPackage"
2
- export * from "./src/main/ets/rnoh/RNGestureHandlerModule"