@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,234 @@
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
+
9
+ namespace rnoh {
10
+ class RNGestureHandlerRootViewComponentInstance
11
+ : public CppComponentInstance<facebook::react::RNGestureHandlerRootViewShadowNode>,
12
+ public TouchEventHandler {
13
+ using Point = facebook::react::Point;
14
+
15
+ /**
16
+ * This function is borrowed from TouchEventDispatcher
17
+ */
18
+ static TouchTarget::Shared findTargetForTouchPoint(Point const &point, TouchTarget::Shared const &target) {
19
+ bool canHandleTouch =
20
+ target->canHandleTouch() && target->containsPoint(point) && (target->getTouchEventEmitter() != nullptr);
21
+ bool canChildrenHandleTouch = target->canChildrenHandleTouch() && target->containsPointInBoundingBox(point);
22
+
23
+ if (canChildrenHandleTouch) {
24
+ auto children = target->getTouchTargetChildren();
25
+ // we want to check the children in reverse order, since the last child is the topmost one
26
+ std::reverse(children.begin(), children.end());
27
+ for (auto const &child : children) {
28
+ auto childPoint = target->computeChildPoint(point, child);
29
+ auto result = findTargetForTouchPoint(childPoint, child);
30
+ if (result != nullptr) {
31
+ return result;
32
+ }
33
+ }
34
+ }
35
+ if (canHandleTouch) {
36
+ return target;
37
+ }
38
+ return nullptr;
39
+ }
40
+
41
+ private:
42
+ bool m_isHandlingTouches = false;
43
+ StackNode m_stackNode;
44
+
45
+ struct TouchableView {
46
+ Tag tag;
47
+ facebook::react::Float width;
48
+ facebook::react::Float height;
49
+ facebook::react::Float x;
50
+ facebook::react::Float y;
51
+ };
52
+
53
+ public:
54
+ RNGestureHandlerRootViewComponentInstance(Context context) : CppComponentInstance(std::move(context)) {
55
+ ArkUINodeRegistry::getInstance().registerTouchHandler(&m_stackNode, this);
56
+ NativeNodeApi::getInstance()->registerNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT,
57
+ NODE_TOUCH_EVENT, 0);
58
+ auto rnInstance = m_deps->rnInstance.lock();
59
+ if (rnInstance) {
60
+ rnInstance->postMessageToArkTS("RNGH::ROOT_CREATED", m_tag);
61
+ }
62
+ };
63
+
64
+ ~RNGestureHandlerRootViewComponentInstance() override {
65
+ NativeNodeApi::getInstance()->unregisterNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT);
66
+ ArkUINodeRegistry::getInstance().unregisterTouchHandler(&m_stackNode);
67
+ }
68
+
69
+ StackNode &getLocalRootArkUINode() override { return m_stackNode; };
70
+
71
+ void onTouchEvent(ArkUI_UIInputEvent *e) override {
72
+ auto ancestor = this->getParent().lock();
73
+ while (ancestor != nullptr) {
74
+ auto ancestorRNGHRootView = std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
75
+ if (ancestorRNGHRootView != nullptr) {
76
+ // If there are multiple nested GestureHandlerRootViews, the one nearest to the actual root will handle the
77
+ // touch.
78
+ return;
79
+ }
80
+ ancestor = ancestor->getParent().lock();
81
+ }
82
+
83
+ auto ancestorTouchTarget = this->getTouchTargetParent();
84
+ auto rnInstance = m_deps->rnInstance.lock();
85
+ while (ancestorTouchTarget != nullptr) {
86
+ if (ancestorTouchTarget->isHandlingTouches()) {
87
+ rnInstance->postMessageToArkTS("RNGH::CANCEL_TOUCHES", m_tag);
88
+ return;
89
+ }
90
+ ancestorTouchTarget = ancestorTouchTarget->getTouchTargetParent();
91
+ }
92
+
93
+ folly::dynamic payload = folly::dynamic::object;
94
+ payload["action"] = OH_ArkUI_UIInputEvent_GetAction(e);
95
+ folly::dynamic touchPoints = folly::dynamic::array();
96
+ auto activeWindowX = OH_ArkUI_PointerEvent_GetWindowX(e);
97
+ auto activeWindowY = OH_ArkUI_PointerEvent_GetWindowY(e);
98
+
99
+ // point relative to top left corner of this component
100
+ auto componentX = OH_ArkUI_PointerEvent_GetX(e);
101
+ auto componentY = OH_ArkUI_PointerEvent_GetY(e);
102
+ auto touchableViews = this->findTouchableViews(componentX, componentY);
103
+
104
+ std::stringstream touchableViewTags;
105
+ for (auto touchableView : touchableViews) {
106
+ touchableViewTags << touchableView.tag << ";";
107
+ }
108
+
109
+ payload["touchableViews"] = this->dynamicFromTouchableViews(touchableViews);
110
+
111
+ int32_t pointerCount = OH_ArkUI_PointerEvent_GetPointerCount(e);
112
+ int activePointerIdx = 0;
113
+ for (int i = 0; i < pointerCount; i++) {
114
+ auto touchPoint = this->convertNodeTouchPointToDynamic(e, i);
115
+ touchPoints.push_back(touchPoint);
116
+ if (activeWindowX == touchPoint["windowX"].asDouble() && activeWindowY == touchPoint["windowY"].asDouble()) {
117
+ activePointerIdx = i;
118
+ }
119
+ }
120
+ payload["actionTouch"] = touchPoints[activePointerIdx];
121
+ payload["touchPoints"] = touchPoints;
122
+ payload["sourceType"] = OH_ArkUI_UIInputEvent_GetSourceType(e);
123
+ payload["timestamp"] = OH_ArkUI_UIInputEvent_GetEventTime(e);
124
+ payload["rootTag"] = m_tag;
125
+ if (rnInstance) {
126
+ rnInstance->postMessageToArkTS("RNGH::TOUCH_EVENT", payload);
127
+ }
128
+ }
129
+
130
+ void setIsHandlingTouches(bool isHandlingTouches) { m_isHandlingTouches = isHandlingTouches; }
131
+
132
+ bool isHandlingTouches() const override { return m_isHandlingTouches; }
133
+
134
+ private:
135
+ std::vector<TouchableView> findTouchableViews(float componentX, float componentY) {
136
+ auto touchTarget = findTargetForTouchPoint({.x = componentX, .y = componentY}, this->shared_from_this());
137
+ std::vector<TouchTarget::Shared> touchTargets{};
138
+ auto tmp = touchTarget;
139
+ while (tmp != nullptr) {
140
+ touchTargets.push_back(tmp);
141
+ tmp = tmp->getTouchTargetParent();
142
+ }
143
+ std::reverse(touchTargets.begin(), touchTargets.end()); // leaf / ... / root -> root / ... / leaf
144
+ std::vector<TouchableView> touchableViews{};
145
+
146
+ float offsetX = 0;
147
+ float offsetY = 0;
148
+ auto surface = this->getSurface().lock();
149
+ if (surface != nullptr) {
150
+ offsetX = surface->getLayoutContext().viewportOffset.x;
151
+ offsetY = surface->getLayoutContext().viewportOffset.y;
152
+ } else {
153
+ LOG(WARNING) << "Surface is nullptr";
154
+ }
155
+ for (auto &touchTarget : touchTargets) {
156
+ touchableViews.push_back({
157
+ .tag = touchTarget->getTouchTargetTag(),
158
+ .x = touchTarget->getLayoutMetrics().frame.origin.x + offsetX,
159
+ .y = touchTarget->getLayoutMetrics().frame.origin.y + offsetY,
160
+ .width = touchTarget->getLayoutMetrics().frame.size.width,
161
+ .height = touchTarget->getLayoutMetrics().frame.size.height,
162
+ });
163
+ offsetX += touchTarget->getLayoutMetrics().frame.origin.x;
164
+ offsetY += touchTarget->getLayoutMetrics().frame.origin.y;
165
+ offsetX -= touchTarget->getCurrentOffset().x;
166
+ offsetY -= touchTarget->getCurrentOffset().y;
167
+ }
168
+
169
+ return touchableViews;
170
+ }
171
+
172
+ folly::dynamic dynamicFromTouchableViews(const std::vector<TouchableView> &touchableViews) {
173
+ folly::dynamic d_touchableViews = folly::dynamic::array();
174
+ for (auto touchableView : touchableViews) {
175
+ folly::dynamic d_touchableView = folly::dynamic::object;
176
+ d_touchableView["tag"] = touchableView.tag;
177
+ d_touchableView["x"] = touchableView.x;
178
+ d_touchableView["y"] = touchableView.y;
179
+ d_touchableView["width"] = touchableView.width;
180
+ d_touchableView["height"] = touchableView.height;
181
+ d_touchableViews.push_back(d_touchableView);
182
+ }
183
+ return d_touchableViews;
184
+ }
185
+
186
+ folly::dynamic convertNodeTouchPointToDynamic(ArkUI_UIInputEvent *e, int32_t index = 0) {
187
+ folly::dynamic result = folly::dynamic::object;
188
+ result["pointerId"] = OH_ArkUI_PointerEvent_GetPointerId(e, index);
189
+ result["windowX"] = OH_ArkUI_PointerEvent_GetWindowXByIndex(e, index);
190
+ result["windowY"] = OH_ArkUI_PointerEvent_GetWindowYByIndex(e, index);
191
+ return result;
192
+ }
193
+
194
+ protected:
195
+ void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override {
196
+ CppComponentInstance::onChildInserted(childComponentInstance, index);
197
+ m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
198
+ };
199
+
200
+ void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
201
+ CppComponentInstance::onChildRemoved(childComponentInstance);
202
+ m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
203
+ };
204
+
205
+ private:
206
+ Surface::Weak m_surface;
207
+
208
+ Surface::Weak getSurface() {
209
+ if (m_surface.lock() != nullptr) {
210
+ return m_surface;
211
+ }
212
+ auto rnInstance = m_deps->rnInstance.lock();
213
+ if (rnInstance == nullptr) {
214
+ m_surface.reset();
215
+ return m_surface;
216
+ }
217
+ ComponentInstance::Shared currentRoot = shared_from_this();
218
+ while (true) {
219
+ auto maybeNewCurrentRoot = currentRoot->getParent().lock();
220
+ if (maybeNewCurrentRoot == nullptr) {
221
+ break;
222
+ }
223
+ currentRoot = maybeNewCurrentRoot;
224
+ }
225
+ auto maybeSurface = rnInstance->getSurfaceByRootTag(currentRoot->getTag());
226
+ if (!maybeSurface.has_value()) {
227
+ m_surface.reset();
228
+ return m_surface;
229
+ }
230
+ m_surface = maybeSurface.value();
231
+ return m_surface;
232
+ }
233
+ };
234
+ } // namespace rnoh
@@ -0,0 +1,42 @@
1
+ export class CircularBuffer<T> {
2
+ private bufferSize: number;
3
+ private buffer: T[];
4
+ private index: number;
5
+ private actualSize: number;
6
+
7
+ constructor(size: number) {
8
+ this.bufferSize = size;
9
+ this.buffer = new Array<T>(size);
10
+ this.index = 0;
11
+ this.actualSize = 0;
12
+ }
13
+
14
+ public get size(): number {
15
+ return this.actualSize;
16
+ }
17
+
18
+ public push(element: T): void {
19
+ this.buffer[this.index] = element;
20
+ this.index = (this.index + 1) % this.bufferSize;
21
+ this.actualSize = Math.min(this.actualSize + 1, this.bufferSize);
22
+ }
23
+
24
+ public get(at: number): T {
25
+ if (this.actualSize === this.bufferSize) {
26
+ let index = (this.index + at) % this.bufferSize;
27
+ if (index < 0) {
28
+ index += this.bufferSize;
29
+ }
30
+
31
+ return this.buffer[index];
32
+ } else {
33
+ return this.buffer[at];
34
+ }
35
+ }
36
+
37
+ public clear(): void {
38
+ this.buffer = new Array<T>(this.bufferSize);
39
+ this.index = 0;
40
+ this.actualSize = 0;
41
+ }
42
+ }