@react-native-oh-tpl/react-native-gesture-handler 2.14.7 → 2.14.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) 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 +242 -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 +690 -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 +63 -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 +21 -0
  36. package/harmony/gesture_handler/src/main/ets/core/ViewFinder.ts +11 -0
  37. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +8 -0
  38. package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
  39. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
  40. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
  41. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
  42. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
  43. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
  44. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +115 -0
  45. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +342 -0
  46. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
  47. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
  48. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +206 -0
  49. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
  50. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
  51. package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +24 -0
  52. package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerButton.ts +139 -0
  53. package/harmony/gesture_handler/src/main/ets/namespace/components/RNGestureHandlerRootView.ts +101 -0
  54. package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
  55. package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -0
  56. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
  57. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +22 -0
  58. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
  59. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
  60. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +98 -0
  61. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
  62. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerButton.ets +38 -0
  63. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +233 -0
  64. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerRootView.ets +53 -0
  65. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
  66. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
  67. package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +134 -0
  68. package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +97 -0
  69. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +25 -0
  70. package/harmony/gesture_handler/src/main/module.json5 +9 -0
  71. package/harmony/gesture_handler/src/main/resources/base/element/color.json +8 -0
  72. package/harmony/gesture_handler/src/main/resources/base/element/string.json +16 -0
  73. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  74. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -0
  75. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +16 -0
  76. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +16 -0
  77. package/harmony/gesture_handler/ts.ts +2 -0
  78. package/harmony/gesture_handler.har +0 -0
  79. package/lib/commonjs/RNGestureHandlerModule.js +3 -2
  80. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  81. package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
  82. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  83. package/lib/commonjs/handlers/createHandler.js +18 -15
  84. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  85. package/lib/commonjs/index.js +36 -8
  86. package/lib/commonjs/index.js.map +1 -1
  87. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +2 -1
  88. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  89. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +3 -2
  90. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  91. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +3 -2
  92. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  93. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  94. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  95. package/lib/module/handlers/createHandler.js +15 -12
  96. package/lib/module/handlers/createHandler.js.map +1 -1
  97. package/lib/module/index.js +5 -7
  98. package/lib/module/index.js.map +1 -1
  99. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  100. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  101. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  102. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  103. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  104. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  105. package/lib/typescript/index.d.ts +47 -42
  106. package/lib/typescript/index.d.ts.map +1 -1
  107. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  108. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  109. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  110. package/package.json +73 -72
  111. package/src/RNGestureHandlerModule.ts +4 -4
  112. package/src/components/GestureHandlerRootView.tsx +23 -23
  113. package/src/handlers/createHandler.tsx +534 -534
  114. package/src/index.ts +172 -172
  115. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  116. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  117. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
@@ -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
@@ -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
+ }