@react-native-oh-tpl/react-native-gesture-handler 2.12.9 → 2.14.1-2.14.9
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.
- package/DrawerLayout/index.ts +2 -0
- package/Swipeable/index.ts +2 -0
- package/harmony/gesture_handler/BuildProfile.ets +15 -3
- package/harmony/gesture_handler/hvigorfile.ts +1 -1
- package/harmony/gesture_handler/index.ets +2 -2
- package/harmony/gesture_handler/oh-package-lock.json5 +4 -3
- package/harmony/gesture_handler/oh-package.json5 +4 -4
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +63 -17
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +3 -3
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +2 -2
- package/harmony/gesture_handler/src/main/cpp/{RNGestureHandlerButtonComponentInstance.h → componentInstances/RNGestureHandlerButtonComponentInstance.h} +2 -2
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +234 -0
- package/harmony/gesture_handler/src/main/ets/{GestureHandler.ts → core/GestureHandler.ts} +46 -25
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerOrchestrator.ts → core/GestureHandlerOrchestrator.ts} +122 -67
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerRegistry.ts → core/GestureHandlerRegistry.ts} +7 -0
- package/harmony/gesture_handler/src/main/ets/{Event.ts → core/IncomingEvent.ts} +30 -20
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
- package/harmony/gesture_handler/src/main/ets/{OutgoingEvent.ts → core/OutgoingEvent.ts} +1 -1
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/{PointerTracker.ts → core/PointerTracker.ts} +4 -4
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
- package/harmony/gesture_handler/src/main/ets/{VelocityTracker.ts → core/VelocityTracker.ts} +13 -5
- package/harmony/gesture_handler/src/main/ets/core/View.ts +19 -0
- package/harmony/gesture_handler/src/main/ets/core/index.ts +13 -0
- package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +211 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +64 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +127 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +42 -0
- package/harmony/gesture_handler/src/main/ets/{NativeViewGestureHandler.ts → gesture-handlers/NativeViewGestureHandler.ts} +10 -12
- package/harmony/gesture_handler/src/main/ets/{PanGestureHandler.ts → gesture-handlers/PanGestureHandler.ts} +27 -13
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +159 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +164 -0
- package/harmony/gesture_handler/src/main/ets/{TapGestureHandler.ts → gesture-handlers/TapGestureHandler.ts} +11 -11
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/detectors/RotationGestureDetector.ts +167 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/index.ts +1 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +8 -9
- package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerButton.ts → components/RNGestureHandlerButton.ts} +35 -36
- package/harmony/gesture_handler/src/main/ets/namespace/{RNGestureHandlerRootView.ts → components/RNGestureHandlerRootView.ts} +23 -23
- package/harmony/gesture_handler/src/main/ets/namespace/components/ts.ts +2 -0
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +2 -3
- package/harmony/gesture_handler/src/main/ets/rnoh/GestureHandlerArkUIAdapter.ts +240 -0
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerPackage.ts → rnoh/GestureHandlerPackage.ts} +4 -4
- package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +49 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +71 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerArkTS.ts +104 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootTouchHandlerCAPI.ts +110 -0
- package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerButton.ets → rnoh/RNGestureHandlerButton.ets} +3 -3
- package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerModule.ts → rnoh/RNGestureHandlerModule.ts} +74 -27
- package/harmony/gesture_handler/src/main/ets/{RNGestureHandlerRootView.ets → rnoh/RNGestureHandlerRootView.ets} +3 -3
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +24 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +32 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/View.ts +119 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/ViewRegistry.ts +95 -0
- package/harmony/gesture_handler/src/main/module.json5 +8 -6
- package/harmony/gesture_handler/ts.ts +2 -2
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/index.js +98 -138
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +9 -142
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +35 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +13 -10
- package/src/index.ts +136 -136
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +0 -72
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +0 -78
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +0 -53
- package/harmony/gesture_handler/src/main/ets/GestureHandlerArkUIAdapter.ts +0 -203
- package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +0 -45
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +0 -109
- package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +0 -48
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerArkTS.ts +0 -60
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +0 -87
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +0 -23
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +0 -36
- package/harmony/gesture_handler/src/main/ets/View.ts +0 -71
- package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +0 -43
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +0 -17
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +0 -41
- /package/harmony/gesture_handler/src/main/ets/{CircularBuffer.ts → core/CircularBuffer.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{LeastSquareSolver.ts → core/LeastSquareSolver.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{RNGHError.ts → core/RNGHError.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{State.ts → core/State.ts} +0 -0
- /package/harmony/gesture_handler/src/main/ets/{types.ts → rnoh/types.ts} +0 -0
|
@@ -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.9';
|
|
5
|
+
export const BUILD_MODE_NAME = 'debug';
|
|
6
|
+
export const DEBUG = true;
|
|
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 =
|
|
3
|
-
static readonly BUILD_MODE_NAME =
|
|
4
|
-
static readonly DEBUG =
|
|
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@../
|
|
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@../
|
|
11
|
+
"@rnoh/react-native-openharmony@../react_native_openharmony.har": {
|
|
12
12
|
"name": "@rnoh/react-native-openharmony",
|
|
13
|
-
"
|
|
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
|
-
|
|
8
|
-
version: '2.
|
|
7
|
+
type: 'module',
|
|
8
|
+
version: '2.14.1-2.14.9',
|
|
9
9
|
dependencies: {
|
|
10
|
-
"@rnoh/react-native-openharmony":
|
|
11
|
-
}
|
|
10
|
+
"@rnoh/react-native-openharmony": "file:../react_native_openharmony"
|
|
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);
|
|
@@ -31,6 +33,8 @@ class RNGHEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
|
31
33
|
}
|
|
32
34
|
if (ctx.eventName == "onGestureHandlerEvent") {
|
|
33
35
|
eventEmitter->dispatchEvent(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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
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
|
|
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,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
|