Skip to content

Commit 57a8844

Browse files
committed
chore: format cpp files
See merge request rnoh/react-native-harmony-gesture-handler!78 (cherry picked from commit affd0380c4e6154f7e94f2c48387c20c37ceae02)
1 parent 0846074 commit 57a8844

File tree

5 files changed

+313
-312
lines changed

5 files changed

+313
-312
lines changed

tester/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace rnoh {
66
* @deprecated: Use RnohReactNativeHarmonyGestureHandlerPackage instead (2024-10-10)
77
*/
88
class GestureHandlerPackage : public RnohReactNativeHarmonyGestureHandlerPackage {
9-
using Super = RnohReactNativeHarmonyGestureHandlerPackage;
10-
using Super::Super;
9+
using Super = RnohReactNativeHarmonyGestureHandlerPackage;
10+
using Super::Super;
1111
};
1212
} // namespace rnoh

tester/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.cpp

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,107 +9,112 @@ using namespace rnoh;
99
using namespace facebook;
1010

1111
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+
}
2122
}
22-
}
2323
};
2424

2525
class RNOHCorePackageComponentInstanceFactoryDelegate : public ComponentInstanceFactoryDelegate {
2626
public:
27-
using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
27+
using ComponentInstanceFactoryDelegate::ComponentInstanceFactoryDelegate;
2828

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;
3436
}
35-
return nullptr;
36-
}
3737
};
3838

3939

4040
EventEmitRequestHandlers RnohReactNativeHarmonyGestureHandlerPackage::createEventEmitRequestHandlers() {
41-
return {
42-
std::make_shared<RNGHEventEmitRequestHandler>(),
43-
};
41+
return {
42+
std::make_shared<RNGHEventEmitRequestHandler>(),
43+
};
4444
}
4545

46-
ComponentInstanceFactoryDelegate::Shared RnohReactNativeHarmonyGestureHandlerPackage::createComponentInstanceFactoryDelegate() {
47-
return std::make_shared<RNOHCorePackageComponentInstanceFactoryDelegate>();
46+
ComponentInstanceFactoryDelegate::Shared
47+
RnohReactNativeHarmonyGestureHandlerPackage::createComponentInstanceFactoryDelegate() {
48+
return std::make_shared<RNOHCorePackageComponentInstanceFactoryDelegate>();
4849
}
4950

5051
class ScrollLockerArkTSMessageHandler : public ArkTSMessageHandler {
5152
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+
}
105113
}
106-
}
107114
}
108-
}
109-
}
110-
};
115+
};
111116
};
112117

113118
std::vector<ArkTSMessageHandler::Shared> RnohReactNativeHarmonyGestureHandlerPackage::createArkTSMessageHandlers() {
114-
return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
119+
return {std::make_shared<ScrollLockerArkTSMessageHandler>()};
115120
}

tester/harmony/gesture_handler/src/main/cpp/RnohReactNativeHarmonyGestureHandlerPackage.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
#include "RNOH/Package.h"
33

44
namespace rnoh {
5-
class RnohReactNativeHarmonyGestureHandlerPackage : public Package {
6-
public:
7-
RnohReactNativeHarmonyGestureHandlerPackage(Package::Context ctx) : Package(ctx) {}
5+
class RnohReactNativeHarmonyGestureHandlerPackage : public Package {
6+
public:
7+
RnohReactNativeHarmonyGestureHandlerPackage(Package::Context ctx) : Package(ctx) {}
88

9-
EventEmitRequestHandlers createEventEmitRequestHandlers();
9+
EventEmitRequestHandlers createEventEmitRequestHandlers();
1010

11-
ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate();
11+
ComponentInstanceFactoryDelegate::Shared createComponentInstanceFactoryDelegate();
1212

13-
std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override;
14-
};
13+
std::vector<ArkTSMessageHandler::Shared> createArkTSMessageHandlers() override;
14+
};
1515
} // namespace rnoh

tester/harmony/gesture_handler/src/main/cpp/componentInstances/RNGestureHandlerButtonComponentInstance.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
#import "generated/RNGestureHandlerButtonComponentDescriptor.h"
55

66
namespace rnoh {
7-
class RNGestureHandlerButtonComponentInstance
8-
: public CppComponentInstance<facebook::react::RNGestureHandlerButtonShadowNode> {
9-
private:
10-
StackNode m_stackNode;
7+
class RNGestureHandlerButtonComponentInstance
8+
: public CppComponentInstance<facebook::react::RNGestureHandlerButtonShadowNode> {
9+
private:
10+
StackNode m_stackNode;
1111

12-
public:
13-
RNGestureHandlerButtonComponentInstance(Context context) : CppComponentInstance(std::move(context)) {};
12+
public:
13+
RNGestureHandlerButtonComponentInstance(Context context) : CppComponentInstance(std::move(context)){};
1414

15-
StackNode &getLocalRootArkUINode() override { return m_stackNode; };
15+
StackNode &getLocalRootArkUINode() override { return m_stackNode; };
1616

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-
};
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+
};
2121

22-
void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
23-
CppComponentInstance::onChildRemoved(childComponentInstance);
24-
m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
25-
};
22+
void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
23+
CppComponentInstance::onChildRemoved(childComponentInstance);
24+
m_stackNode.removeChild(childComponentInstance->getLocalRootArkUINode());
2625
};
26+
};
2727
} // namespace rnoh

0 commit comments

Comments
 (0)