Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename cpp NativeReanimatedModule to ReanimatedModuleProxy #6766

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifdef RCT_NEW_ARCH_ENABLED

#include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
#include <reanimated/NativeModules/NativeReanimatedModule.h>
#include <reanimated/NativeModules/ReanimatedModuleProxy.h>

#include <react/renderer/animations/utils.h>
#include <react/renderer/mounting/ShadowViewMutation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace reanimated {

class NativeReanimatedModule;
class ReanimatedModuleProxy;

using namespace facebook;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <reanimated/NativeModules/NativeReanimatedModule.h>
#include <reanimated/NativeModules/ReanimatedModuleProxy.h>
#include <reanimated/RuntimeDecorators/ReanimatedWorkletRuntimeDecorator.h>
#include <reanimated/RuntimeDecorators/UIRuntimeDecorator.h>
#include <reanimated/Tools/CollectionUtils.h>
Expand Down Expand Up @@ -51,15 +51,15 @@ using namespace facebook;

namespace reanimated {

NativeReanimatedModule::NativeReanimatedModule(
ReanimatedModuleProxy::ReanimatedModuleProxy(
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const bool isBridgeless,
const bool isReducedMotion)
: NativeReanimatedModuleSpec(
: ReanimatedModuleProxySpec(
isBridgeless ? nullptr : jsScheduler->getJSCallInvoker()),
isBridgeless_(isBridgeless),
isReducedMotion_(isReducedMotion),
Expand Down Expand Up @@ -101,7 +101,7 @@ NativeReanimatedModule::NativeReanimatedModule(
commonInit(platformDepMethodsHolder);
}

void NativeReanimatedModule::commonInit(
void ReanimatedModuleProxy::commonInit(
const PlatformDepMethodsHolder &platformDepMethodsHolder) {
auto requestAnimationFrame =
[this](jsi::Runtime &rt, const jsi::Value &callback) {
Expand Down Expand Up @@ -193,15 +193,15 @@ void NativeReanimatedModule::commonInit(
platformDepMethodsHolder.maybeFlushUIUpdatesQueueFunction);
}

NativeReanimatedModule::~NativeReanimatedModule() {
ReanimatedModuleProxy::~ReanimatedModuleProxy() {
// event handler registry and frame callbacks store some JSI values from UI
// runtime, so they have to go away before we tear down the runtime
eventHandlerRegistry_.reset();
frameCallbacks_.clear();
uiWorkletRuntime_.reset();
}

void NativeReanimatedModule::scheduleOnUI(
void ReanimatedModuleProxy::scheduleOnUI(
jsi::Runtime &rt,
const jsi::Value &worklet) {
auto shareableWorklet = extractShareableOrThrow<ShareableWorklet>(
Expand All @@ -219,13 +219,13 @@ void NativeReanimatedModule::scheduleOnUI(
});
}

jsi::Value NativeReanimatedModule::executeOnUIRuntimeSync(
jsi::Value ReanimatedModuleProxy::executeOnUIRuntimeSync(
jsi::Runtime &rt,
const jsi::Value &worklet) {
return uiWorkletRuntime_->executeSync(rt, worklet);
}

jsi::Value NativeReanimatedModule::createWorkletRuntime(
jsi::Value ReanimatedModuleProxy::createWorkletRuntime(
jsi::Runtime &rt,
const jsi::Value &name,
const jsi::Value &initializer) {
Expand All @@ -243,15 +243,15 @@ jsi::Value NativeReanimatedModule::createWorkletRuntime(
return jsi::Object::createFromHostObject(rt, workletRuntime);
}

jsi::Value NativeReanimatedModule::scheduleOnRuntime(
jsi::Value ReanimatedModuleProxy::scheduleOnRuntime(
jsi::Runtime &rt,
const jsi::Value &workletRuntimeValue,
const jsi::Value &shareableWorkletValue) {
reanimated::scheduleOnRuntime(rt, workletRuntimeValue, shareableWorkletValue);
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::registerEventHandler(
jsi::Value ReanimatedModuleProxy::registerEventHandler(
jsi::Runtime &rt,
const jsi::Value &worklet,
const jsi::Value &eventName,
Expand All @@ -273,7 +273,7 @@ jsi::Value NativeReanimatedModule::registerEventHandler(
return jsi::Value(static_cast<double>(newRegistrationId));
}

void NativeReanimatedModule::unregisterEventHandler(
void ReanimatedModuleProxy::unregisterEventHandler(
jsi::Runtime &,
const jsi::Value &registrationId) {
uint64_t id = registrationId.asNumber();
Expand All @@ -297,7 +297,7 @@ static inline std::string intColorToHex(const int val) {
return hexColor;
}

std::string NativeReanimatedModule::obtainPropFromShadowNode(
std::string ReanimatedModuleProxy::obtainPropFromShadowNode(
jsi::Runtime &rt,
const std::string &propName,
const ShadowNode::Shared &shadowNode) {
Expand Down Expand Up @@ -340,7 +340,7 @@ std::string NativeReanimatedModule::obtainPropFromShadowNode(
"` with function `getViewProp` is not supported"));
}

jsi::Value NativeReanimatedModule::getViewProp(
jsi::Value ReanimatedModuleProxy::getViewProp(
jsi::Runtime &rnRuntime,
const jsi::Value &shadowNodeWrapper,
const jsi::Value &propName,
Expand All @@ -365,7 +365,7 @@ jsi::Value NativeReanimatedModule::getViewProp(

#else

jsi::Value NativeReanimatedModule::getViewProp(
jsi::Value ReanimatedModuleProxy::getViewProp(
jsi::Runtime &rnRuntime,
const jsi::Value &viewTag,
const jsi::Value &propName,
Expand Down Expand Up @@ -398,14 +398,14 @@ jsi::Value NativeReanimatedModule::getViewProp(

#endif

jsi::Value NativeReanimatedModule::enableLayoutAnimations(
jsi::Value ReanimatedModuleProxy::enableLayoutAnimations(
jsi::Runtime &,
const jsi::Value &config) {
FeaturesConfig::setLayoutAnimationEnabled(config.getBool());
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::configureProps(
jsi::Value ReanimatedModuleProxy::configureProps(
jsi::Runtime &rt,
const jsi::Value &uiProps,
const jsi::Value &nativeProps) {
Expand All @@ -428,7 +428,7 @@ jsi::Value NativeReanimatedModule::configureProps(
return jsi::Value::undefined();
}

jsi::Value NativeReanimatedModule::configureLayoutAnimationBatch(
jsi::Value ReanimatedModuleProxy::configureLayoutAnimationBatch(
jsi::Runtime &rt,
const jsi::Value &layoutAnimationsBatch) {
auto array = layoutAnimationsBatch.asObject(rt).asArray(rt);
Expand Down Expand Up @@ -464,37 +464,37 @@ jsi::Value NativeReanimatedModule::configureLayoutAnimationBatch(
return jsi::Value::undefined();
}

void NativeReanimatedModule::setShouldAnimateExiting(
void ReanimatedModuleProxy::setShouldAnimateExiting(
jsi::Runtime &rt,
const jsi::Value &viewTag,
const jsi::Value &shouldAnimate) {
layoutAnimationsManager_->setShouldAnimateExiting(
viewTag.asNumber(), shouldAnimate.getBool());
}

bool NativeReanimatedModule::isAnyHandlerWaitingForEvent(
bool ReanimatedModuleProxy::isAnyHandlerWaitingForEvent(
const std::string &eventName,
const int emitterReactTag) {
return eventHandlerRegistry_->isAnyHandlerWaitingForEvent(
eventName, emitterReactTag);
}

void NativeReanimatedModule::requestAnimationFrame(
void ReanimatedModuleProxy::requestAnimationFrame(
jsi::Runtime &rt,
const jsi::Value &callback) {
frameCallbacks_.push_back(std::make_shared<jsi::Value>(rt, callback));
maybeRequestRender();
}

void NativeReanimatedModule::maybeRequestRender() {
void ReanimatedModuleProxy::maybeRequestRender() {
if (!renderRequested_) {
renderRequested_ = true;
jsi::Runtime &uiRuntime = uiWorkletRuntime_->getJSIRuntime();
requestRender_(onRenderCallback_, uiRuntime);
}
}

void NativeReanimatedModule::onRender(double timestampMs) {
void ReanimatedModuleProxy::onRender(double timestampMs) {
auto callbacks = std::move(frameCallbacks_);
frameCallbacks_.clear();
jsi::Runtime &uiRuntime = uiWorkletRuntime_->getJSIRuntime();
Expand All @@ -504,7 +504,7 @@ void NativeReanimatedModule::onRender(double timestampMs) {
}
}

jsi::Value NativeReanimatedModule::registerSensor(
jsi::Value ReanimatedModuleProxy::registerSensor(
jsi::Runtime &rt,
const jsi::Value &sensorType,
const jsi::Value &interval,
Expand All @@ -519,18 +519,18 @@ jsi::Value NativeReanimatedModule::registerSensor(
sensorDataHandler);
}

void NativeReanimatedModule::unregisterSensor(
void ReanimatedModuleProxy::unregisterSensor(
jsi::Runtime &,
const jsi::Value &sensorId) {
animatedSensorModule_.unregisterSensor(sensorId);
}

void NativeReanimatedModule::cleanupSensors() {
void ReanimatedModuleProxy::cleanupSensors() {
animatedSensorModule_.unregisterAllSensors();
}

#ifdef RCT_NEW_ARCH_ENABLED
bool NativeReanimatedModule::isThereAnyLayoutProp(
bool ReanimatedModuleProxy::isThereAnyLayoutProp(
jsi::Runtime &rt,
const jsi::Object &props) {
const jsi::Array propNames = props.getPropertyNames(rt);
Expand All @@ -546,7 +546,7 @@ bool NativeReanimatedModule::isThereAnyLayoutProp(
return false;
}

jsi::Value NativeReanimatedModule::filterNonAnimatableProps(
jsi::Value ReanimatedModuleProxy::filterNonAnimatableProps(
jsi::Runtime &rt,
const jsi::Value &props) {
jsi::Object nonAnimatableProps(rt);
Expand All @@ -570,7 +570,7 @@ jsi::Value NativeReanimatedModule::filterNonAnimatableProps(
}
#endif // RCT_NEW_ARCH_ENABLED

bool NativeReanimatedModule::handleEvent(
bool ReanimatedModuleProxy::handleEvent(
const std::string &eventName,
const int emitterReactTag,
const jsi::Value &payload,
Expand All @@ -584,7 +584,7 @@ bool NativeReanimatedModule::handleEvent(
}

#ifdef RCT_NEW_ARCH_ENABLED
bool NativeReanimatedModule::handleRawEvent(
bool ReanimatedModuleProxy::handleRawEvent(
const RawEvent &rawEvent,
double currentTime) {
const EventTarget *eventTarget = rawEvent.eventTarget.get();
Expand Down Expand Up @@ -615,7 +615,7 @@ bool NativeReanimatedModule::handleRawEvent(
return res;
}

void NativeReanimatedModule::updateProps(
void ReanimatedModuleProxy::updateProps(
jsi::Runtime &rt,
const jsi::Value &operations) {
auto array = operations.asObject(rt).asArray(rt);
Expand All @@ -630,7 +630,7 @@ void NativeReanimatedModule::updateProps(
}
}

void NativeReanimatedModule::performOperations() {
void ReanimatedModuleProxy::performOperations() {
if (operationsInBatch_.empty() && tagsToRemove_.empty()) {
// nothing to do
return;
Expand Down Expand Up @@ -755,7 +755,7 @@ void NativeReanimatedModule::performOperations() {
}
}

void NativeReanimatedModule::removeFromPropsRegistry(
void ReanimatedModuleProxy::removeFromPropsRegistry(
jsi::Runtime &rt,
const jsi::Value &viewTags) {
auto array = viewTags.asObject(rt).asArray(rt);
Expand All @@ -764,7 +764,7 @@ void NativeReanimatedModule::removeFromPropsRegistry(
}
}

void NativeReanimatedModule::dispatchCommand(
void ReanimatedModuleProxy::dispatchCommand(
jsi::Runtime &rt,
const jsi::Value &shadowNodeValue,
const jsi::Value &commandNameValue,
Expand All @@ -775,7 +775,7 @@ void NativeReanimatedModule::dispatchCommand(
uiManager_->dispatchCommand(shadowNode, commandName, args);
}

jsi::String NativeReanimatedModule::obtainProp(
jsi::String ReanimatedModuleProxy::obtainProp(
jsi::Runtime &rt,
const jsi::Value &shadowNodeWrapper,
const jsi::Value &propName) {
Expand All @@ -787,7 +787,7 @@ jsi::String NativeReanimatedModule::obtainProp(
return jsi::String::createFromUtf8(rt, resultStr);
}

jsi::Value NativeReanimatedModule::measure(
jsi::Value ReanimatedModuleProxy::measure(
jsi::Runtime &rt,
const jsi::Value &shadowNodeValue) {
// based on implementation from UIManagerBinding.cpp
Expand Down Expand Up @@ -831,7 +831,7 @@ jsi::Value NativeReanimatedModule::measure(
return result;
}

void NativeReanimatedModule::initializeFabric(
void ReanimatedModuleProxy::initializeFabric(
const std::shared_ptr<UIManager> &uiManager) {
uiManager_ = uiManager;

Expand All @@ -843,7 +843,7 @@ void NativeReanimatedModule::initializeFabric(
propsRegistry_, uiManager_, layoutAnimationsProxy_);
}

void NativeReanimatedModule::initializeLayoutAnimationsProxy() {
void ReanimatedModuleProxy::initializeLayoutAnimationsProxy() {
uiManager_->setAnimationDelegate(nullptr);
auto scheduler = reinterpret_cast<Scheduler *>(uiManager_->getDelegate());
auto componentDescriptorRegistry =
Expand All @@ -864,7 +864,7 @@ void NativeReanimatedModule::initializeLayoutAnimationsProxy() {

#endif // RCT_NEW_ARCH_ENABLED

jsi::Value NativeReanimatedModule::subscribeForKeyboardEvents(
jsi::Value ReanimatedModuleProxy::subscribeForKeyboardEvents(
jsi::Runtime &rt,
const jsi::Value &handlerWorklet,
const jsi::Value &isStatusBarTranslucent,
Expand All @@ -884,7 +884,7 @@ jsi::Value NativeReanimatedModule::subscribeForKeyboardEvents(
isNavigationBarTranslucent.getBool());
}

void NativeReanimatedModule::unsubscribeFromKeyboardEvents(
void ReanimatedModuleProxy::unsubscribeFromKeyboardEvents(
jsi::Runtime &,
const jsi::Value &listenerId) {
unsubscribeFromKeyboardEventsFunction_(listenerId.asNumber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <reanimated/AnimatedSensor/AnimatedSensorModule.h>
#include <reanimated/LayoutAnimations/LayoutAnimationsManager.h>
#include <reanimated/NativeModules/NativeReanimatedModuleSpec.h>
#include <reanimated/NativeModules/ReanimatedModuleProxySpec.h>
#include <reanimated/Tools/PlatformDepMethodsHolder.h>

#ifdef RCT_NEW_ARCH_ENABLED
Expand Down Expand Up @@ -30,9 +30,9 @@

namespace reanimated {

class NativeReanimatedModule : public NativeReanimatedModuleSpec {
class ReanimatedModuleProxy : public ReanimatedModuleProxySpec {
public:
NativeReanimatedModule(
ReanimatedModuleProxy(
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
Expand All @@ -41,7 +41,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const bool isBridgeless,
const bool isReducedMotion);

~NativeReanimatedModule();
~ReanimatedModuleProxy();

void scheduleOnUI(jsi::Runtime &rt, const jsi::Value &worklet) override;
jsi::Value executeOnUIRuntimeSync(jsi::Runtime &rt, const jsi::Value &worklet)
Expand Down Expand Up @@ -235,8 +235,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEventsFunction_;

#ifndef NDEBUG
worklets::SingleInstanceChecker<NativeReanimatedModule>
singleInstanceChecker_;
worklets::SingleInstanceChecker<ReanimatedModuleProxy> singleInstanceChecker_;
#endif // NDEBUG
};

Expand Down
Loading
Loading