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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. package/harmony/gesture_handler/BuildProfile.ets +6 -0
  2. package/harmony/gesture_handler/build-profile.json5 +18 -7
  3. package/harmony/gesture_handler/hvigorfile.ts +2 -2
  4. package/harmony/gesture_handler/index.ets +3 -3
  5. package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
  6. package/harmony/gesture_handler/oh-package.json5 +12 -11
  7. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
  8. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +103 -34
  9. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -15
  10. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -60
  11. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +27 -0
  12. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
  13. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -17
  14. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -12
  15. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +72 -0
  16. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -60
  17. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +123 -0
  18. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
  19. package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +42 -42
  20. package/harmony/gesture_handler/src/main/ets/Event.ts +67 -67
  21. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +52 -37
  22. package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
  23. package/harmony/gesture_handler/src/main/ets/{GestureHandlerArkUIAdapter.ets → GestureHandlerArkUIAdapter.ts} +202 -201
  24. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +44 -44
  25. package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +280 -280
  26. package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +22 -22
  27. package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +27 -27
  28. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +108 -108
  29. package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +182 -182
  30. package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +114 -114
  31. package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +33 -33
  32. package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +327 -327
  33. package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +239 -239
  34. package/harmony/gesture_handler/src/main/ets/RNGHError.ts +4 -4
  35. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +47 -28
  36. package/harmony/gesture_handler/src/main/ets/{RNGHRootTouchHandler.ets → RNGHRootTouchHandlerArkTS.ts} +59 -57
  37. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +87 -0
  38. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +37 -36
  39. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +183 -125
  40. package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +52 -55
  41. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +23 -11
  42. package/harmony/gesture_handler/src/main/ets/State.ts +46 -46
  43. package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +205 -205
  44. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +36 -36
  45. package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +98 -98
  46. package/harmony/gesture_handler/src/main/ets/View.ts +70 -70
  47. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +42 -42
  48. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +140 -0
  49. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +25 -0
  50. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +101 -0
  51. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +3 -0
  52. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
  53. package/harmony/gesture_handler/src/main/ets/types.ts +25 -0
  54. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
  55. package/harmony/gesture_handler/src/main/module.json5 +7 -7
  56. package/harmony/gesture_handler/src/main/resources/base/element/color.json +7 -7
  57. package/harmony/gesture_handler/src/main/resources/base/element/string.json +15 -15
  58. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -5
  59. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +15 -15
  60. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +15 -15
  61. package/harmony/gesture_handler/ts.ts +2 -1
  62. package/harmony/gesture_handler.har +0 -0
  63. package/lib/commonjs/RNGestureHandlerModule.js +6 -3
  64. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  65. package/lib/commonjs/components/GestureHandlerRootView.js +5 -13
  66. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  67. package/lib/commonjs/handlers/createHandler.js +31 -28
  68. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  69. package/lib/commonjs/index.js +42 -19
  70. package/lib/commonjs/index.js.map +1 -1
  71. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +10 -0
  72. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
  73. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +11 -0
  74. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  75. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +11 -0
  76. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  77. package/lib/module/RNGestureHandlerModule.js +3 -2
  78. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  79. package/lib/module/components/GestureHandlerRootView.js +3 -11
  80. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  81. package/lib/module/handlers/createHandler.js +20 -19
  82. package/lib/module/handlers/createHandler.js.map +1 -1
  83. package/lib/module/index.js +6 -14
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
  86. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
  87. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js +3 -0
  88. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  89. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js +3 -0
  90. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  91. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -6
  92. package/lib/typescript/RNGestureHandlerModule.d.ts.map +1 -1
  93. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  94. package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
  95. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  96. package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
  97. package/lib/typescript/index.d.ts +9 -8
  98. package/lib/typescript/index.d.ts.map +1 -1
  99. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +15 -0
  100. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -0
  101. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +15 -0
  102. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -0
  103. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +7 -0
  104. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -0
  105. package/package.json +66 -70
  106. package/src/RNGestureHandlerModule.ts +5 -6
  107. package/src/components/GestureHandlerRootView.tsx +23 -34
  108. package/src/handlers/createHandler.tsx +534 -535
  109. package/src/index.ts +172 -172
  110. package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
  111. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -0
  112. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -0
  113. package/README.md +0 -1
  114. package/lib/commonjs/components/GestureButtons.js +0 -186
  115. package/lib/commonjs/components/GestureButtons.js.map +0 -1
  116. package/lib/commonjs/components/GestureHandlerButton.js +0 -9
  117. package/lib/commonjs/components/GestureHandlerButton.js.map +0 -1
  118. package/lib/commonjs/components/RNGestureHandlerButton.js +0 -23
  119. package/lib/commonjs/components/RNGestureHandlerButton.js.map +0 -1
  120. package/lib/commonjs/components/touchables/GenericTouchable.js +0 -247
  121. package/lib/commonjs/components/touchables/GenericTouchable.js.map +0 -1
  122. package/lib/commonjs/components/touchables/TouchableOpacity.js +0 -58
  123. package/lib/commonjs/components/touchables/TouchableOpacity.js.map +0 -1
  124. package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js +0 -18
  125. package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +0 -1
  126. package/lib/commonjs/components/touchables/index.js +0 -21
  127. package/lib/commonjs/components/touchables/index.js.map +0 -1
  128. package/lib/commonjs/handlers/NativeViewGestureHandler.js +0 -19
  129. package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +0 -1
  130. package/lib/commonjs/handlers/PanGestureHandler.js +0 -103
  131. package/lib/commonjs/handlers/PanGestureHandler.js.map +0 -1
  132. package/lib/commonjs/handlers/TapGestureHandler.js +0 -22
  133. package/lib/commonjs/handlers/TapGestureHandler.js.map +0 -1
  134. package/lib/commonjs/handlers/createNativeWrapper.js +0 -64
  135. package/lib/commonjs/handlers/createNativeWrapper.js.map +0 -1
  136. package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -22
  137. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +0 -1
  138. package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -554
  139. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
  140. package/lib/commonjs/init.js +0 -24
  141. package/lib/commonjs/init.js.map +0 -1
  142. package/lib/module/components/GestureButtons.js +0 -168
  143. package/lib/module/components/GestureButtons.js.map +0 -1
  144. package/lib/module/components/GestureHandlerButton.js +0 -3
  145. package/lib/module/components/GestureHandlerButton.js.map +0 -1
  146. package/lib/module/components/RNGestureHandlerButton.js +0 -17
  147. package/lib/module/components/RNGestureHandlerButton.js.map +0 -1
  148. package/lib/module/components/touchables/GenericTouchable.js +0 -238
  149. package/lib/module/components/touchables/GenericTouchable.js.map +0 -1
  150. package/lib/module/components/touchables/TouchableOpacity.js +0 -49
  151. package/lib/module/components/touchables/TouchableOpacity.js.map +0 -1
  152. package/lib/module/components/touchables/TouchableWithoutFeedback.js +0 -9
  153. package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +0 -1
  154. package/lib/module/components/touchables/index.js +0 -8
  155. package/lib/module/components/touchables/index.js.map +0 -1
  156. package/lib/module/handlers/NativeViewGestureHandler.js +0 -12
  157. package/lib/module/handlers/NativeViewGestureHandler.js.map +0 -1
  158. package/lib/module/handlers/PanGestureHandler.js +0 -92
  159. package/lib/module/handlers/PanGestureHandler.js.map +0 -1
  160. package/lib/module/handlers/TapGestureHandler.js +0 -14
  161. package/lib/module/handlers/TapGestureHandler.js.map +0 -1
  162. package/lib/module/handlers/createNativeWrapper.js +0 -57
  163. package/lib/module/handlers/createNativeWrapper.js.map +0 -1
  164. package/lib/module/handlers/gestureHandlerCommon.js +0 -15
  165. package/lib/module/handlers/gestureHandlerCommon.js.map +0 -1
  166. package/lib/module/handlers/gestures/GestureDetector.js +0 -543
  167. package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
  168. package/lib/module/init.js +0 -17
  169. package/lib/module/init.js.map +0 -1
  170. package/lib/typescript/components/GestureButtons.d.ts +0 -122
  171. package/lib/typescript/components/GestureButtons.d.ts.map +0 -1
  172. package/lib/typescript/components/GestureHandlerButton.d.ts +0 -5
  173. package/lib/typescript/components/GestureHandlerButton.d.ts.map +0 -1
  174. package/lib/typescript/components/RNGestureHandlerButton.d.ts +0 -2
  175. package/lib/typescript/components/RNGestureHandlerButton.d.ts.map +0 -1
  176. package/lib/typescript/components/touchables/GenericTouchable.d.ts +0 -68
  177. package/lib/typescript/components/touchables/GenericTouchable.d.ts.map +0 -1
  178. package/lib/typescript/components/touchables/TouchableOpacity.d.ts +0 -26
  179. package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +0 -1
  180. package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +0 -8
  181. package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts.map +0 -1
  182. package/lib/typescript/components/touchables/index.d.ts +0 -4
  183. package/lib/typescript/components/touchables/index.d.ts.map +0 -1
  184. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +0 -29
  185. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts.map +0 -1
  186. package/lib/typescript/handlers/PanGestureHandler.d.ts +0 -140
  187. package/lib/typescript/handlers/PanGestureHandler.d.ts.map +0 -1
  188. package/lib/typescript/handlers/TapGestureHandler.d.ts +0 -58
  189. package/lib/typescript/handlers/TapGestureHandler.d.ts.map +0 -1
  190. package/lib/typescript/handlers/createNativeWrapper.d.ts +0 -4
  191. package/lib/typescript/handlers/createNativeWrapper.d.ts.map +0 -1
  192. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -2
  193. package/lib/typescript/handlers/gestureHandlerCommon.d.ts.map +0 -1
  194. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -24
  195. package/lib/typescript/handlers/gestures/GestureDetector.d.ts.map +0 -1
  196. package/lib/typescript/init.d.ts +0 -3
  197. package/lib/typescript/init.d.ts.map +0 -1
  198. package/src/components/GestureButtons.tsx +0 -334
  199. package/src/components/GestureHandlerButton.tsx +0 -5
  200. package/src/components/RNGestureHandlerButton.tsx +0 -23
  201. package/src/components/touchables/GenericTouchable.tsx +0 -301
  202. package/src/components/touchables/TouchableOpacity.tsx +0 -76
  203. package/src/components/touchables/TouchableWithoutFeedback.tsx +0 -14
  204. package/src/components/touchables/index.ts +0 -7
  205. package/src/handlers/NativeViewGestureHandler.ts +0 -55
  206. package/src/handlers/PanGestureHandler.ts +0 -327
  207. package/src/handlers/TapGestureHandler.ts +0 -95
  208. package/src/handlers/createNativeWrapper.tsx +0 -81
  209. package/src/handlers/gestureHandlerCommon.ts +0 -15
  210. package/src/handlers/gestures/GestureDetector.tsx +0 -823
  211. package/src/init.ts +0 -18
@@ -1,58 +1,60 @@
1
- import { Tag } from "rnoh"
2
- import { GestureHandlerRegistry } from "./GestureHandlerRegistry"
3
- import { GestureHandlerArkUIAdapter } from "./GestureHandlerArkUIAdapter"
4
- import { ViewRegistry } from "./ViewRegistry"
5
- import { RNGHLogger } from './RNGHLogger'
6
-
7
-
8
- export class RNGHRootTouchHandler {
9
- private adapterByViewTag: Map<number, GestureHandlerArkUIAdapter> = new Map() // TODO: remove an adapter when a view or gesture handler is removed
10
- private activeViewTags: number[] = []
11
- private viewRegistry: ViewRegistry
12
- private gestureHandlerRegistry: GestureHandlerRegistry
13
- private logger: RNGHLogger
14
- private rootTag: Tag
15
-
16
- constructor(rootTag: Tag, viewRegistry: ViewRegistry, gestureHandlerRegistry: GestureHandlerRegistry, logger: RNGHLogger) {
17
- this.rootTag = rootTag
18
- this.viewRegistry = viewRegistry
19
- this.gestureHandlerRegistry = gestureHandlerRegistry
20
- this.logger = logger
21
- }
22
-
23
- public handleTouch(e: TouchEvent) {
24
- if (e.type === TouchType.Down) {
25
- this.activeViewTags = []
26
- }
27
- for (const changedTouch of e.changedTouches) {
28
- const views = this.viewRegistry.getTouchableViewsAt({
29
- x: changedTouch.windowX,
30
- y: changedTouch.windowY
31
- }, this.rootTag)
32
- for (const view of views) {
33
- for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag())) {
34
- this.logger.info(`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`)
35
- if (!this.adapterByViewTag.has(view.getTag()))
36
- this.adapterByViewTag.set(view.getTag(), new GestureHandlerArkUIAdapter(handler, view, this.logger.cloneWithPrefix("ArkUIAdapter")))
37
- if (!this.activeViewTags.includes(view.getTag())) {
38
- const adapter = this.adapterByViewTag.get(view.getTag())
39
- if (adapter) {
40
- adapter.handleTouch(e)
41
- } else {
42
- console.warn("RNGH: Couldn't find adapter")
43
- }
44
- }
45
- if (e.type === TouchType.Down) {
46
- this.activeViewTags.push(view.getTag())
47
- }
48
- }
49
- }
50
- for (const viewTag of this.activeViewTags) {
51
- const adapter = this.adapterByViewTag.get(viewTag)
52
- if (adapter) {
53
- adapter.handleTouch(e)
54
- }
55
- }
56
- }
57
- }
1
+ import { Tag } from "@rnoh/react-native-openharmony/ts"
2
+ import { GestureHandlerRegistry } from "./GestureHandlerRegistry"
3
+ import { GestureHandlerArkUIAdapter } from "./GestureHandlerArkUIAdapter"
4
+ import { ViewRegistry } from "./ViewRegistry"
5
+ import { RNGHLogger } from './RNGHLogger'
6
+ import { TouchEvent, TouchType } from "./types"
7
+
8
+
9
+ export class RNGHRootTouchHandlerArkTS {
10
+ private adapterByViewTag: Map<number, GestureHandlerArkUIAdapter> = new Map() // TODO: remove an adapter when a view or gesture handler is removed
11
+ private activeViewTags: number[] = []
12
+ private viewRegistry: ViewRegistry
13
+ private gestureHandlerRegistry: GestureHandlerRegistry
14
+ private logger: RNGHLogger
15
+ private rootTag: Tag
16
+
17
+ constructor(rootTag: Tag, viewRegistry: ViewRegistry, gestureHandlerRegistry: GestureHandlerRegistry, logger: RNGHLogger) {
18
+ this.rootTag = rootTag
19
+ this.viewRegistry = viewRegistry
20
+ this.gestureHandlerRegistry = gestureHandlerRegistry
21
+ this.logger = logger
22
+ }
23
+
24
+ public handleTouch(touchEvent: any) {
25
+ const e = touchEvent as TouchEvent
26
+ if (e.type === TouchType.Down) {
27
+ this.activeViewTags = []
28
+ }
29
+ for (const changedTouch of e.changedTouches) {
30
+ const views = this.viewRegistry.getTouchableViewsAt({
31
+ x: changedTouch.windowX,
32
+ y: changedTouch.windowY
33
+ }, this.rootTag)
34
+ for (const view of views) {
35
+ for (const handler of this.gestureHandlerRegistry.getGestureHandlersByViewTag(view.getTag())) {
36
+ this.logger.info(`Found GestureHandler ${handler.getTag()} for view ${view.getTag()}`)
37
+ if (!this.adapterByViewTag.has(view.getTag()))
38
+ this.adapterByViewTag.set(view.getTag(), new GestureHandlerArkUIAdapter(handler, view, this.logger.cloneWithPrefix("ArkUIAdapter")))
39
+ if (!this.activeViewTags.includes(view.getTag())) {
40
+ const adapter = this.adapterByViewTag.get(view.getTag())
41
+ if (adapter) {
42
+ adapter.handleTouch(e)
43
+ } else {
44
+ console.warn("RNGH: Couldn't find adapter")
45
+ }
46
+ }
47
+ if (e.type === TouchType.Down) {
48
+ this.activeViewTags.push(view.getTag())
49
+ }
50
+ }
51
+ }
52
+ for (const viewTag of this.activeViewTags) {
53
+ const adapter = this.adapterByViewTag.get(viewTag)
54
+ if (adapter) {
55
+ adapter.handleTouch(e)
56
+ }
57
+ }
58
+ }
59
+ }
58
60
  }
@@ -0,0 +1,87 @@
1
+ import { RNGHRootTouchHandlerArkTS } from "./RNGHRootTouchHandlerArkTS"
2
+ import { TouchEvent as TouchEventArkTS, TouchType, TouchObject } from "./types"
3
+ import { RNGHLogger } from "./RNGHLogger"
4
+
5
+ type RawTouchPoint = {
6
+ contactAreaHeight: number
7
+ contactAreaWidth: number
8
+ id: number
9
+ nodeX: number
10
+ nodeY: number
11
+ pressedTime: number
12
+ pressure: number
13
+ rawX: number
14
+ rawY: number
15
+ screenX: number
16
+ screenY: number
17
+ tiltX: number
18
+ tiltY: number
19
+ toolHeight: number
20
+ toolType: number
21
+ toolWidth: number
22
+ toolX: number
23
+ toolY: number
24
+ windowX: number
25
+ windowY: number
26
+ }
27
+
28
+ export type RawTouchEvent = {
29
+ action: number,
30
+ actionTouch: RawTouchPoint,
31
+ touchPoints: RawTouchPoint[],
32
+ sourceType: number,
33
+ timestamp: number
34
+ }
35
+
36
+ class TouchEvent {
37
+ constructor(private raw: RawTouchEvent) {
38
+ }
39
+
40
+ asTouchEventArkTS(): TouchEventArkTS {
41
+ const touchType = this.touchTypeFromAction(this.raw.action)
42
+ return {
43
+ type: this.touchTypeFromAction(this.raw.action),
44
+ touches: this.raw.touchPoints.map(tp => this.touchObjectFromTouchPoint(tp, touchType)),
45
+ changedTouches: [this.touchObjectFromTouchPoint(this.raw.actionTouch, touchType)],
46
+ timestamp: this.raw.timestamp
47
+ }
48
+ }
49
+
50
+ private touchTypeFromAction(action: number): TouchType {
51
+ switch (action) {
52
+ case 1:
53
+ return TouchType.Down
54
+ case 2:
55
+ return TouchType.Move
56
+ case 3:
57
+ return TouchType.Up
58
+ default:
59
+ return TouchType.Cancel
60
+ }
61
+ }
62
+
63
+ private touchObjectFromTouchPoint(touchPoint: RawTouchPoint, touchType: TouchType): TouchObject {
64
+ return {
65
+ id: touchPoint.id,
66
+ windowX: touchPoint.windowX,
67
+ windowY: touchPoint.windowY,
68
+ x: touchPoint.windowX,
69
+ y: touchPoint.windowY,
70
+ type: touchType
71
+ }
72
+ }
73
+ }
74
+
75
+ export class RNGHRootTouchHandlerCAPI {
76
+ private logger: RNGHLogger
77
+
78
+ constructor(logger: RNGHLogger, private touchHandlerArkTS: RNGHRootTouchHandlerArkTS) {
79
+ this.logger = logger.cloneWithPrefix("RNGHRootTouchHandlerCAPI")
80
+ }
81
+
82
+ handleTouch(rawTouchEvent: RawTouchEvent) {
83
+ this.logger.cloneWithPrefix("handleTouch").debug(JSON.stringify(rawTouchEvent))
84
+ this.touchHandlerArkTS.handleTouch(new TouchEvent(rawTouchEvent).asTouchEventArkTS())
85
+ }
86
+ }
87
+
@@ -1,37 +1,38 @@
1
- import { Descriptor, RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "rnoh"
2
-
3
- export type RNGestureHandlerButtonDescriptor = Descriptor<"RNGestureHandlerButton">
4
-
5
- @Component
6
- export struct RNGestureHandlerButton {
7
- static readonly DESCRIPTOR_TYPE = "RNGestureHandlerButton"
8
- public ctx!: RNOHContext
9
- public tag: number = -1
10
- @BuilderParam public buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
11
-
12
- @State private descriptor: RNGestureHandlerButtonDescriptor = {} as RNGestureHandlerButtonDescriptor
13
- private unsubscribes: (() => void)[] = []
14
-
15
- aboutToAppear() {
16
- this.handleDescriptorChange(this.ctx.descriptorRegistry.getDescriptor<RNGestureHandlerButtonDescriptor>(this.tag))
17
- this.unsubscribes.push(this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag, (d) => {
18
- this.handleDescriptorChange(d as RNGestureHandlerButtonDescriptor)
19
- }))
20
- }
21
-
22
- aboutToDisappear() {
23
- this.unsubscribes.forEach(unsubscribe => unsubscribe())
24
- }
25
-
26
- handleDescriptorChange(newDescriptor: RNGestureHandlerButtonDescriptor) {
27
- this.descriptor = newDescriptor
28
- }
29
-
30
- build() {
31
- RNViewBase({ ctx: this.ctx, tag: this.tag }) {
32
- ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
33
- RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
34
- })
35
- }
36
- }
1
+ import { RNOHContext, RNViewBase, ComponentBuilderContext, RNComponentFactory, Tag } from "@rnoh/react-native-openharmony"
2
+ import { RNGestureHandlerButton as RNC } from "./namespace/RNGestureHandlerButton"
3
+
4
+ export type RNGestureHandlerButtonDescriptor = RNC.Descriptor
5
+
6
+ @Component
7
+ export struct RNGestureHandlerButton {
8
+ static readonly NAME = RNC.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
+ }
37
38
  }
@@ -1,125 +1,183 @@
1
- import { TurboModule, TurboModuleContext } from 'rnoh/ts';
2
- import { GestureHandlerRegistry } from './GestureHandlerRegistry';
3
- import { GestureHandlerFactory } from "./GestureHandlerFactory"
4
- import { ViewRegistry } from './ViewRegistry';
5
- import { RNGHLogger, StandardRNGHLogger, FakeRNGHLogger } from './RNGHLogger';
6
- import { EventDispatcher, JSEventDispatcher, AnimatedEventDispatcher } from './EventDispatcher'
7
- import { RNOHScrollLocker } from "./RNOHScrollLocker"
8
-
9
- export enum ActionType {
10
- REANIMATED_WORKLET = 1,
11
- NATIVE_ANIMATED_EVENT = 2,
12
- JS_FUNCTION_OLD_API = 3,
13
- JS_FUNCTION_NEW_API = 4,
14
- }
15
-
16
-
17
- export class RNGestureHandlerModule extends TurboModule {
18
- static NAME = "RNGestureHandlerModule"
19
-
20
- private gestureHandlerRegistry = new GestureHandlerRegistry()
21
- private gestureHandlerFactory: GestureHandlerFactory | undefined = undefined
22
- private viewRegistry: ViewRegistry | undefined = undefined
23
- private logger: RNGHLogger
24
-
25
- constructor(ctx: TurboModuleContext) {
26
- super(ctx)
27
- const debug = false
28
- this.logger = debug ? new StandardRNGHLogger(ctx.logger, "RNGH") : new FakeRNGHLogger()
29
- }
30
-
31
- public install() {
32
- this.viewRegistry = new ViewRegistry(this.ctx.descriptorRegistry, this.ctx.componentManagerRegistry)
33
- this.gestureHandlerFactory = new GestureHandlerFactory(this.logger, new RNOHScrollLocker(this.ctx.rnInstance))
34
- }
35
-
36
- public createGestureHandler(
37
- handlerName: string,
38
- handlerTag: number,
39
- config: Readonly<Record<string, unknown>>
40
- ) {
41
- if (!this.gestureHandlerFactory) {
42
- this.ctx.logger.error("Trying to create a gesture handler before creating gesture handler factory")
43
- return
44
- }
45
- const gestureHandler = this.gestureHandlerFactory.create(handlerName, handlerTag)
46
- this.gestureHandlerRegistry.addGestureHandler(gestureHandler)
47
- gestureHandler.updateGestureConfig(config)
48
- }
49
-
50
- public attachGestureHandler(
51
- handlerTag: number,
52
- viewTag: number,
53
- actionType: ActionType
54
- ) {
55
- const eventDispatcher = this.createEventDispatcher(actionType, viewTag)
56
- if (!eventDispatcher) {
57
- this.ctx.logger.error("RNGH: Couldn't create EventDispatcher")
58
- return
59
- }
60
- const view = this.viewRegistry.getViewByTag(viewTag)
61
- if (!view) {
62
- this.ctx.logger.error(`RNGH: Couldn't attachGestureHandler to view ${viewTag}`)
63
- return;
64
- }
65
- this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
66
- this.gestureHandlerRegistry
67
- .getGestureHandlerByHandlerTag(handlerTag)
68
- .setEventDispatcher(eventDispatcher)
69
- }
70
-
71
- private createEventDispatcher(actionType: ActionType, viewTag: number): EventDispatcher | null {
72
- switch (actionType) {
73
- case ActionType.REANIMATED_WORKLET:
74
- this.ctx.logger.error("RNGH: Reanimated Worklets are not supported")
75
- break;
76
- case ActionType.NATIVE_ANIMATED_EVENT:
77
- return new AnimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('AnimatedEventDispatcher'), viewTag)
78
- case ActionType.JS_FUNCTION_OLD_API:
79
- case ActionType.JS_FUNCTION_NEW_API:
80
- return new JSEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('JSEventDispatcher'));
81
- }
82
- return null
83
- }
84
-
85
- public updateGestureHandler(
86
- handlerTag: number,
87
- newConfig: Readonly<Record<string, unknown>>
88
- ) {
89
- const gestureHandler = this.gestureHandlerRegistry.getGestureHandlerByHandlerTag(handlerTag)
90
- gestureHandler.updateGestureConfig(newConfig)
91
- }
92
-
93
- public dropGestureHandler(handlerTag: number) {
94
- this.warn("dropGestureHandler is not implemented")
95
- }
96
-
97
- public handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
98
- this.warn("handleSetJSResponder is not implemented")
99
- }
100
-
101
- public handleClearJSResponder() {
102
- this.warn("handleClearJSResponder is not implemented")
103
- }
104
-
105
- public flushOperations() {
106
- this.warn("flushOperations is not implemented")
107
- }
108
-
109
- // -------------------------------------------------------------------------------------------------------------------
110
- protected warn(message: string) {
111
- this.ctx.logger.warn("RNGH: " + message)
112
- }
113
-
114
- public getGestureHandlerRegistry() {
115
- return this.gestureHandlerRegistry
116
- }
117
-
118
- public getLogger() {
119
- return this.logger
120
- }
121
-
122
- public getViewRegistry() {
123
- return this.viewRegistry
124
- }
125
- }
1
+ import { TurboModule, TurboModuleContext, Tag } from '@rnoh/react-native-openharmony/ts';
2
+ // import { TM } from "rnoh/generated/ts"
3
+ import { GestureHandlerRegistry } from './GestureHandlerRegistry';
4
+ import { GestureHandlerFactory } from "./GestureHandlerFactory"
5
+ import { ViewRegistry } from './ViewRegistry';
6
+ import { RNGHLogger, StandardRNGHLogger, FakeRNGHLogger } from './RNGHLogger';
7
+ import {
8
+ EventDispatcher,
9
+ JSEventDispatcher,
10
+ AnimatedEventDispatcher,
11
+ ReanimatedEventDispatcher
12
+ } from './EventDispatcher'
13
+ import { RNOHScrollLockerArkTS, RNOHScrollLockerCAPI } from "./RNOHScrollLocker"
14
+ import { State } from './State';
15
+ import { RNGHRootTouchHandlerCAPI, RawTouchEvent } from "./RNGHRootTouchHandlerCAPI"
16
+ import { RNGHRootTouchHandlerArkTS } from './RNGHRootTouchHandlerArkTS';
17
+
18
+ export enum ActionType {
19
+ REANIMATED_WORKLET = 1,
20
+ NATIVE_ANIMATED_EVENT = 2,
21
+ JS_FUNCTION_OLD_API = 3,
22
+ JS_FUNCTION_NEW_API = 4,
23
+ }
24
+
25
+
26
+ export class RNGestureHandlerModule extends TurboModule {
27
+ // implements TM.RNGestureHandlerModule.Spec {
28
+ static NAME = "RNGestureHandlerModule"
29
+
30
+ private gestureHandlerRegistry = new GestureHandlerRegistry()
31
+ private gestureHandlerFactory: GestureHandlerFactory | undefined = undefined
32
+ private viewRegistry: ViewRegistry | undefined = undefined
33
+ private logger: RNGHLogger
34
+ private touchHandlerByRootTag = new Map<Tag, RNGHRootTouchHandlerCAPI>()
35
+
36
+ constructor(ctx: TurboModuleContext) {
37
+ super(ctx)
38
+ const debug = false
39
+ this.logger = debug ? new StandardRNGHLogger(ctx.logger, "RNGH") : new FakeRNGHLogger()
40
+ if (this.ctx.rnInstance.getArchitecture() === "C_API") {
41
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::TOUCH_EVENT", (e: any) => {
42
+ this.onTouch(e)
43
+ })
44
+ this.ctx.rnInstance.cppEventEmitter.subscribe("RNGH::ROOT_CREATED", (rootTag: any) => {
45
+ this.onGHRootCreated(rootTag)
46
+ })
47
+ }
48
+ }
49
+
50
+ private onGHRootCreated(rootTag: Tag) {
51
+ this.touchHandlerByRootTag.set(rootTag, new RNGHRootTouchHandlerCAPI(this.logger, new RNGHRootTouchHandlerArkTS(rootTag, this.viewRegistry, this.gestureHandlerRegistry, this.logger)));
52
+ }
53
+
54
+ private onTouch(e: RawTouchEvent & { rootTag: Tag }) {
55
+ const touchHandler = this.touchHandlerByRootTag.get(e.rootTag)
56
+ if (touchHandler) {
57
+ touchHandler.handleTouch(e);
58
+ } else {
59
+ this.logger.info(`Couldn't find touch handler for root tag: ${e.rootTag}`)
60
+ }
61
+
62
+ }
63
+
64
+ public install() {
65
+ this.viewRegistry = new ViewRegistry(this.ctx.descriptorRegistry, this.ctx.componentManagerRegistry)
66
+ const scrollLocker = this.ctx.rnInstance.getArchitecture() === "ARK_TS" ? new RNOHScrollLockerArkTS(this.ctx.rnInstance) : new RNOHScrollLockerCAPI(this.ctx.rnInstance);
67
+ this.gestureHandlerFactory = new GestureHandlerFactory(this.logger, scrollLocker)
68
+ return true
69
+ }
70
+
71
+ public createGestureHandler(
72
+ handlerName: string,
73
+ handlerTag: number,
74
+ config: Readonly<Record<string, unknown>>
75
+ ) {
76
+ if (!this.gestureHandlerFactory) {
77
+ this.ctx.logger.error("Trying to create a gesture handler before creating gesture handler factory")
78
+ return
79
+ }
80
+ const gestureHandler = this.gestureHandlerFactory.create(handlerName, handlerTag)
81
+ this.gestureHandlerRegistry.addGestureHandler(gestureHandler)
82
+ gestureHandler.updateGestureConfig(config)
83
+ }
84
+
85
+ public attachGestureHandler(
86
+ handlerTag: number,
87
+ viewTag: number,
88
+ actionType: ActionType
89
+ ) {
90
+ const eventDispatcher = this.createEventDispatcher(actionType, viewTag)
91
+ if (!eventDispatcher) {
92
+ this.ctx.logger.error("RNGH: Couldn't create EventDispatcher")
93
+ return
94
+ }
95
+ const view = this.viewRegistry.getViewByTag(viewTag)
96
+ if (!view) {
97
+ this.ctx.logger.error(`RNGH: Couldn't attachGestureHandler to view ${viewTag}`)
98
+ return;
99
+ }
100
+ this.gestureHandlerRegistry.bindGestureHandlerWithView(handlerTag, view)
101
+ this.gestureHandlerRegistry
102
+ .getGestureHandlerByHandlerTag(handlerTag)
103
+ .setEventDispatcher(eventDispatcher)
104
+ }
105
+
106
+ private createEventDispatcher(actionType: ActionType, viewTag: number): EventDispatcher | null {
107
+ switch (actionType) {
108
+ case ActionType.REANIMATED_WORKLET:
109
+ return new ReanimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('ReanimatedEventDispatcher'), viewTag)
110
+ case ActionType.NATIVE_ANIMATED_EVENT:
111
+ return new AnimatedEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('AnimatedEventDispatcher'), viewTag)
112
+ case ActionType.JS_FUNCTION_OLD_API:
113
+ case ActionType.JS_FUNCTION_NEW_API:
114
+ return new JSEventDispatcher(this.ctx.rnInstance, this.logger.cloneWithPrefix('JSEventDispatcher'));
115
+ }
116
+ }
117
+
118
+ public updateGestureHandler(
119
+ handlerTag: number,
120
+ newConfig: Readonly<Record<string, unknown>>
121
+ ) {
122
+ const gestureHandler = this.gestureHandlerRegistry.getGestureHandlerByHandlerTag(handlerTag)
123
+ gestureHandler.updateGestureConfig(newConfig)
124
+ }
125
+
126
+ public dropGestureHandler(handlerTag: number) {
127
+ this.warn("dropGestureHandler is not implemented")
128
+ }
129
+
130
+ public handleSetJSResponder(tag: number, blockNativeResponder: boolean) {
131
+ this.warn("handleSetJSResponder is not implemented")
132
+ }
133
+
134
+ public handleClearJSResponder() {
135
+ this.warn("handleClearJSResponder is not implemented")
136
+ }
137
+
138
+ public flushOperations() {
139
+ this.warn("flushOperations is not implemented")
140
+ }
141
+
142
+ // -------------------------------------------------------------------------------------------------------------------
143
+ protected warn(message: string) {
144
+ this.ctx.logger.warn("RNGH: " + message)
145
+ }
146
+
147
+ public getGestureHandlerRegistry() {
148
+ return this.gestureHandlerRegistry
149
+ }
150
+
151
+ public getLogger() {
152
+ return this.logger
153
+ }
154
+
155
+ public getViewRegistry() {
156
+ if (!this.viewRegistry) {
157
+ this.logger.info("Tried to get viewRegistry before it was initialized")
158
+ throw new Error("Tried to get viewRegistry before it was initialized")
159
+ }
160
+ return this.viewRegistry
161
+ }
162
+
163
+ public setGestureHandlerState(handlerTag: number, newState: State) {
164
+ const handler = this.getGestureHandlerRegistry().getGestureHandlerByHandlerTag(handlerTag);
165
+ switch (newState) {
166
+ case State.ACTIVE:
167
+ handler.activate();
168
+ break;
169
+ case State.BEGAN:
170
+ handler.begin();
171
+ break;
172
+ case State.END:
173
+ handler.end();
174
+ break;
175
+ case State.FAILED:
176
+ handler.fail();
177
+ break;
178
+ case State.CANCELLED:
179
+ handler.cancel();
180
+ break;
181
+ }
182
+ }
183
+ }