@react-native-oh-tpl/react-native-gesture-handler 2.14.16 → 2.14.17-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/DrawerLayout/index.ts +2 -2
  2. package/Swipeable/index.ts +2 -2
  3. package/harmony/gesture_handler.har +0 -0
  4. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  5. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  6. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  9. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  10. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  11. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  12. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  13. package/lib/module/handlers/createHandler.js.map +1 -1
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  16. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  17. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  18. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
  19. package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
  20. package/lib/typescript/handlers/createHandler.d.ts +11 -11
  21. package/lib/typescript/index.d.ts +47 -47
  22. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
  23. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
  24. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
  25. package/package.json +83 -78
  26. package/src/RNGestureHandlerModule.ts +4 -4
  27. package/src/components/GestureHandlerRootView.tsx +23 -23
  28. package/src/handlers/createHandler.tsx +534 -534
  29. package/src/index.ts +172 -172
  30. package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
  31. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
  32. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
  33. package/harmony/gesture_handler/BuildProfile.ets +0 -17
  34. package/harmony/gesture_handler/build-profile.json5 +0 -12
  35. package/harmony/gesture_handler/hvigorfile.ts +0 -2
  36. package/harmony/gesture_handler/index.ets +0 -2
  37. package/harmony/gesture_handler/oh-package-lock.json5 +0 -19
  38. package/harmony/gesture_handler/oh-package.json5 +0 -12
  39. package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +0 -8
  40. package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +0 -12
  41. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +0 -123
  42. package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +0 -15
  43. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +0 -27
  44. package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +0 -245
  45. package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +0 -17
  46. package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +0 -42
  47. package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +0 -739
  48. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +0 -344
  49. package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +0 -63
  50. package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +0 -78
  51. package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +0 -144
  52. package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +0 -182
  53. package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +0 -26
  54. package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +0 -34
  55. package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +0 -12
  56. package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +0 -239
  57. package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +0 -5
  58. package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +0 -16
  59. package/harmony/gesture_handler/src/main/ets/core/State.ts +0 -47
  60. package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +0 -80
  61. package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +0 -106
  62. package/harmony/gesture_handler/src/main/ets/core/View.ts +0 -21
  63. package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +0 -7
  64. package/harmony/gesture_handler/src/main/ets/core/index.ts +0 -15
  65. package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +0 -169
  66. package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +0 -219
  67. package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +0 -67
  68. package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +0 -139
  69. package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +0 -50
  70. package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +0 -124
  71. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +0 -375
  72. package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +0 -174
  73. package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +0 -172
  74. package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +0 -216
  75. package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +0 -167
  76. package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +0 -1
  77. package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerPackage.ts +0 -25
  78. package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +0 -107
  79. package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +0 -94
  80. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +0 -196
  81. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +0 -89
  82. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +0 -255
  83. package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +0 -19
  84. package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +0 -267
  85. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +0 -15
  86. package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +0 -25
  87. package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +0 -25
  88. package/harmony/gesture_handler/src/main/module.json5 +0 -9
  89. package/harmony/gesture_handler/src/main/resources/base/element/color.json +0 -8
  90. package/harmony/gesture_handler/src/main/resources/base/element/string.json +0 -16
  91. package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
  92. package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +0 -5
  93. package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +0 -16
  94. package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +0 -16
  95. package/harmony/gesture_handler/ts.ts +0 -2
@@ -1,123 +0,0 @@
1
- #pragma once
2
- #include "RnohReactNativeHarmonyGestureHandlerPackage.h"
3
- #include "RNOH/RNInstanceCAPI.h"
4
- #include "componentInstances/RNGestureHandlerButtonComponentInstance.h"
5
- #include "componentInstances/RNGestureHandlerRootViewComponentInstance.h"
6
- #include <glog/logging.h>
7
- #include <react/renderer/debug/SystraceSection.h>
8
-
9
- using namespace rnoh;
10
- using namespace facebook;
11
-
12
- class RNGHEventEmitRequestHandler : public EventEmitRequestHandler {
13
- void handleEvent(EventEmitRequestHandler::Context const &ctx) override {
14
- facebook::react::SystraceSection s("RNGH::RNGHEventEmitRequestHandler::handleEvent");
15
- auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::ViewEventEmitter>(ctx.tag);
16
- if (eventEmitter == nullptr) {
17
- return;
18
- }
19
- if (ctx.eventName == "onGestureHandlerEvent") {
20
- eventEmitter->dispatchUniqueEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
21
- } else if (ctx.eventName == "onGestureHandlerStateChange") {
22
- eventEmitter->dispatchEvent("onGestureHandlerStateChange", ArkJS(ctx.env).getDynamic(ctx.payload));
23
- }
24
- }
25
- };
26
-
27
- class RNOHCorePackageComponentInstanceFactoryDelegate : public ComponentInstanceFactoryDelegate {
28
- public:
29
- using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
30
-
31
- ComponentInstance::Shared create(ComponentInstance::Context ctx) override {
32
- if (ctx.componentName == "RNGestureHandlerButton") {
33
- return std::make_shared<RNGestureHandlerButtonComponentInstance>(ctx);
34
- } else if (ctx.componentName == "RNGestureHandlerRootView") {
35
- return std::make_shared<RNGestureHandlerRootViewComponentInstance>(ctx);
36
- }
37
- return nullptr;
38
- }
39
- };
40
-
41
-
42
- EventEmitRequestHandlers RnohReactNativeHarmonyGestureHandlerPackage::createEventEmitRequestHandlers() {
43
- return {
44
- std::make_shared<RNGHEventEmitRequestHandler>(),
45
- };
46
- }
47
-
48
- ComponentInstanceFactoryDelegate::Shared
49
- RnohReactNativeHarmonyGestureHandlerPackage::createComponentInstanceFactoryDelegate() {
50
- return std::make_shared<RNOHCorePackageComponentInstanceFactoryDelegate>();
51
- }
52
-
53
- class ScrollLockerArkTSMessageHandler : public ArkTSMessageHandler {
54
- public:
55
- void handleArkTSMessage(const Context &ctx) override {
56
- facebook::react::SystraceSection s("RNGH::ScrollLockerArkTSMessageHandler::handleArkTSMessage");
57
- if (ctx.messageName == "RNGH::SET_NATIVE_RESPONDERS_BLOCK") {
58
- auto targetComponentInstanceTag = ctx.messagePayload["targetTag"].asDouble();
59
- auto shouldBlock = ctx.messagePayload["shouldBlock"].asBool();
60
- auto rnInstance = ctx.rnInstance.lock();
61
- if (rnInstance != nullptr) {
62
- auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
63
- if (rnInstanceCAPI != nullptr) {
64
-
65
- std::vector<ComponentInstance::Shared> ancestors;
66
- auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(targetComponentInstanceTag);
67
- while (tmpComponentInstance != nullptr) {
68
- ancestors.push_back(tmpComponentInstance);
69
- tmpComponentInstance = tmpComponentInstance->getParent().lock();
70
- }
71
- if (ancestors.size() == 0) {
72
- return;
73
- }
74
- /**
75
- * Ensure consistent behavior with Android by not blocking
76
- * scrolls above the GestureHandlerRootView handling the
77
- * touch. If there are multiple nested
78
- * GestureHandlerRootViews, the one nearest to the actual
79
- * root will handle the touch.
80
- */
81
- auto isChangingResponderStatusAllowed = false;
82
- for (size_t i = ancestors.size() - 1; i > 0; i--) {
83
- auto ancestor = ancestors[i];
84
- if (!isChangingResponderStatusAllowed) {
85
- auto rootView =
86
- std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
87
- if (rootView != nullptr) {
88
- isChangingResponderStatusAllowed = true;
89
- }
90
- } else {
91
- ancestor->setNativeResponderBlocked(shouldBlock, "RNGH");
92
- }
93
- }
94
- }
95
- }
96
- } else if (ctx.messageName == "RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES") {
97
- auto descendantViewTag = ctx.messagePayload["descendantViewTag"].asDouble();
98
- auto isHandlingTouches = ctx.messagePayload["isHandlingTouches"].asBool();
99
- auto rnInstance = ctx.rnInstance.lock();
100
- if (rnInstance != nullptr) {
101
- auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
102
- if (rnInstanceCAPI != nullptr) {
103
- auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag(descendantViewTag);
104
- while (tmpComponentInstance != nullptr) {
105
- tmpComponentInstance = tmpComponentInstance->getParent().lock();
106
- if (tmpComponentInstance) {
107
- auto rnghRootViewComponentInstance =
108
- std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(
109
- tmpComponentInstance);
110
- if (rnghRootViewComponentInstance) {
111
- rnghRootViewComponentInstance->setIsHandlingTouches(isHandlingTouches);
112
- }
113
- }
114
- }
115
- }
116
- }
117
- }
118
- };
119
- };
120
-
121
- std::vector<ArkTSMessageHandler::Shared> RnohReactNativeHarmonyGestureHandlerPackage::createArkTSMessageHandlers() {
122
- return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
123
- }
@@ -1,15 +0,0 @@
1
- #pragma once
2
- #include "RNOH/Package.h"
3
-
4
- namespace rnoh {
5
- class RnohReactNativeHarmonyGestureHandlerPackage : public Package {
6
- public:
7
- RnohReactNativeHarmonyGestureHandlerPackage(Package::Context ctx) : Package(ctx) {}
8
-
9
- EventEmitRequestHandlers createEventEmitRequestHandlers();
10
-
11
- ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate();
12
-
13
- std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override;
14
- };
15
- } // namespace rnoh
@@ -1,27 +0,0 @@
1
- #pragma once
2
- #import "RNOH/CppComponentInstance.h"
3
- #import "RNOH/arkui/StackNode.h"
4
- #import "generated/RNGestureHandlerButtonComponentDescriptor.h"
5
-
6
- namespace rnoh {
7
- class RNGestureHandlerButtonComponentInstance
8
- : public CppComponentInstance<facebook::react::RNGestureHandlerButtonShadowNode> {
9
- private:
10
- StackNode m_stackNode;
11
-
12
- public:
13
- RNGestureHandlerButtonComponentInstance(Context context) : CppComponentInstance(std::move(context)){};
14
-
15
- StackNode &getLocalRootArkUINode() override { return m_stackNode; };
16
-
17
- void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override {
18
- CppComponentInstance::onChildInserted(childComponentInstance, index);
19
- m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
20
- };
21
-
22
- void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
23
- CppComponentInstance::onChildRemoved(childComponentInstance);
24
- m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
25
- };
26
- };
27
- } // namespace rnoh
@@ -1,245 +0,0 @@
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 "generated/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
- enum class ActionType { Cancel, Down, Move, Up };
17
-
18
- /**
19
- * This function is borrowed from TouchEventDispatcher
20
- */
21
- static TouchTarget::Shared findTargetForTouchPoint(Point const &point, TouchTarget::Shared const &target) {
22
- bool canHandleTouch =
23
- target->canHandleTouch() && target->containsPoint(point) && (target->getTouchEventEmitter() != nullptr);
24
- bool canChildrenHandleTouch = target->canChildrenHandleTouch() && target->containsPointInBoundingBox(point);
25
-
26
- if (canChildrenHandleTouch) {
27
- auto children = target->getTouchTargetChildren();
28
- // we want to check the children in reverse order, since the last child is the topmost one
29
- std::reverse(children.begin(), children.end());
30
- for (auto const &child : children) {
31
- auto childPoint = target->computeChildPoint(point, child);
32
- auto result = findTargetForTouchPoint(childPoint, child);
33
- if (result != nullptr) {
34
- return result;
35
- }
36
- }
37
- }
38
- if (canHandleTouch) {
39
- return target;
40
- }
41
- return nullptr;
42
- }
43
-
44
- private:
45
- bool m_isHandlingTouches = false;
46
- StackNode m_stackNode;
47
-
48
- struct TouchableView {
49
- Tag tag;
50
- facebook::react::Float width;
51
- facebook::react::Float height;
52
- facebook::react::Float x;
53
- facebook::react::Float y;
54
- bool buttonRole;
55
- };
56
-
57
- public:
58
- RNGestureHandlerRootViewComponentInstance(Context context) : CppComponentInstance(std::move(context)) {
59
- ArkUINodeRegistry::getInstance().registerTouchHandler(&m_stackNode, this);
60
- NativeNodeApi::getInstance()->registerNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT,
61
- NODE_TOUCH_EVENT, 0);
62
- auto rnInstance = m_deps->rnInstance.lock();
63
- if (rnInstance) {
64
- rnInstance->postMessageToArkTS("RNGH::ROOT_CREATED", m_tag);
65
- }
66
- };
67
-
68
- ~RNGestureHandlerRootViewComponentInstance() override {
69
- NativeNodeApi::getInstance()->unregisterNodeEvent(m_stackNode.getArkUINodeHandle(), NODE_TOUCH_EVENT);
70
- ArkUINodeRegistry::getInstance().unregisterTouchHandler(&m_stackNode);
71
- }
72
-
73
- StackNode &getLocalRootArkUINode() override { return m_stackNode; };
74
-
75
- void onTouchEvent(ArkUI_UIInputEvent *e) override {
76
- auto ancestor = this->getParent().lock();
77
- while (ancestor != nullptr) {
78
- auto ancestorRNGHRootView = std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
79
- if (ancestorRNGHRootView != nullptr) {
80
- // If there are multiple nested GestureHandlerRootViews, the one nearest to the actual root will handle
81
- // the touch.
82
- return;
83
- }
84
- ancestor = ancestor->getParent().lock();
85
- }
86
-
87
- auto ancestorTouchTarget = this->getTouchTargetParent();
88
- auto rnInstance = m_deps->rnInstance.lock();
89
- while (ancestorTouchTarget != nullptr) {
90
- if (ancestorTouchTarget->isHandlingTouches()) {
91
- rnInstance->postMessageToArkTS("RNGH::CANCEL_TOUCHES", m_tag);
92
- return;
93
- }
94
- ancestorTouchTarget = ancestorTouchTarget->getTouchTargetParent();
95
- }
96
-
97
- folly::dynamic payload = folly::dynamic::object;
98
- folly::dynamic touchPoints = folly::dynamic::array();
99
- std::vector<TouchableView> touchableViews;
100
-
101
- auto action = OH_ArkUI_UIInputEvent_GetAction(e);
102
- auto actionType = static_cast<ActionType>(action);
103
-
104
- if (actionType != ActionType::Move) {
105
- // point relative to top left corner of this component
106
- auto componentX = OH_ArkUI_PointerEvent_GetX(e);
107
- auto componentY = OH_ArkUI_PointerEvent_GetY(e);
108
- touchableViews = this->findTouchableViews(componentX, componentY);
109
- }
110
-
111
- auto activeWindowX = OH_ArkUI_PointerEvent_GetWindowX(e);
112
- auto activeWindowY = OH_ArkUI_PointerEvent_GetWindowY(e);
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() &&
119
- activeWindowY == touchPoint["windowY"].asDouble()) {
120
- activePointerIdx = i;
121
- }
122
- }
123
- payload["actionTouch"] = touchPoints[activePointerIdx];
124
- payload["touchPoints"] = touchPoints;
125
- payload["sourceType"] = OH_ArkUI_UIInputEvent_GetSourceType(e);
126
- payload["timestamp"] = OH_ArkUI_UIInputEvent_GetEventTime(e);
127
- payload["touchableViews"] = this->dynamicFromTouchableViews(touchableViews);
128
- payload["rootTag"] = m_tag;
129
- payload["action"] = action;
130
- if (rnInstance) {
131
- rnInstance->postMessageToArkTS("RNGH::TOUCH_EVENT", payload);
132
- }
133
- }
134
-
135
- void setIsHandlingTouches(bool isHandlingTouches) { m_isHandlingTouches = isHandlingTouches; }
136
-
137
- bool isHandlingTouches() const override { return m_isHandlingTouches; }
138
-
139
- private:
140
- std::vector<TouchableView> findTouchableViews(float componentX, float componentY) {
141
- auto touchTarget = findTargetForTouchPoint({.x = componentX, .y = componentY}, this->shared_from_this());
142
- std::vector<TouchTarget::Shared> touchTargets{};
143
- auto tmp = touchTarget;
144
- while (tmp != nullptr) {
145
- touchTargets.push_back(tmp);
146
- tmp = tmp->getTouchTargetParent();
147
- }
148
- std::reverse(touchTargets.begin(), touchTargets.end()); // leaf / ... / root -> root / ... / leaf
149
- std::vector<TouchableView> touchableViews{};
150
-
151
- float offsetX = 0;
152
- float offsetY = 0;
153
- auto surface = this->getSurface().lock();
154
- if (surface != nullptr) {
155
- offsetX = surface->getLayoutContext().viewportOffset.x;
156
- offsetY = surface->getLayoutContext().viewportOffset.y;
157
- } else {
158
- LOG(WARNING) << "Surface is nullptr";
159
- }
160
- for (auto &touchTarget : touchTargets) {
161
- auto buttonRole = dynamic_cast<RNGestureHandlerButtonComponentInstance *>(touchTarget.get()) != nullptr;
162
- auto frame = touchTarget->getLayoutMetrics().frame;
163
- auto transform = touchTarget->getTransform();
164
- auto transformedFrame = frame * transform;
165
- touchableViews.push_back({
166
- .tag = touchTarget->getTouchTargetTag(),
167
- .width = transformedFrame.size.width,
168
- .height = transformedFrame.size.height,
169
- .x = transformedFrame.origin.x + offsetX,
170
- .y = transformedFrame.origin.y + offsetY,
171
- .buttonRole = buttonRole,
172
- });
173
- offsetX += transformedFrame.origin.x;
174
- offsetY += transformedFrame.origin.y;
175
- offsetX -= touchTarget->getCurrentOffset().x;
176
- offsetY -= touchTarget->getCurrentOffset().y;
177
- }
178
-
179
- return touchableViews;
180
- }
181
-
182
- folly::dynamic dynamicFromTouchableViews(const std::vector<TouchableView> &touchableViews) {
183
- folly::dynamic d_touchableViews = folly::dynamic::array();
184
- for (auto touchableView : touchableViews) {
185
- folly::dynamic d_touchableView = folly::dynamic::object;
186
- d_touchableView["tag"] = touchableView.tag;
187
- d_touchableView["x"] = touchableView.x;
188
- d_touchableView["y"] = touchableView.y;
189
- d_touchableView["width"] = touchableView.width;
190
- d_touchableView["height"] = touchableView.height;
191
- d_touchableView["buttonRole"] = touchableView.buttonRole;
192
- d_touchableViews.push_back(d_touchableView);
193
- }
194
- return d_touchableViews;
195
- }
196
-
197
- folly::dynamic convertNodeTouchPointToDynamic(ArkUI_UIInputEvent *e, int32_t index = 0) {
198
- folly::dynamic result = folly::dynamic::object;
199
- result["pointerId"] = OH_ArkUI_PointerEvent_GetPointerId(e, index);
200
- result["windowX"] = OH_ArkUI_PointerEvent_GetWindowXByIndex(e, index);
201
- result["windowY"] = OH_ArkUI_PointerEvent_GetWindowYByIndex(e, index);
202
- return result;
203
- }
204
-
205
- protected:
206
- void onChildInserted(ComponentInstance::Shared const &childComponentInstance, std::size_t index) override {
207
- CppComponentInstance::onChildInserted(childComponentInstance, index);
208
- m_stackNode.insertChild(childComponentInstance->getLocalRootArkUINode(), index);
209
- };
210
-
211
- void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
212
- CppComponentInstance::onChildRemoved(childComponentInstance);
213
- m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
214
- };
215
-
216
- private:
217
- Surface::Weak m_surface;
218
-
219
- Surface::Weak getSurface() {
220
- if (m_surface.lock() != nullptr) {
221
- return m_surface;
222
- }
223
- auto rnInstance = m_deps->rnInstance.lock();
224
- if (rnInstance == nullptr) {
225
- m_surface.reset();
226
- return m_surface;
227
- }
228
- ComponentInstance::Shared currentRoot = shared_from_this();
229
- while (true) {
230
- auto maybeNewCurrentRoot = currentRoot->getParent().lock();
231
- if (maybeNewCurrentRoot == nullptr) {
232
- break;
233
- }
234
- currentRoot = maybeNewCurrentRoot;
235
- }
236
- auto maybeSurface = rnInstance->getSurfaceByRootTag(currentRoot->getTag());
237
- if (!maybeSurface.has_value()) {
238
- m_surface.reset();
239
- return m_surface;
240
- }
241
- m_surface = maybeSurface.value();
242
- return m_surface;
243
- }
244
- };
245
- } // namespace rnoh
@@ -1,17 +0,0 @@
1
- import { RNPackage, RNPackageContext } from "@rnoh/react-native-openharmony";
2
- import type { TurboModule, TurboModuleContext } from "@rnoh/react-native-openharmony/ts";
3
- import { RNGestureHandlerModule } from './rnoh/RNGestureHandlerModule';
4
-
5
- export default class RnohReactNativeHarmonyGestureHandlerPackage extends RNPackage {
6
- private isRNGHDevModeEnabled: boolean
7
-
8
- constructor(ctx: RNPackageContext, isRNGHDevModeEnabled: boolean = false) {
9
- super(ctx)
10
- this.isRNGHDevModeEnabled = isRNGHDevModeEnabled
11
- }
12
-
13
- getUITurboModuleFactoryByNameMap(): Map<string, (ctx: TurboModuleContext) => TurboModule | null> {
14
- return new Map().set(RNGestureHandlerModule.NAME,
15
- (ctx: TurboModuleContext) => new RNGestureHandlerModule(ctx, this.isRNGHDevModeEnabled))
16
- }
17
- }
@@ -1,42 +0,0 @@
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
- }