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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/DrawerLayout/index.ts +2 -0
  2. package/Swipeable/index.ts +2 -0
  3. package/harmony/gesture_handler/BuildProfile.ets +15 -3
  4. package/harmony/gesture_handler/hvigorfile.ts +1 -1
  5. package/harmony/gesture_handler/index.ets +2 -2
  6. package/harmony/gesture_handler/oh-package-lock.json5 +4 -3
  7. package/harmony/gesture_handler/oh-package.json5 +3 -3
  8. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +64 -18
  9. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +3 -3
  10. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +2 -2
  11. package/harmony/gesture_handler/src/main/cpp/{RNGestureHandlerButtonComponentInstance.h → componentInstances/RNGestureHandlerButtonComponentInstance.h} +2 -2
  12. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +242 -0
  13. package/harmony/gesture_handler/src/main/ets/{GestureHandler.ts → core/GestureHandler.ts} +54 -27
  14. package/harmony/gesture_handler/src/main/ets/{GestureHandlerOrchestrator.ts → core/GestureHandlerOrchestrator.ts} +122 -67
  15. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +63 -0
  16. package/harmony/gesture_handler/src/main/ets/{Event.ts → core/IncomingEvent.ts} +30 -20
  17. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
  18. package/harmony/gesture_handler/src/main/ets/{OutgoingEvent.ts → core/OutgoingEvent.ts} +1 -1
  19. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
  20. package/harmony/gesture_handler/src/main/ets/{PointerTracker.ts → core/PointerTracker.ts} +4 -4
  21. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
  22. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
  23. package/harmony/gesture_handler/src/main/ets/{VelocityTracker.ts → core/VelocityTracker.ts} +13 -5
  24. package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
  25. package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +11 -0
  26. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +8 -0
  27. package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
  28. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  29. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
  30. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
  31. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
  32. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
  33. package/harmony/gesture_handler/src/main/ets/{NativeViewGestureHandler.ts → gesture-handlers/NativeViewGestureHandler.ts} +15 -15
  34. package/harmony/gesture_handler/src/main/ets/{PanGestureHandler.ts → gesture-handlers/PanGestureHandler.ts} +27 -13
  35. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
  36. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
  37. package/harmony/gesture_handler/src/main/ets/{TapGestureHandler.ts → gesture-handlers/TapGestureHandler.ts} +11 -11
  38. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  39. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  40. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +8 -9
  41. package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerButton.ts → components/RNGestureHandlerButton.ts} +35 -36
  42. package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerRootView.ts → components/RNGestureHandlerRootView.ts} +23 -23
  43. package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
  44. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -3
  45. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
  46. package/harmony/gesture_handler/src/main/ets/{GestureHandlerPackage.ts → rnoh/GestureHandlerPackage.ts} +4 -4
  47. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
  48. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
  49. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +98 -0
  50. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
  51. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerButton.ets → rnoh/RNGestureHandlerButton.ets} +3 -3
  52. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerModule.ts → rnoh/RNGestureHandlerModule.ts} +79 -29
  53. package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerRootView.ets → rnoh/RNGestureHandlerRootView.ets} +3 -3
  54. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
  55. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
  56. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +134 -0
  57. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +97 -0
  58. package/harmony/gesture_handler/src/main/module.json5 +8 -6
  59. package/harmony/gesture_handler/ts.ts +2 -2
  60. package/harmony/gesture_handler.har +0 -0
  61. package/lib/commonjs/index.js +126 -141
  62. package/lib/commonjs/index.js.map +1 -1
  63. package/lib/module/index.js +13 -146
  64. package/lib/module/index.js.map +1 -1
  65. package/lib/typescript/index.d.ts +39 -1
  66. package/lib/typescript/index.d.ts.map +1 -1
  67. package/package.json +13 -10
  68. package/src/index.ts +140 -140
  69. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
  70. package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -78
  71. package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
  72. package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
  73. package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
  74. package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +0 -28
  75. package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
  76. package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
  77. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
  78. package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
  79. package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
  80. package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
  81. package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
  82. package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
  83. package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
  84. package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
  85. /package/harmony/gesture_handler/src/main/ets/{CircularBuffer.ts → core/CircularBuffer.ts} +0 -0
  86. /package/harmony/gesture_handler/src/main/ets/{LeastSquareSolver.ts → core/LeastSquareSolver.ts} +0 -0
  87. /package/harmony/gesture_handler/src/main/ets/{RNGHError.ts → core/RNGHError.ts} +0 -0
  88. /package/harmony/gesture_handler/src/main/ets/{State.ts → core/State.ts} +0 -0
  89. /package/harmony/gesture_handler/src/main/ets/{types.ts → rnoh/types.ts} +0 -0
@@ -0,0 +1,2 @@
1
+ import DrawerLayout from 'react-native-gesture-handler/DrawerLayout';
2
+ export default DrawerLayout;
@@ -0,0 +1,2 @@
1
+ import Swipeable from 'react-native-gesture-handler/Swipeable';
2
+ export default Swipeable;
@@ -1,5 +1,17 @@
1
+ /**
2
+ * Use these variables when you tailor your ArkTS code. They must be of the const type.
3
+ */
4
+ export const HAR_VERSION = '2.14.1-2.14.13';
5
+ export const BUILD_MODE_NAME = 'release';
6
+ export const DEBUG = false;
7
+ export const TARGET_NAME = 'default';
8
+
9
+ /**
10
+ * BuildProfile Class is used only for compatibility purposes.
11
+ */
1
12
  export default class BuildProfile {
2
- static readonly HAR_VERSION = '2.12.9';
3
- static readonly BUILD_MODE_NAME = 'debug';
4
- static readonly DEBUG = true;
13
+ static readonly HAR_VERSION = HAR_VERSION;
14
+ static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
15
+ static readonly DEBUG = DEBUG;
16
+ static readonly TARGET_NAME = TARGET_NAME;
5
17
  }
@@ -1,2 +1,2 @@
1
1
  // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
2
- export { harTasks } from '@ohos/hvigor-ohos-plugin';
2
+ export { harTasks } from '@ohos/hvigor-ohos-plugin';
@@ -1,3 +1,3 @@
1
1
  export * from "./ts"
2
- export * from "./src/main/ets/RNGestureHandlerRootView"
3
- export * from "./src/main/ets/RNGestureHandlerButton"
2
+ export * from "./src/main/ets/rnoh/RNGestureHandlerRootView"
3
+ export * from "./src/main/ets/rnoh/RNGestureHandlerButton"
@@ -5,12 +5,13 @@
5
5
  "lockfileVersion": 3,
6
6
  "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
7
7
  "specifiers": {
8
- "@rnoh/react-native-openharmony@../rnoh": "@rnoh/react-native-openharmony@../rnoh"
8
+ "@rnoh/react-native-openharmony@../react_native_openharmony.har": "@rnoh/react-native-openharmony@../react_native_openharmony.har"
9
9
  },
10
10
  "packages": {
11
- "@rnoh/react-native-openharmony@../rnoh": {
11
+ "@rnoh/react-native-openharmony@../react_native_openharmony.har": {
12
12
  "name": "@rnoh/react-native-openharmony",
13
- "resolved": "../rnoh",
13
+ "version": "0.72.28",
14
+ "resolved": "../react_native_openharmony.har",
14
15
  "registryType": "local"
15
16
  }
16
17
  }
@@ -4,9 +4,9 @@
4
4
  author: '',
5
5
  name: '@react-native-oh-tpl/react-native-gesture-handler',
6
6
  description: '',
7
- main: 'index.ets',
8
- version: '2.12.9',
7
+ type: 'module',
8
+ version: '2.14.1-2.14.13',
9
9
  dependencies: {
10
- "@rnoh/react-native-openharmony": 'file:../rnoh',
10
+ "@rnoh/react-native-openharmony": "file:./react_native_openharmony"
11
11
  },
12
12
  }
@@ -1,14 +1,15 @@
1
1
  #pragma once
2
2
  #include "GestureHandlerPackage.h"
3
3
  #include "RNOH/RNInstanceCAPI.h"
4
- #include "RNGestureHandlerButtonComponentInstance.h"
5
- #include "RNGestureHandlerRootViewComponentInstance.h"
4
+ #include "componentInstances/RNGestureHandlerButtonComponentInstance.h"
5
+ #include "componentInstances/RNGestureHandlerRootViewComponentInstance.h"
6
6
  #include "RNOH/ArkTSTurboModule.h"
7
7
  #include "RNGestureHandlerModule.h"
8
8
  #include "RNGestureHandlerButtonComponentDescriptor.h"
9
9
  #include "RNGestureHandlerRootViewComponentDescriptor.h"
10
10
  #include "RNGestureHandlerButtonJSIBinder.h"
11
11
  #include "RNGestureHandlerRootViewJSIBinder.h"
12
+ #include <glog/logging.h>
12
13
 
13
14
  using namespace rnoh;
14
15
  using namespace facebook;
@@ -23,6 +24,7 @@ public:
23
24
  };
24
25
  };
25
26
 
27
+
26
28
  class RNGHEventEmitRequestHandler : public EventEmitRequestHandler {
27
29
  void handleEvent(EventEmitRequestHandler::Context const &ctx) override {
28
30
  auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::ViewEventEmitter>(ctx.tag);
@@ -30,7 +32,9 @@ class RNGHEventEmitRequestHandler : public EventEmitRequestHandler {
30
32
  return;
31
33
  }
32
34
  if (ctx.eventName == "onGestureHandlerEvent") {
33
- eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
35
+ eventEmitter->dispatchUniqueEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
36
+ } else if (ctx.eventName == "onGestureHandlerStateChange") {
37
+ eventEmitter->dispatchEvent("onGestureHandlerStateChange", ArkJS(ctx.env).getDynamic(ctx.payload));
34
38
  }
35
39
  }
36
40
  };
@@ -79,23 +83,65 @@ ComponentInstanceFactoryDelegate::Shared GestureHandlerPackage::createComponentI
79
83
 
80
84
  class ScrollLockerArkTSMessageHandler : public ArkTSMessageHandler {
81
85
  public:
82
- void handleArkTSMessage(const Context &ctx) override {
83
- if (ctx.messageName == "RNGH::SET_NATIVE_RESPONDERS_BLOCK") {
84
- auto targetComponentInstanceTag = ctx.messagePayload["targetTag"].asDouble();
85
- auto shouldBlock = ctx.messagePayload["shouldBlock"].asBool();
86
- auto rnInstance = ctx.rnInstance.lock();
87
- if (rnInstance != nullptr) {
88
- auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
89
- if (rnInstanceCAPI != nullptr) {
90
- auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(targetComponentInstanceTag);
91
- while (tmpComponentInstance != nullptr) {
92
- tmpComponentInstance->setNativeResponderBlocked(shouldBlock, "RNGH");
93
- tmpComponentInstance = tmpComponentInstance->getParent().lock();
94
- }
95
- }
86
+ void handleArkTSMessage(const Context &ctx) override {
87
+ if (ctx.messageName == "RNGH::SET_NATIVE_RESPONDERS_BLOCK") {
88
+ auto targetComponentInstanceTag = ctx.messagePayload["targetTag"].asDouble();
89
+ auto shouldBlock = ctx.messagePayload["shouldBlock"].asBool();
90
+ auto rnInstance = ctx.rnInstance.lock();
91
+ if (rnInstance != nullptr) {
92
+ auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
93
+ if (rnInstanceCAPI != nullptr) {
94
+
95
+ std::vector<ComponentInstance::Shared> ancestors;
96
+ auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(targetComponentInstanceTag);
97
+ while (tmpComponentInstance != nullptr) {
98
+ ancestors.push_back(tmpComponentInstance);
99
+ tmpComponentInstance = tmpComponentInstance->getParent().lock();
100
+ }
101
+ if (ancestors.size() == 0) {
102
+ return;
103
+ }
104
+ /**
105
+ * Ensure consistent behavior with Android by not blocking scrolls above the GestureHandlerRootView handling
106
+ * the touch. If there are multiple nested GestureHandlerRootViews, the one nearest to the actual root will
107
+ * handle the touch.
108
+ */
109
+ auto isChangingResponderStatusAllowed = false;
110
+ for (size_t i = ancestors.size() - 1; i > 0; i--) {
111
+ auto ancestor = ancestors[i];
112
+ if (!isChangingResponderStatusAllowed) {
113
+ auto rootView = std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
114
+ if (rootView != nullptr) {
115
+ isChangingResponderStatusAllowed = true;
116
+ }
117
+ } else {
118
+ ancestor->setNativeResponderBlocked(shouldBlock, "RNGH");
119
+ }
120
+ }
121
+ }
122
+ }
123
+ } else if (ctx.messageName == "RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES") {
124
+ auto descendantViewTag = ctx.messagePayload["descendantViewTag"].asDouble();
125
+ auto isHandlingTouches = ctx.messagePayload["isHandlingTouches"].asBool();
126
+ auto rnInstance = ctx.rnInstance.lock();
127
+ if (rnInstance != nullptr) {
128
+ auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
129
+ if (rnInstanceCAPI != nullptr) {
130
+ auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(descendantViewTag);
131
+ while (tmpComponentInstance != nullptr) {
132
+ tmpComponentInstance = tmpComponentInstance->getParent().lock();
133
+ if (tmpComponentInstance) {
134
+ auto rnghRootViewComponentInstance =
135
+ std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(tmpComponentInstance);
136
+ if (rnghRootViewComponentInstance) {
137
+ rnghRootViewComponentInstance->setIsHandlingTouches(isHandlingTouches);
138
+ }
96
139
  }
140
+ }
97
141
  }
98
- };
142
+ }
143
+ }
144
+ };
99
145
  };
100
146
 
101
147
  std::vector<ArkTSMessageHandler::Shared> GestureHandlerPackage::createArkTSMessageHandlers() {
@@ -5,13 +5,13 @@ namespace rnoh {
5
5
  class GestureHandlerPackage : public Package {
6
6
  public:
7
7
  GestureHandlerPackage(Package::Context ctx) : Package(ctx) {}
8
-
8
+
9
9
  std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override;
10
-
10
+
11
11
  std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override;
12
12
 
13
13
  ComponentJSIBinderByString createComponentJSIBinderByName() override;
14
-
14
+
15
15
  EventEmitRequestHandlers createEventEmitRequestHandlers();
16
16
 
17
17
  ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate();
@@ -12,12 +12,12 @@ class RNGestureHandlerRootViewJSIBinder : public ViewComponentJSIBinder {
12
12
  return object;
13
13
  }
14
14
 
15
- facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
15
+ facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
16
16
  facebook::jsi::Object events(rt);
17
17
  return events;
18
18
  }
19
19
 
20
- facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
20
+ facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
21
21
  facebook::jsi::Object events(rt);
22
22
  return events;
23
23
  }
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
  #import "RNOH/CppComponentInstance.h"
3
3
  #import "RNOH/arkui/StackNode.h"
4
- #import "RNGestureHandlerButtonComponentDescriptor.h"
4
+ #import "../RNGestureHandlerButtonComponentDescriptor.h"
5
5
 
6
6
  namespace rnoh {
7
7
  class RNGestureHandlerButtonComponentInstance
@@ -24,4 +24,4 @@ namespace rnoh {
24
24
  m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
25
25
  };
26
26
  };
27
- } // namespace rnoh
27
+ } // namespace rnoh
@@ -0,0 +1,242 @@
1
+ #pragma once
2
+ #import "RNOH/CppComponentInstance.h"
3
+ #import "RNOH/arkui/StackNode.h"
4
+ #import "RNOH/arkui/ArkUINodeRegistry.h"
5
+ #import "RNOH/arkui/NativeNodeApi.h"
6
+ #import "RNOH/RNInstanceCAPI.h"
7
+ #import "../RNGestureHandlerRootViewComponentDescriptor.h"
8
+ #import "RNGestureHandlerButtonComponentInstance.h"
9
+
10
+ namespace rnoh {
11
+ class RNGestureHandlerRootViewComponentInstance
12
+ : public CppComponentInstance<facebook::react::RNGestureHandlerRootViewShadowNode>,
13
+ public TouchEventHandler {
14
+ using Point = facebook::react::Point;
15
+
16
+ /**
17
+ * This function is borrowed from TouchEventDispatcher
18
+ */
19
+ static TouchTarget::Shared findTargetForTouchPoint(Point const &point, TouchTarget::Shared const &target) {
20
+ bool canHandleTouch =
21
+ target->canHandleTouch() && target->containsPoint(point) && (target->getTouchEventEmitter() != nullptr);
22
+ bool canChildrenHandleTouch = target->canChildrenHandleTouch() && target->containsPointInBoundingBox(point);
23
+
24
+ if (canChildrenHandleTouch) {
25
+ auto children = target->getTouchTargetChildren();
26
+ // we want to check the children in reverse order, since the last child is the topmost one
27
+ std::reverse(children.begin(), children.end());
28
+ for (auto const &child : children) {
29
+ auto childPoint = target->computeChildPoint(point, child);
30
+ auto result = findTargetForTouchPoint(childPoint, child);
31
+ if (result != nullptr) {
32
+ return result;
33
+ }
34
+ }
35
+ }
36
+ if (canHandleTouch) {
37
+ return target;
38
+ }
39
+ return nullptr;
40
+ }
41
+
42
+ private:
43
+ bool m_isHandlingTouches = false;
44
+ StackNode m_stackNode;
45
+
46
+ struct TouchableView {
47
+ Tag tag;
48
+ facebook::react::Float width;
49
+ facebook::react::Float height;
50
+ facebook::react::Float x;
51
+ facebook::react::Float y;
52
+ bool buttonRole;
53
+ };
54
+
55
+ public:
56
+ RNGestureHandlerRootViewComponentInstance(Context context) : CppComponentInstance(std::move(context)) {
57
+ ArkUINodeRegistry::getInstance().registerTouchHandler(&m_stackNode, this);
58
+ NativeNodeApi::getInstance()->registerNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT,
59
+ NODE_TOUCH_EVENT, 0);
60
+ auto rnInstance = m_deps->rnInstance.lock();
61
+ if (rnInstance) {
62
+ rnInstance->postMessageToArkTS("RNGH::ROOT_CREATED", m_tag);
63
+ }
64
+ };
65
+
66
+ ~RNGestureHandlerRootViewComponentInstance() override {
67
+ NativeNodeApi::getInstance()->unregisterNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT);
68
+ ArkUINodeRegistry::getInstance().unregisterTouchHandler(&m_stackNode);
69
+ }
70
+
71
+ StackNode &getLocalRootArkUINode() override { return m_stackNode; };
72
+
73
+ void onTouchEvent(ArkUI_UIInputEvent *e) override {
74
+ auto ancestor = this->getParent().lock();
75
+ while (ancestor != nullptr) {
76
+ auto ancestorRNGHRootView = std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
77
+ if (ancestorRNGHRootView != nullptr) {
78
+ // If there are multiple nested GestureHandlerRootViews, the one nearest to the actual root will handle the
79
+ // touch.
80
+ return;
81
+ }
82
+ ancestor = ancestor->getParent().lock();
83
+ }
84
+
85
+ auto ancestorTouchTarget = this->getTouchTargetParent();
86
+ auto rnInstance = m_deps->rnInstance.lock();
87
+ while (ancestorTouchTarget != nullptr) {
88
+ if (ancestorTouchTarget->isHandlingTouches()) {
89
+ rnInstance->postMessageToArkTS("RNGH::CANCEL_TOUCHES", m_tag);
90
+ return;
91
+ }
92
+ ancestorTouchTarget = ancestorTouchTarget->getTouchTargetParent();
93
+ }
94
+
95
+ folly::dynamic payload = folly::dynamic::object;
96
+ payload["action"] = OH_ArkUI_UIInputEvent_GetAction(e);
97
+ folly::dynamic touchPoints = folly::dynamic::array();
98
+ auto activeWindowX = OH_ArkUI_PointerEvent_GetWindowX(e);
99
+ auto activeWindowY = OH_ArkUI_PointerEvent_GetWindowY(e);
100
+
101
+ // point relative to top left corner of this component
102
+ auto componentX = OH_ArkUI_PointerEvent_GetX(e);
103
+ auto componentY = OH_ArkUI_PointerEvent_GetY(e);
104
+ auto touchableViews = this->findTouchableViews(componentX, componentY);
105
+
106
+ std::stringstream touchableViewTags;
107
+ for (auto touchableView : touchableViews) {
108
+ touchableViewTags << touchableView.tag << ";";
109
+ }
110
+
111
+ payload["touchableViews"] = this->dynamicFromTouchableViews(touchableViews);
112
+
113
+ int32_t pointerCount = OH_ArkUI_PointerEvent_GetPointerCount(e);
114
+ int activePointerIdx = 0;
115
+ for (int i = 0; i < pointerCount; i++) {
116
+ auto touchPoint = this->convertNodeTouchPointToDynamic(e, i);
117
+ touchPoints.push_back(touchPoint);
118
+ if (activeWindowX == touchPoint["windowX"].asDouble() && activeWindowY == touchPoint["windowY"].asDouble()) {
119
+ activePointerIdx = i;
120
+ }
121
+ }
122
+ payload["actionTouch"] = touchPoints[activePointerIdx];
123
+ payload["touchPoints"] = touchPoints;
124
+ payload["sourceType"] = OH_ArkUI_UIInputEvent_GetSourceType(e);
125
+ payload["timestamp"] = OH_ArkUI_UIInputEvent_GetEventTime(e);
126
+ payload["rootTag"] = m_tag;
127
+ if (rnInstance) {
128
+ rnInstance->postMessageToArkTS("RNGH::TOUCH_EVENT", payload);
129
+ }
130
+ }
131
+
132
+ void setIsHandlingTouches(bool isHandlingTouches) { m_isHandlingTouches = isHandlingTouches; }
133
+
134
+ bool isHandlingTouches() const override { return m_isHandlingTouches; }
135
+
136
+ private:
137
+ std::vector<TouchableView> findTouchableViews(float componentX, float componentY) {
138
+ auto touchTarget = findTargetForTouchPoint({.x = componentX, .y = componentY}, this->shared_from_this());
139
+ std::vector<TouchTarget::Shared> touchTargets{};
140
+ auto tmp = touchTarget;
141
+ while (tmp != nullptr) {
142
+ touchTargets.push_back(tmp);
143
+ tmp = tmp->getTouchTargetParent();
144
+ }
145
+ std::reverse(touchTargets.begin(), touchTargets.end()); // leaf / ... / root -> root / ... / leaf
146
+ std::vector<TouchableView> touchableViews{};
147
+
148
+ float offsetX = 0;
149
+ float offsetY = 0;
150
+ auto surface = this->getSurface().lock();
151
+ if (surface != nullptr) {
152
+ offsetX = surface->getLayoutContext().viewportOffset.x;
153
+ offsetY = surface->getLayoutContext().viewportOffset.y;
154
+ } else {
155
+ LOG(WARNING) << "Surface is nullptr";
156
+ }
157
+ for (auto &touchTarget : touchTargets) {
158
+ auto buttonRole = dynamic_cast<RNGestureHandlerButtonComponentInstance*>(touchTarget.get()) != nullptr;
159
+ auto frame = touchTarget->getLayoutMetrics().frame;
160
+ auto transform = touchTarget->getTransform();
161
+ auto transformedFrame = frame * transform;
162
+ touchableViews.push_back({
163
+ .tag = touchTarget->getTouchTargetTag(),
164
+ .width = transformedFrame.size.width,
165
+ .height = transformedFrame.size.height,
166
+ .x = transformedFrame.origin.x + offsetX,
167
+ .y = transformedFrame.origin.y + offsetY,
168
+ .buttonRole = buttonRole,
169
+ });
170
+ offsetX += transformedFrame.origin.x;
171
+ offsetY += transformedFrame.origin.y;
172
+ offsetX -= touchTarget->getCurrentOffset().x;
173
+ offsetY -= touchTarget->getCurrentOffset().y;
174
+ }
175
+
176
+ return touchableViews;
177
+ }
178
+
179
+ folly::dynamic dynamicFromTouchableViews(const std::vector<TouchableView> &touchableViews) {
180
+ folly::dynamic d_touchableViews = folly::dynamic::array();
181
+ for (auto touchableView : touchableViews) {
182
+ folly::dynamic d_touchableView = folly::dynamic::object;
183
+ d_touchableView["tag"] = touchableView.tag;
184
+ d_touchableView["x"] = touchableView.x;
185
+ d_touchableView["y"] = touchableView.y;
186
+ d_touchableView["width"] = touchableView.width;
187
+ d_touchableView["height"] = touchableView.height;
188
+ d_touchableView["buttonRole"] = touchableView.buttonRole;
189
+ d_touchableViews.push_back(d_touchableView);
190
+ }
191
+ return d_touchableViews;
192
+ }
193
+
194
+ folly::dynamic convertNodeTouchPointToDynamic(ArkUI_UIInputEvent *e, int32_t index = 0) {
195
+ folly::dynamic result = folly::dynamic::object;
196
+ result["pointerId"] = OH_ArkUI_PointerEvent_GetPointerId(e, index);
197
+ result["windowX"] = OH_ArkUI_PointerEvent_GetWindowXByIndex(e, index);
198
+ result["windowY"] = OH_ArkUI_PointerEvent_GetWindowYByIndex(e, index);
199
+ return result;
200
+ }
201
+
202
+ protected:
203
+ void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override {
204
+ CppComponentInstance::onChildInserted(childComponentInstance, index);
205
+ m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
206
+ };
207
+
208
+ void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
209
+ CppComponentInstance::onChildRemoved(childComponentInstance);
210
+ m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
211
+ };
212
+
213
+ private:
214
+ Surface::Weak m_surface;
215
+
216
+ Surface::Weak getSurface() {
217
+ if (m_surface.lock() != nullptr) {
218
+ return m_surface;
219
+ }
220
+ auto rnInstance = m_deps->rnInstance.lock();
221
+ if (rnInstance == nullptr) {
222
+ m_surface.reset();
223
+ return m_surface;
224
+ }
225
+ ComponentInstance::Shared currentRoot = shared_from_this();
226
+ while (true) {
227
+ auto maybeNewCurrentRoot = currentRoot->getParent().lock();
228
+ if (maybeNewCurrentRoot == nullptr) {
229
+ break;
230
+ }
231
+ currentRoot = maybeNewCurrentRoot;
232
+ }
233
+ auto maybeSurface = rnInstance->getSurfaceByRootTag(currentRoot->getTag());
234
+ if (!maybeSurface.has_value()) {
235
+ m_surface.reset();
236
+ return m_surface;
237
+ }
238
+ m_surface = maybeSurface.value();
239
+ return m_surface;
240
+ }
241
+ };
242
+ } // namespace rnoh