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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. package/DrawerLayout/index.ts +2 -2
  2. package/Swipeable/index.ts +2 -2
  3. package/harmony/gesture_handler/BuildProfile.ets +17 -0
  4. package/harmony/gesture_handler/build-profile.json5 +19 -0
  5. package/harmony/gesture_handler/hvigorfile.ts +2 -0
  6. package/harmony/gesture_handler/index.ets +3 -0
  7. package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
  8. package/harmony/gesture_handler/oh-package.json5 +12 -0
  9. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -0
  10. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +149 -0
  11. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -0
  12. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -0
  13. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
  14. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -0
  15. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -0
  16. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -0
  17. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
  18. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +27 -0
  19. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +234 -0
  20. package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +42 -0
  21. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +684 -0
  22. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +335 -0
  23. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +35 -0
  24. package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +78 -0
  25. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
  26. package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +182 -0
  27. package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +34 -0
  28. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
  29. package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +239 -0
  30. package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +5 -0
  31. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
  32. package/harmony/gesture_handler/src/main/ets/core/State.ts +47 -0
  33. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
  34. package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +106 -0
  35. package/harmony/gesture_handler/src/main/ets/core/View.ts +19 -0
  36. package/harmony/gesture_handler/src/main/ets/core/index.ts +13 -0
  37. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  38. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
  39. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
  40. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
  41. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
  42. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +113 -0
  43. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +342 -0
  44. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
  45. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
  46. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +206 -0
  47. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  48. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  49. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +24 -0
  50. package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerButton.ts +139 -0
  51. package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerRootView.ts +101 -0
  52. package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
  53. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -0
  54. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
  55. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +22 -0
  56. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
  57. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
  58. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +104 -0
  59. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
  60. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +38 -0
  61. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +230 -0
  62. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +53 -0
  63. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
  64. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
  65. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +119 -0
  66. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +95 -0
  67. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +25 -0
  68. package/harmony/gesture_handler/src/main/module.json5 +9 -0
  69. package/harmony/gesture_handler/src/main/resources/base/element/color.json +8 -0
  70. package/harmony/gesture_handler/src/main/resources/base/element/string.json +16 -0
  71. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  72. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -0
  73. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +16 -0
  74. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +16 -0
  75. package/harmony/gesture_handler/ts.ts +2 -0
  76. package/harmony/gesture_handler.har +0 -0
  77. package/lib/commonjs/RNGestureHandlerModule.js +3 -2
  78. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  79. package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
  80. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  81. package/lib/commonjs/handlers/createHandler.js +18 -15
  82. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  83. package/lib/commonjs/index.js +8 -5
  84. package/lib/commonjs/index.js.map +1 -1
  85. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +2 -1
  86. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  87. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +3 -2
  88. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  89. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +3 -2
  90. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  91. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  92. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  93. package/lib/module/handlers/createHandler.js +15 -12
  94. package/lib/module/handlers/createHandler.js.map +1 -1
  95. package/lib/module/index.js +1 -3
  96. package/lib/module/index.js.map +1 -1
  97. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  98. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  99. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  100. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  101. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  102. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  103. package/lib/typescript/index.d.ts +43 -42
  104. package/lib/typescript/index.d.ts.map +1 -1
  105. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  106. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  107. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  108. package/package.json +68 -69
  109. package/src/RNGestureHandlerModule.ts +4 -4
  110. package/src/components/GestureHandlerRootView.tsx +23 -23
  111. package/src/handlers/createHandler.tsx +534 -534
  112. package/src/index.ts +172 -172
  113. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  114. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  115. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
@@ -0,0 +1,38 @@
1
+ import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
2
+ import { RNC } from "../namespace/ts"
3
+
4
+ export type RNGestureHandlerButtonDescriptor = RNC.RNGestureHandlerButton.Descriptor
5
+
6
+ @Component
7
+ export struct RNGestureHandlerButton {
8
+ static readonly NAME = RNC.RNGestureHandlerButton.NAME
9
+ public ctx!: RNOHContext
10
+ public tag: number = -1
11
+ @BuilderParam public buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
12
+
13
+ @State private descriptor: RNGestureHandlerButtonDescriptor = {} as RNGestureHandlerButtonDescriptor
14
+ private unsubscribes: (() => void)[] = []
15
+
16
+ aboutToAppear() {
17
+ this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerButtonDescriptor>(this.tag))
18
+ this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
19
+ this.handleDescriptorChange(d as RNGestureHandlerButtonDescriptor)
20
+ }))
21
+ }
22
+
23
+ aboutToDisappear() {
24
+ this.unsubscribes.forEach(unsubscribe => unsubscribe())
25
+ }
26
+
27
+ handleDescriptorChange(newDescriptor: RNGestureHandlerButtonDescriptor) {
28
+ this.descriptor = newDescriptor
29
+ }
30
+
31
+ build() {
32
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
33
+ ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
34
+ RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
35
+ })
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,230 @@
1
+ import { TurboModule, TurboModuleContext, Tag } from "@rnoh/react-native-openharmony/ts";
2
+ import { TM } from "../namespace/ts"
3
+ import { GestureHandlerRegistry, State, OutgoingEventDispatcher, RNGHLogger, InteractionManager } from '../core';
4
+ import { GestureHandlerFactory } from "../gesture-handlers"
5
+ import { ViewRegistry, ViewRegistryArkTS, ViewRegistryCAPI } from './ViewRegistry';
6
+ import { StandardRNGHLogger, FakeRNGHLogger } from './Logger';
7
+ import { JSEventDispatcher, AnimatedEventDispatcher, ReanimatedEventDispatcher } from './OutgoingEventDispatchers'
8
+ import { RNOHScrollLockerArkTS, RNOHScrollLockerCAPI } from "./RNOHScrollLocker"
9
+ import { RNGHRootTouchHandlerCAPI, RawTouchEvent } from "./RNGHRootTouchHandlerCAPI"
10
+ import { RNGHRootTouchHandlerArkTS } from './RNGHRootTouchHandlerArkTS';
11
+ import { ViewCAPI } from "./View"
12
+ import { FakeRNGestureResponder, RNOHGestureResponder } from "./RNOHGestureResponder"
13
+
14
+ export enum ActionType {
15
+ REANIMATED_WORKLET = 1,
16
+ NATIVE_ANIMATED_EVENT = 2,
17
+ JS_FUNCTION_OLD_API = 3,
18
+ JS_FUNCTION_NEW_API = 4,
19
+ }
20
+
21
+
22
+ export class RNGestureHandlerModule extends TurboModule implements TM.RNGestureHandlerModule.Spec {
23
+ static NAME = "RNGestureHandlerModule"
24
+
25
+ private gestureHandlerRegistry: GestureHandlerRegistry
26
+ private gestureHandlerFactory: GestureHandlerFactory | undefined = undefined
27
+ private viewRegistry: ViewRegistry | undefined = undefined
28
+ private logger: RNGHLogger
29
+ private touchHandlerByRootTag = new Map<Tag, RNGHRootTouchHandlerCAPI>()
30
+ private interactionManager: InteractionManager
31
+
32
+ constructor(ctx: TurboModuleContext) {
33
+ super(ctx)
34
+ const debug = false
35
+ this.logger = debug ? new StandardRNGHLogger(ctx.logger, "RNGH") : new FakeRNGHLogger()
36
+ this.interactionManager = new InteractionManager(this.logger)
37
+ this.gestureHandlerRegistry = new GestureHandlerRegistry(this.logger)
38
+
39
+ if (this.ctx.rnInstance.getArchitecture() === "C_API") {
40
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::TOUCH_EVENT", (e: any) => {
41
+ this.onTouch(e)
42
+ })
43
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::ROOT_CREATED", (rootTag: any) => {
44
+ this.onGHRootCreated(rootTag)
45
+ })
46
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::CANCEL_TOUCHES", (rootTag: any) => {
47
+ const touchHandler = this.touchHandlerByRootTag.get(rootTag)
48
+ touchHandler?.cancelTouches()
49
+ })
50
+ }
51
+ }
52
+
53
+ /**
54
+ * @architecture: C-API
55
+ * Called from C++.
56
+ */
57
+ private onGHRootCreated(rootTag: Tag) {
58
+ this.touchHandlerByRootTag.set(rootTag, new RNGHRootTouchHandlerCAPI(this.logger, new RNGHRootTouchHandlerArkTS(rootTag, this.viewRegistry, this.gestureHandlerRegistry, this.logger)));
59
+ }
60
+
61
+ /**
62
+ * @architecture: C-API
63
+ * Called from C++.
64
+ */
65
+ private onTouch(e: RawTouchEvent & { rootTag: Tag }) {
66
+ const logger = this.logger.cloneWithPrefix("onTouch")
67
+ if (!(this.viewRegistry instanceof ViewRegistryCAPI)) {
68
+ logger.error("Expected ViewRegistryCAPI")
69
+ return;
70
+ }
71
+ const touchHandler = this.touchHandlerByRootTag.get(e.rootTag)
72
+ if (!touchHandler) {
73
+ logger.error(`Couldn't find touch handler for gesture root tag: ${e.rootTag}`)
74
+ return;
75
+ }
76
+ // update view registry
77
+ e.touchableViews.forEach(touchableView => {
78
+ const view = this.viewRegistry.getViewByTag(touchableView.tag)
79
+ if (view) {
80
+ if (!(view instanceof ViewCAPI)) {
81
+ logger.error(`Expected ViewCAPI`)
82
+ return
83
+ }
84
+ view.updateBoundingBox(touchableView)
85
+ } else {
86
+ this.viewRegistry.save(new ViewCAPI(touchableView))
87
+ }
88
+ })
89
+ // relay touch
90
+ touchHandler.handleTouch(e, e.touchableViews.map(({tag}) => this.viewRegistry.getViewByTag(tag)));
91
+ }
92
+
93
+ // -------------------------------------------------------------------------------------------------------------------
94
+
95
+ public install() {
96
+ this.viewRegistry = this.ctx.rnInstance.getArchitecture() === "ARK_TS" ? new ViewRegistryArkTS(this.ctx.descriptorRegistry) : new ViewRegistryCAPI()
97
+ const scrollLocker = this.ctx.rnInstance.getArchitecture() === "ARK_TS" ? new RNOHScrollLockerArkTS(this.ctx.rnInstance) : new RNOHScrollLockerCAPI(this.ctx.rnInstance, this.logger);
98
+ const rnGestureResponder = this.ctx.rnInstance.getArchitecture() === "ARK_TS" ? new FakeRNGestureResponder() : new RNOHGestureResponder(this.ctx.rnInstance)
99
+ this.gestureHandlerFactory = new GestureHandlerFactory(this.logger, scrollLocker, this.interactionManager, rnGestureResponder)
100
+ return true
101
+ }
102
+
103
+ public createGestureHandler(
104
+ handlerName: string,
105
+ handlerTag: number,
106
+ config: Readonly<Record<string, unknown>>
107
+ ) {
108
+ const logger = this.logger.cloneWithPrefix("createGestureHandler")
109
+ if (!this.gestureHandlerFactory) {
110
+ this.ctx.logger.error("Trying to create a gesture handler before creating gesture handler factory")
111
+ return
112
+ }
113
+ logger.debug({ handlerName, handlerTag, config })
114
+ const gestureHandler = this.gestureHandlerFactory.create(handlerName, handlerTag)
115
+ this.gestureHandlerRegistry.addGestureHandler(gestureHandler)
116
+ this.interactionManager.configureInteractions(gestureHandler, config);
117
+ gestureHandler.updateGestureConfig(config)
118
+ }
119
+
120
+ public attachGestureHandler(
121
+ handlerTag: number,
122
+ viewTag: number,
123
+ actionType: ActionType
124
+ ) {
125
+ const eventDispatcher = this.createEventDispatcher(actionType, viewTag)
126
+ if (!eventDispatcher) {
127
+ this.ctx.logger.error("RNGH: Couldn't create EventDispatcher")
128
+ return
129
+ }
130
+ const viewRegistry = this.viewRegistry
131
+ let view = this.viewRegistry.getViewByTag(viewTag)
132
+ if (!view && viewRegistry instanceof ViewRegistryCAPI) {
133
+ view = new ViewCAPI({
134
+ tag: viewTag,
135
+ x: 0,
136
+ y: 0,
137
+ width: 0,
138
+ height: 0
139
+ })
140
+ viewRegistry.save(view)
141
+ }
142
+ if (!view) {
143
+ this.ctx.logger.error("Expected view")
144
+ return;
145
+ }
146
+ this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
147
+ this.gestureHandlerRegistry
148
+ .getGestureHandlerByHandlerTag(handlerTag)
149
+ .setEventDispatcher(eventDispatcher)
150
+ }
151
+
152
+ private createEventDispatcher(actionType: ActionType, viewTag: number): OutgoingEventDispatcher | null {
153
+ switch (actionType) {
154
+ case ActionType.REANIMATED_WORKLET:
155
+ return new ReanimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('ReanimatedEventDispatcher'), viewTag)
156
+ case ActionType.NATIVE_ANIMATED_EVENT:
157
+ return new AnimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('AnimatedEventDispatcher'), viewTag)
158
+ case ActionType.JS_FUNCTION_OLD_API:
159
+ case ActionType.JS_FUNCTION_NEW_API:
160
+ return new JSEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('JSEventDispatcher'));
161
+ }
162
+ }
163
+
164
+ public updateGestureHandler(
165
+ handlerTag: number,
166
+ newConfig: Readonly<Record<string, unknown>>
167
+ ) {
168
+ const gestureHandler = this.gestureHandlerRegistry.getGestureHandlerByHandlerTag(handlerTag)
169
+ this.interactionManager.configureInteractions(gestureHandler, newConfig);
170
+ gestureHandler.updateGestureConfig(newConfig)
171
+ }
172
+
173
+ public dropGestureHandler(handlerTag: number) {
174
+ this.warn("dropGestureHandler is not implemented")
175
+ }
176
+
177
+ public handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
178
+ this.warn("handleSetJSResponder is not implemented")
179
+ }
180
+
181
+ public handleClearJSResponder() {
182
+ this.warn("handleClearJSResponder is not implemented")
183
+ }
184
+
185
+ public flushOperations() {
186
+ this.warn("flushOperations is not implemented")
187
+ }
188
+
189
+ // -------------------------------------------------------------------------------------------------------------------
190
+ protected warn(message: string) {
191
+ this.ctx.logger.warn("RNGH: " + message)
192
+ }
193
+
194
+ public getGestureHandlerRegistry() {
195
+ return this.gestureHandlerRegistry
196
+ }
197
+
198
+ public getLogger() {
199
+ return this.logger
200
+ }
201
+
202
+ public getViewRegistry() {
203
+ if (!this.viewRegistry) {
204
+ this.logger.info("Tried to get viewRegistry before it was initialized")
205
+ throw new Error("Tried to get viewRegistry before it was initialized")
206
+ }
207
+ return this.viewRegistry
208
+ }
209
+
210
+ public setGestureHandlerState(handlerTag: number, newState: State) {
211
+ const handler = this.getGestureHandlerRegistry().getGestureHandlerByHandlerTag(handlerTag);
212
+ switch (newState) {
213
+ case State.ACTIVE:
214
+ handler.activate();
215
+ break;
216
+ case State.BEGAN:
217
+ handler.begin();
218
+ break;
219
+ case State.END:
220
+ handler.end();
221
+ break;
222
+ case State.FAILED:
223
+ handler.fail();
224
+ break;
225
+ case State.CANCELLED:
226
+ handler.cancel();
227
+ break;
228
+ }
229
+ }
230
+ }
@@ -0,0 +1,53 @@
1
+ import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
2
+ import { RNC } from "../namespace/ts"
3
+ import { RNGHRootTouchHandlerArkTS as RNGHRootTouchHandler } from "./RNGHRootTouchHandlerArkTS"
4
+ import { RNGestureHandlerModule } from "./RNGestureHandlerModule"
5
+
6
+
7
+ export type RNGestureHandlerRootViewDescriptor = RNC.RNGestureHandlerRootView.Descriptor
8
+
9
+ @Component
10
+ export struct RNGestureHandlerRootView {
11
+ static readonly NAME = RNC.RNGestureHandlerRootView.NAME
12
+ ctx!: RNOHContext
13
+ tag: number = -1
14
+ @BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
15
+ @State descriptor: RNGestureHandlerRootViewDescriptor = {} as RNGestureHandlerRootViewDescriptor
16
+ private unsubscribes: (() => void)[] = []
17
+ private touchHandler: RNGHRootTouchHandler | undefined = undefined
18
+
19
+ aboutToAppear() {
20
+ const rnGestureHandlerModule = this.ctx.rnInstance.getTurboModule<RNGestureHandlerModule>(RNGestureHandlerModule.NAME)
21
+ const rootTag = this.ctx.descriptorRegistry.getDescriptorLineage(this.tag)[0].tag
22
+ this.touchHandler = new RNGHRootTouchHandler(rootTag, rnGestureHandlerModule.getViewRegistry(), rnGestureHandlerModule.getGestureHandlerRegistry(), rnGestureHandlerModule.getLogger())
23
+ this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerRootViewDescriptor>(this.tag))
24
+ this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
25
+ this.handleDescriptorChange(d as RNGestureHandlerRootViewDescriptor)
26
+ }))
27
+ }
28
+
29
+ aboutToDisappear() {
30
+ this.unsubscribes.forEach(unsubscribe => unsubscribe())
31
+ }
32
+
33
+ handleDescriptorChange(newDescriptor: RNGestureHandlerRootViewDescriptor) {
34
+ this.descriptor = newDescriptor
35
+ }
36
+
37
+ build() {
38
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
39
+ ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
40
+ RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
41
+ })
42
+ Stack() {
43
+ }
44
+ .width("100%")
45
+ .height("100%")
46
+ .onTouch((e) => {
47
+ this.touchHandler?.handleTouch(e)
48
+ })
49
+ .hitTestBehavior(HitTestMode.Transparent)
50
+
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,24 @@
1
+ import { RNInstance } from "@rnoh/react-native-openharmony/ts"
2
+ import { RNGestureResponder } from "../core"
3
+
4
+ export class FakeRNGestureResponder {
5
+ lock() {
6
+ // Cancelling RN events isn't supported in ArkTS architecture.
7
+ return () => {}
8
+ }
9
+ }
10
+
11
+ /**
12
+ * Used in C-API architecture.
13
+ */
14
+ export class RNOHGestureResponder implements RNGestureResponder {
15
+ constructor(private rnInstance: RNInstance) {
16
+ }
17
+
18
+ lock(viewTag: number): () => void {
19
+ this.rnInstance.postMessageToCpp("RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES", { descendantViewTag: viewTag, isHandlingTouches: true })
20
+ return () => {
21
+ this.rnInstance.postMessageToCpp("RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES", { descendantViewTag: viewTag, isHandlingTouches: false })
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,32 @@
1
+ import { RNInstance } from '@rnoh/react-native-openharmony/ts';
2
+ import { ScrollLocker, RNGHLogger } from '../core';
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
+ private logger: RNGHLogger
15
+
16
+ constructor(private rnInstance: RNInstance, logger: RNGHLogger) {
17
+ this.logger = logger.cloneWithPrefix("RNOHScrollLockerCAPI")
18
+ }
19
+
20
+ lockScrollContainingViewTag(viewTag: number) {
21
+ this.rnInstance.postMessageToCpp('RNGH::SET_NATIVE_RESPONDERS_BLOCK', {
22
+ targetTag: viewTag,
23
+ shouldBlock: true,
24
+ });
25
+ return () => {
26
+ this.rnInstance.postMessageToCpp('RNGH::SET_NATIVE_RESPONDERS_BLOCK', {
27
+ targetTag: viewTag,
28
+ shouldBlock: false,
29
+ });
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,119 @@
1
+ import { DescriptorRegistry, Descriptor, Tag } from '@rnoh/react-native-openharmony/ts';
2
+ import { View, Vector2D, BoundingBox } from "../core"
3
+
4
+
5
+ export type RawTouchableView = {
6
+ tag: number,
7
+ /**
8
+ * Relative to application window.
9
+ */
10
+ x: number,
11
+ /**
12
+ * Relative to application window.
13
+ */
14
+ y: number,
15
+ width: number,
16
+ height: number
17
+ }
18
+
19
+ export class ViewCAPI implements View {
20
+ private tag: number
21
+ private boundingBox: BoundingBox
22
+
23
+ constructor({ tag, ...boundingBox }: RawTouchableView) {
24
+ this.tag = tag
25
+ this.boundingBox = boundingBox
26
+ }
27
+
28
+ getTag(): number {
29
+ return this.tag
30
+ }
31
+
32
+ getBoundingRect(): BoundingBox {
33
+ return { ...this.boundingBox }
34
+ }
35
+
36
+ isPositionInBounds({x, y}: {
37
+ x: number;
38
+ y: number
39
+ }): boolean {
40
+ const rect = this.getBoundingRect();
41
+ return (
42
+ x >= rect.x &&
43
+ x <= rect.x + rect.width &&
44
+ y >= rect.y &&
45
+ y <= rect.y + rect.height
46
+ );
47
+ }
48
+
49
+ updateBoundingBox(boundingBox: BoundingBox) {
50
+ this.boundingBox = boundingBox
51
+ }
52
+ }
53
+
54
+ export class ViewArkTS implements View {
55
+ constructor(
56
+ private descriptorRegistry: DescriptorRegistry,
57
+ private viewTag: number,
58
+ ) {
59
+ }
60
+
61
+
62
+ public getTag(): Tag {
63
+ return this.viewTag;
64
+ }
65
+
66
+ public isPositionInBounds({x, y}: {
67
+ x: number;
68
+ y: number
69
+ }): boolean {
70
+ const rect = this.getBoundingRect();
71
+ return (
72
+ x >= rect.x &&
73
+ x <= rect.x + rect.width &&
74
+ y >= rect.y &&
75
+ y <= rect.y + rect.height
76
+ );
77
+ }
78
+
79
+ public getBoundingRect(): BoundingBox {
80
+ const d = this.getDescriptor();
81
+ if (!d) {
82
+ return { x: 0, y: 0, width: 0, height: 0 };
83
+ }
84
+ const offsetToAbsolutePosition = this.getOffsetToAbsolutePosition();
85
+ return {
86
+ x: d.layoutMetrics.frame.origin.x - offsetToAbsolutePosition.x,
87
+ y: d.layoutMetrics.frame.origin.y - offsetToAbsolutePosition.y,
88
+ width: d.layoutMetrics.frame.size.width,
89
+ height: d.layoutMetrics.frame.size.height,
90
+ };
91
+ }
92
+
93
+ private getDescriptor() {
94
+ return this.descriptorRegistry.getDescriptor(this.viewTag);
95
+ }
96
+
97
+ private getOffsetToAbsolutePosition(): Vector2D {
98
+ const currentOffset = new Vector2D();
99
+ let parentTag = this.getDescriptor()?.parentTag;
100
+ while (parentTag !== undefined) {
101
+ const d = this.descriptorRegistry.getDescriptor(parentTag);
102
+ currentOffset.add(this.extractScrollOffsetFromDescriptor(d));
103
+ currentOffset.subtract(new Vector2D(d.layoutMetrics.frame.origin));
104
+ parentTag = d.parentTag;
105
+ }
106
+ return currentOffset;
107
+ }
108
+
109
+ private extractScrollOffsetFromDescriptor(descriptor: Descriptor<any>) {
110
+ if (descriptor.type !== 'ScrollView') {
111
+ return new Vector2D();
112
+ }
113
+ const scrollViewState: any = descriptor.state;
114
+ return new Vector2D({
115
+ x: scrollViewState.contentOffsetX,
116
+ y: scrollViewState.contentOffsetY,
117
+ });
118
+ }
119
+ }
@@ -0,0 +1,95 @@
1
+ import { DescriptorRegistry, Tag, } from '@rnoh/react-native-openharmony/ts';
2
+ import { ViewArkTS } from './View';
3
+ import { View } from '../core';
4
+ import type { ViewFinder } from "./RNGHRootTouchHandlerArkTS"
5
+
6
+ export interface ViewRegistry extends ViewFinder {
7
+ getViewByTag(viewTag: Tag)
8
+ save(view: View)
9
+ }
10
+
11
+ export class ViewRegistryArkTS implements ViewRegistry {
12
+ constructor(
13
+ private descriptorRegistry: DescriptorRegistry,
14
+ ) {
15
+ }
16
+
17
+ getViewByTag(viewTag: Tag) {
18
+ return this.createView(viewTag);
19
+ }
20
+
21
+ save(view: View) {
22
+ /**
23
+ * Currently, a new View object is created when getViewByTag is called. That was the approach in initial "quick"
24
+ * implementation of this library. The save was introduced later, for the needs of implementation using C-API architecture.
25
+ * C-API architecture is going to replace ArkTS anyway, so there's no point of doing this properly since this class
26
+ * will be removed in the future.
27
+ */
28
+ }
29
+
30
+ private createView(tag: Tag): ViewArkTS {
31
+ return new ViewArkTS(this.descriptorRegistry, tag);
32
+ }
33
+
34
+ getTouchableViewsAt(
35
+ pos: {
36
+ x: number;
37
+ y: number;
38
+ },
39
+ rootTag: Tag,
40
+ ): ViewArkTS[] {
41
+ const rootView = this.createView(rootTag);
42
+ const results: ViewArkTS[] = [];
43
+ for (const view of this.getTouchableViewsAtPosInView(pos, rootView)) {
44
+ results.push(view);
45
+ }
46
+ return results;
47
+ }
48
+
49
+ private getTouchableViewsAtPosInView(
50
+ pos: {
51
+ x: number;
52
+ y: number;
53
+ },
54
+ view: ViewArkTS,
55
+ ) {
56
+ if (!view.isPositionInBounds(pos)) return [];
57
+ const results: ViewArkTS[] = [];
58
+ results.push(view);
59
+ for (const child of this.getChildrenOf(view.getTag())) {
60
+ for (const result of this.getTouchableViewsAtPosInView(pos, child)) {
61
+ results.push(result);
62
+ }
63
+ }
64
+ return results;
65
+ }
66
+
67
+ private getChildrenOf(viewTag: Tag): ViewArkTS[] {
68
+ return this.descriptorRegistry.findDescriptorWrapperByTag(viewTag).childrenTags.map((tag) => new ViewArkTS(this.descriptorRegistry, tag))
69
+ }
70
+ }
71
+
72
+
73
+ export class ViewRegistryCAPI implements ViewRegistry {
74
+ private viewByTag = new Map<Tag, View>()
75
+
76
+ save(view: View) {
77
+ this.viewByTag.set(view.getTag(), view)
78
+ }
79
+
80
+ getViewByTag(viewTag: Tag) {
81
+ return this.viewByTag.get(viewTag);
82
+ }
83
+
84
+ getTouchableViewsAt(
85
+ pos: {
86
+ x: number;
87
+ y: number;
88
+ },
89
+ rootTag: Tag,
90
+ ): ViewArkTS[] {
91
+ // Finding views is handled on CPP side and provided with the touch event.
92
+ // This method can be removed from ViewRegistry interface once support for ArkTS architecture is removed.
93
+ return []
94
+ }
95
+ }
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "module": {
3
+ "name": "gesture_handler",
4
+ "type": "har",
5
+ "deviceTypes": [
6
+ "default"
7
+ ],
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "color": [
3
+ {
4
+ "name": "start_window_background",
5
+ "value": "#FFFFFF"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "src": [
3
+ "pages/Index"
4
+ ]
5
+ }
@@ -0,0 +1,16 @@
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
+ }