@@ -9,107 +9,112 @@ using namespace rnoh;
9
9
using namespace facebook ;
10
10
11
11
class RNGHEventEmitRequestHandler : public EventEmitRequestHandler {
12
- void handleEvent (EventEmitRequestHandler::Context const &ctx) override {
13
- auto eventEmitter = ctx.shadowViewRegistry ->getEventEmitter <facebook::react::ViewEventEmitter>(ctx.tag );
14
- if (eventEmitter == nullptr ) {
15
- return ;
16
- }
17
- if (ctx.eventName == " onGestureHandlerEvent" ) {
18
- eventEmitter->dispatchUniqueEvent (ctx.eventName , ArkJS (ctx.env ).getDynamic (ctx.payload ));
19
- } else if (ctx.eventName == " onGestureHandlerStateChange" ) {
20
- eventEmitter->dispatchEvent (" onGestureHandlerStateChange" , ArkJS (ctx.env ).getDynamic (ctx.payload ));
12
+ void handleEvent (EventEmitRequestHandler::Context const &ctx) override {
13
+ auto eventEmitter = ctx.shadowViewRegistry ->getEventEmitter <facebook::react::ViewEventEmitter>(ctx.tag );
14
+ if (eventEmitter == nullptr ) {
15
+ return ;
16
+ }
17
+ if (ctx.eventName == " onGestureHandlerEvent" ) {
18
+ eventEmitter->dispatchUniqueEvent (ctx.eventName , ArkJS (ctx.env ).getDynamic (ctx.payload ));
19
+ } else if (ctx.eventName == " onGestureHandlerStateChange" ) {
20
+ eventEmitter->dispatchEvent (" onGestureHandlerStateChange" , ArkJS (ctx.env ).getDynamic (ctx.payload ));
21
+ }
21
22
}
22
- }
23
23
};
24
24
25
25
class RNOHCorePackageComponentInstanceFactoryDelegate : public ComponentInstanceFactoryDelegate {
26
26
public:
27
- using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
27
+ using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
28
28
29
- ComponentInstance::Shared create (ComponentInstance::Context ctx) override {
30
- if (ctx.componentName == " RNGestureHandlerButton" ) {
31
- return std::make_shared<RNGestureHandlerButtonComponentInstance>(ctx);
32
- } else if (ctx.componentName == " RNGestureHandlerRootView" ) {
33
- return std::make_shared<RNGestureHandlerRootViewComponentInstance>(ctx);
29
+ ComponentInstance::Shared create (ComponentInstance::Context ctx) override {
30
+ if (ctx.componentName == " RNGestureHandlerButton" ) {
31
+ return std::make_shared<RNGestureHandlerButtonComponentInstance>(ctx);
32
+ } else if (ctx.componentName == " RNGestureHandlerRootView" ) {
33
+ return std::make_shared<RNGestureHandlerRootViewComponentInstance>(ctx);
34
+ }
35
+ return nullptr ;
34
36
}
35
- return nullptr ;
36
- }
37
37
};
38
38
39
39
40
40
EventEmitRequestHandlers RnohReactNativeHarmonyGestureHandlerPackage::createEventEmitRequestHandlers () {
41
- return {
42
- std::make_shared<RNGHEventEmitRequestHandler>(),
43
- };
41
+ return {
42
+ std::make_shared<RNGHEventEmitRequestHandler>(),
43
+ };
44
44
}
45
45
46
- ComponentInstanceFactoryDelegate::Shared RnohReactNativeHarmonyGestureHandlerPackage::createComponentInstanceFactoryDelegate () {
47
- return std::make_shared<RNOHCorePackageComponentInstanceFactoryDelegate>();
46
+ ComponentInstanceFactoryDelegate::Shared
47
+ RnohReactNativeHarmonyGestureHandlerPackage::createComponentInstanceFactoryDelegate () {
48
+ return std::make_shared<RNOHCorePackageComponentInstanceFactoryDelegate>();
48
49
}
49
50
50
51
class ScrollLockerArkTSMessageHandler : public ArkTSMessageHandler {
51
52
public:
52
- void handleArkTSMessage (const Context &ctx) override {
53
- if (ctx.messageName == " RNGH::SET_NATIVE_RESPONDERS_BLOCK" ) {
54
- auto targetComponentInstanceTag = ctx.messagePayload [" targetTag" ].asDouble ();
55
- auto shouldBlock = ctx.messagePayload [" shouldBlock" ].asBool ();
56
- auto rnInstance = ctx.rnInstance .lock ();
57
- if (rnInstance != nullptr ) {
58
- auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
59
- if (rnInstanceCAPI != nullptr ) {
60
-
61
- std::vector<ComponentInstance::Shared> ancestors;
62
- auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag (targetComponentInstanceTag);
63
- while (tmpComponentInstance != nullptr ) {
64
- ancestors.push_back (tmpComponentInstance);
65
- tmpComponentInstance = tmpComponentInstance->getParent ().lock ();
66
- }
67
- if (ancestors.size () == 0 ) {
68
- return ;
69
- }
70
- /* *
71
- * Ensure consistent behavior with Android by not blocking scrolls above the GestureHandlerRootView handling
72
- * the touch. If there are multiple nested GestureHandlerRootViews, the one nearest to the actual root will
73
- * handle the touch.
74
- */
75
- auto isChangingResponderStatusAllowed = false ;
76
- for (size_t i = ancestors.size () - 1 ; i > 0 ; i--) {
77
- auto ancestor = ancestors[i];
78
- if (!isChangingResponderStatusAllowed) {
79
- auto rootView = std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
80
- if (rootView != nullptr ) {
81
- isChangingResponderStatusAllowed = true ;
82
- }
83
- } else {
84
- ancestor->setNativeResponderBlocked (shouldBlock, " RNGH" );
85
- }
86
- }
87
- }
88
- }
89
- } else if (ctx.messageName == " RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES" ) {
90
- auto descendantViewTag = ctx.messagePayload [" descendantViewTag" ].asDouble ();
91
- auto isHandlingTouches = ctx.messagePayload [" isHandlingTouches" ].asBool ();
92
- auto rnInstance = ctx.rnInstance .lock ();
93
- if (rnInstance != nullptr ) {
94
- auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
95
- if (rnInstanceCAPI != nullptr ) {
96
- auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag (descendantViewTag);
97
- while (tmpComponentInstance != nullptr ) {
98
- tmpComponentInstance = tmpComponentInstance->getParent ().lock ();
99
- if (tmpComponentInstance) {
100
- auto rnghRootViewComponentInstance =
101
- std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(tmpComponentInstance);
102
- if (rnghRootViewComponentInstance) {
103
- rnghRootViewComponentInstance->setIsHandlingTouches (isHandlingTouches);
104
- }
53
+ void handleArkTSMessage (const Context &ctx) override {
54
+ if (ctx.messageName == " RNGH::SET_NATIVE_RESPONDERS_BLOCK" ) {
55
+ auto targetComponentInstanceTag = ctx.messagePayload [" targetTag" ].asDouble ();
56
+ auto shouldBlock = ctx.messagePayload [" shouldBlock" ].asBool ();
57
+ auto rnInstance = ctx.rnInstance .lock ();
58
+ if (rnInstance != nullptr ) {
59
+ auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
60
+ if (rnInstanceCAPI != nullptr ) {
61
+
62
+ std::vector<ComponentInstance::Shared> ancestors;
63
+ auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag (targetComponentInstanceTag);
64
+ while (tmpComponentInstance != nullptr ) {
65
+ ancestors.push_back (tmpComponentInstance);
66
+ tmpComponentInstance = tmpComponentInstance->getParent ().lock ();
67
+ }
68
+ if (ancestors.size () == 0 ) {
69
+ return ;
70
+ }
71
+ /* *
72
+ * Ensure consistent behavior with Android by not blocking
73
+ * scrolls above the GestureHandlerRootView handling the
74
+ * touch. If there are multiple nested
75
+ * GestureHandlerRootViews, the one nearest to the actual
76
+ * root will handle the touch.
77
+ */
78
+ auto isChangingResponderStatusAllowed = false ;
79
+ for (size_t i = ancestors.size () - 1 ; i > 0 ; i--) {
80
+ auto ancestor = ancestors[i];
81
+ if (!isChangingResponderStatusAllowed) {
82
+ auto rootView =
83
+ std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(ancestor);
84
+ if (rootView != nullptr ) {
85
+ isChangingResponderStatusAllowed = true ;
86
+ }
87
+ } else {
88
+ ancestor->setNativeResponderBlocked (shouldBlock, " RNGH" );
89
+ }
90
+ }
91
+ }
92
+ }
93
+ } else if (ctx.messageName == " RNGH::ROOT_VIEW_IS_HANDLING_TOUCHES" ) {
94
+ auto descendantViewTag = ctx.messagePayload [" descendantViewTag" ].asDouble ();
95
+ auto isHandlingTouches = ctx.messagePayload [" isHandlingTouches" ].asBool ();
96
+ auto rnInstance = ctx.rnInstance .lock ();
97
+ if (rnInstance != nullptr ) {
98
+ auto rnInstanceCAPI = std::dynamic_pointer_cast<RNInstanceCAPI>(rnInstance);
99
+ if (rnInstanceCAPI != nullptr ) {
100
+ auto tmpComponentInstance = rnInstanceCAPI->findComponentInstanceByTag (descendantViewTag);
101
+ while (tmpComponentInstance != nullptr ) {
102
+ tmpComponentInstance = tmpComponentInstance->getParent ().lock ();
103
+ if (tmpComponentInstance) {
104
+ auto rnghRootViewComponentInstance =
105
+ std::dynamic_pointer_cast<RNGestureHandlerRootViewComponentInstance>(
106
+ tmpComponentInstance);
107
+ if (rnghRootViewComponentInstance) {
108
+ rnghRootViewComponentInstance->setIsHandlingTouches (isHandlingTouches);
109
+ }
110
+ }
111
+ }
112
+ }
105
113
}
106
- }
107
114
}
108
- }
109
- }
110
- };
115
+ };
111
116
};
112
117
113
118
std::vector<ArkTSMessageHandler::Shared> RnohReactNativeHarmonyGestureHandlerPackage::createArkTSMessageHandlers () {
114
- return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
119
+ return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
115
120
}
0 commit comments