@react-native-oh-tpl/react-native-gesture-handler 2.14.8-rc.1 → 2.14.14
Sign up to get free protection for your applications and to get access to all the features.
- package/DrawerLayout/index.ts +2 -2
- package/Swipeable/index.ts +2 -2
- package/harmony/gesture_handler/BuildProfile.ets +17 -0
- package/harmony/gesture_handler/build-profile.json5 +19 -0
- package/harmony/gesture_handler/hvigorfile.ts +2 -0
- package/harmony/gesture_handler/index.ets +2 -0
- package/harmony/gesture_handler/oh-package-lock.json5 +18 -0
- package/harmony/gesture_handler/oh-package.json5 +12 -0
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -0
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +12 -0
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp +123 -0
- package/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h +15 -0
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h +27 -0
- package/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerRootViewComponentInstance.h +245 -0
- package/harmony/gesture_handler/src/main/ets/RNOHPackage.ets +17 -0
- package/harmony/gesture_handler/src/main/ets/core/CircularBuffer.ts +42 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandler.ts +739 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerOrchestrator.ts +344 -0
- package/harmony/gesture_handler/src/main/ets/core/GestureHandlerRegistry.ts +63 -0
- package/harmony/gesture_handler/src/main/ets/core/IncomingEvent.ts +78 -0
- package/harmony/gesture_handler/src/main/ets/core/InteractionManager.ts +144 -0
- package/harmony/gesture_handler/src/main/ets/core/LeastSquareSolver.ts +182 -0
- package/harmony/gesture_handler/src/main/ets/core/Multiset.ts +26 -0
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEvent.ts +34 -0
- package/harmony/gesture_handler/src/main/ets/core/OutgoingEventDispatcher.ts +12 -0
- package/harmony/gesture_handler/src/main/ets/core/PointerTracker.ts +239 -0
- package/harmony/gesture_handler/src/main/ets/core/RNGHError.ts +5 -0
- package/harmony/gesture_handler/src/main/ets/core/RNGHLogger.ts +16 -0
- package/harmony/gesture_handler/src/main/ets/core/State.ts +47 -0
- package/harmony/gesture_handler/src/main/ets/core/Vector2D.ts +80 -0
- package/harmony/gesture_handler/src/main/ets/core/VelocityTracker.ts +106 -0
- package/harmony/gesture_handler/src/main/ets/core/View.ts +21 -0
- package/harmony/gesture_handler/src/main/ets/core/ViewRegistry.ts +7 -0
- package/harmony/gesture_handler/src/main/ets/core/index.ts +15 -0
- package/harmony/gesture_handler/src/main/ets/detectors/ScaleGestureDetector.ts +169 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/FlingGestureHandler.ts +219 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/GestureHandlerFactory.ts +67 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/LongPressGestureHandler.ts +139 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/ManualGestureHandler.ts +50 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/NativeViewGestureHandler.ts +124 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PanGestureHandler.ts +361 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/PinchGestureHandler.ts +174 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/RotationGestureHandler.ts +172 -0
- package/harmony/gesture_handler/src/main/ets/gesture-handlers/TapGestureHandler.ts +216 -0
- 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/rnoh/GestureHandlerPackage.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/Logger.ts +107 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/OutgoingEventDispatchers.ts +94 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHRootViewController.ts +182 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHView.ts +62 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewController.ts +262 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGHViewRegistry.ts +19 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNGestureHandlerModule.ts +267 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHGestureResponder.ts +15 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/RNOHScrollLocker.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/rnoh/types.ts +25 -0
- package/harmony/gesture_handler/src/main/module.json5 +9 -0
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +8 -0
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +16 -0
- package/harmony/gesture_handler/src/main/resources/base/media/icon.png +0 -0
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +16 -0
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +16 -0
- package/harmony/gesture_handler/ts.ts +2 -0
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js +3 -2
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +3 -3
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +18 -15
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +36 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +2 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +3 -2
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +3 -2
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js +15 -12
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js +5 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -2
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/index.d.ts +47 -42
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +14 -14
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +6 -6
- package/package.json +78 -70
- package/src/RNGestureHandlerModule.ts +4 -4
- package/src/components/GestureHandlerRootView.tsx +23 -23
- package/src/handlers/createHandler.tsx +534 -534
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -26
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -18
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -6
package/DrawerLayout/index.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import DrawerLayout from 'react-native-gesture-handler/DrawerLayout';
|
2
|
-
export default DrawerLayout;
|
1
|
+
import DrawerLayout from 'react-native-gesture-handler/DrawerLayout';
|
2
|
+
export default DrawerLayout;
|
package/Swipeable/index.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import Swipeable from 'react-native-gesture-handler/Swipeable';
|
2
|
-
export default Swipeable;
|
1
|
+
import Swipeable from 'react-native-gesture-handler/Swipeable';
|
2
|
+
export default Swipeable;
|
@@ -0,0 +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.14';
|
5
|
+
export const BUILD_MODE_NAME = 'release';
|
6
|
+
export const DEBUG = false;
|
7
|
+
export const TARGET_NAME = 'default';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* BuildProfile Class is used only for compatibility purposes.
|
11
|
+
*/
|
12
|
+
export default class BuildProfile {
|
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;
|
17
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"apiType": 'stageMode',
|
3
|
+
// "buildOption": {
|
4
|
+
// "externalNativeOptions": {
|
5
|
+
// "path": "./src/main/cpp/CMakeLists.txt",
|
6
|
+
// "arguments": "",
|
7
|
+
// "cppFlags": "",
|
8
|
+
// },
|
9
|
+
// },
|
10
|
+
"targets": [
|
11
|
+
{
|
12
|
+
"name": "default",
|
13
|
+
"runtimeOS": "HarmonyOS"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"name": "ohosTest",
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"meta": {
|
3
|
+
"stableOrder": false
|
4
|
+
},
|
5
|
+
"lockfileVersion": 3,
|
6
|
+
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
7
|
+
"specifiers": {
|
8
|
+
"@rnoh/react-native-openharmony@../react_native_openharmony.har": "@rnoh/react-native-openharmony@../react_native_openharmony.har"
|
9
|
+
},
|
10
|
+
"packages": {
|
11
|
+
"@rnoh/react-native-openharmony@../react_native_openharmony.har": {
|
12
|
+
"name": "@rnoh/react-native-openharmony",
|
13
|
+
"version": "0.72.35",
|
14
|
+
"resolved": "../react_native_openharmony.har",
|
15
|
+
"registryType": "local"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
license: '',
|
3
|
+
devDependencies: {},
|
4
|
+
author: '',
|
5
|
+
name: '@react-native-oh-tpl/react-native-gesture-handler',
|
6
|
+
description: '',
|
7
|
+
type: 'module',
|
8
|
+
version: '2.14.14',
|
9
|
+
dependencies: {
|
10
|
+
"@rnoh/react-native-openharmony": "file:./react_native_openharmony"
|
11
|
+
},
|
12
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
3
|
+
|
4
|
+
file(GLOB rnoh_gesture_handler_SRC CONFIGURE_DEPENDS *.cpp)
|
5
|
+
|
6
|
+
add_library(rnoh_gesture_handler SHARED ${rnoh_gesture_handler_SRC})
|
7
|
+
target_include_directories(rnoh_gesture_handler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
8
|
+
target_link_libraries(rnoh_gesture_handler PUBLIC rnoh)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#pragma once
|
2
|
+
#include "RnohReactNativeHarmonyGestureHandlerPackage.h"
|
3
|
+
|
4
|
+
namespace rnoh {
|
5
|
+
/**
|
6
|
+
* @deprecated: Use RnohReactNativeHarmonyGestureHandlerPackage instead (2024-10-10)
|
7
|
+
*/
|
8
|
+
class GestureHandlerPackage : public RnohReactNativeHarmonyGestureHandlerPackage {
|
9
|
+
using Super = RnohReactNativeHarmonyGestureHandlerPackage;
|
10
|
+
using Super::Super;
|
11
|
+
};
|
12
|
+
} // namespace rnoh
|
@@ -0,0 +1,123 @@
|
|
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
|
+
}
|
@@ -0,0 +1,15 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,245 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
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
|
+
}
|
@@ -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
|
+
}
|