Skip to content

Commit

Permalink
refactor: rename cpp NativeWorkletsModule to WorkletsModuleProxy (#6767)
Browse files Browse the repository at this point in the history
## Summary

Analogous to:
- #6766 

`NativeWorkletsModule` is the name of the ObjC/Java modules generated
from `WorkletsModule`. It's confusing that we name some Cpp object the
same way. With this change Cpp `NativeWorkletsModule` becomes
`WorkletsModuleProxy`, the same name we use to refer to it from
JavaScript.

## Test plan

CI
  • Loading branch information
tjzel authored Nov 27, 2024
1 parent d5362c8 commit 0162804
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ using namespace facebook;
namespace reanimated {

ReanimatedModuleProxy::ReanimatedModuleProxy(
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<UIScheduler> &uiScheduler,
Expand All @@ -63,13 +63,13 @@ ReanimatedModuleProxy::ReanimatedModuleProxy(
isBridgeless ? nullptr : jsScheduler->getJSCallInvoker()),
isBridgeless_(isBridgeless),
isReducedMotion_(isReducedMotion),
nativeWorkletsModule_(nativeWorkletsModule),
workletsModuleProxy_(workletsModuleProxy),
jsScheduler_(jsScheduler),
uiScheduler_(uiScheduler),
valueUnpackerCode_(nativeWorkletsModule->getValueUnpackerCode()),
valueUnpackerCode_(workletsModuleProxy->getValueUnpackerCode()),
uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
rnRuntime,
nativeWorkletsModule->getJSQueue(),
workletsModuleProxy->getJSQueue(),
jsScheduler_,
"Reanimated UI runtime",
true /* supportsLocking */,
Expand Down Expand Up @@ -231,7 +231,7 @@ jsi::Value ReanimatedModuleProxy::createWorkletRuntime(
const jsi::Value &initializer) {
auto workletRuntime = std::make_shared<WorkletRuntime>(
rt,
nativeWorkletsModule_->getJSQueue(),
workletsModuleProxy_->getJSQueue(),
jsScheduler_,
name.asString(rt).utf8(rt),
false /* supportsLocking */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
#endif // RCT_NEW_ARCH_ENABLED

#include <worklets/NativeModules/NativeWorkletsModule.h>
#include <worklets/NativeModules/WorkletsModuleProxy.h>
#include <worklets/Registries/EventHandlerRegistry.h>
#include <worklets/Tools/JSScheduler.h>
#include <worklets/Tools/SingleInstanceChecker.h>
Expand All @@ -33,7 +33,7 @@ namespace reanimated {
class ReanimatedModuleProxy : public ReanimatedModuleProxySpec {
public:
ReanimatedModuleProxy(
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<UIScheduler> &uiScheduler,
Expand Down Expand Up @@ -174,9 +174,9 @@ class ReanimatedModuleProxy : public ReanimatedModuleProxySpec {
return isReducedMotion_;
}

[[nodiscard]] inline std::shared_ptr<NativeWorkletsModule>
getNativeWorkletsModule() const {
return nativeWorkletsModule_;
[[nodiscard]] inline std::shared_ptr<WorkletsModuleProxy>
getWorkletsModuleProxy() const {
return workletsModuleProxy_;
}

private:
Expand All @@ -193,7 +193,7 @@ class ReanimatedModuleProxy : public ReanimatedModuleProxySpec {

const bool isBridgeless_;
const bool isReducedMotion_;
const std::shared_ptr<NativeWorkletsModule> nativeWorkletsModule_;
const std::shared_ptr<WorkletsModuleProxy> workletsModuleProxy_;
const std::shared_ptr<JSScheduler> jsScheduler_;
const std::shared_ptr<UIScheduler> uiScheduler_;
const std::string valueUnpackerCode_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <react/renderer/uimanager/primitives.h>
#endif // RCT_NEW_ARCH_ENABLED

#include <worklets/NativeModules/NativeWorkletsModule.h>
#include <worklets/NativeModules/WorkletsModuleProxy.h>
#include <worklets/SharedItems/Shareables.h>

#ifdef __ANDROID__
Expand All @@ -18,16 +18,16 @@ using namespace facebook;

namespace worklets {

NativeWorkletsModule::NativeWorkletsModule(
WorkletsModuleProxy::WorkletsModuleProxy(
const std::string &valueUnpackerCode,
const std::shared_ptr<MessageQueueThread> &jsQueue)
: NativeWorkletsModuleSpec(nullptr),
: WorkletsModuleProxySpec(nullptr),
valueUnpackerCode_(valueUnpackerCode),
jsQueue_(jsQueue) {}

NativeWorkletsModule::~NativeWorkletsModule() {}
WorkletsModuleProxy::~WorkletsModuleProxy() {}

jsi::Value NativeWorkletsModule::makeShareableClone(
jsi::Value WorkletsModuleProxy::makeShareableClone(
jsi::Runtime &rt,
const jsi::Value &value,
const jsi::Value &shouldRetainRemote,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#pragma once

#include <cxxreact/MessageQueueThread.h>
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h>
#include <worklets/NativeModules/WorkletsModuleProxySpec.h>
#include <worklets/Tools/SingleInstanceChecker.h>
#include <worklets/WorkletRuntime/WorkletRuntime.h>
#include <memory>
#include <string>

namespace worklets {

class NativeWorkletsModule : public NativeWorkletsModuleSpec {
class WorkletsModuleProxy : public WorkletsModuleProxySpec {
public:
explicit NativeWorkletsModule(
explicit WorkletsModuleProxy(
const std::string &valueUnpackerCode,
const std::shared_ptr<MessageQueueThread> &jsQueue);

~NativeWorkletsModule();
~WorkletsModuleProxy();

jsi::Value makeShareableClone(
jsi::Runtime &rt,
Expand All @@ -35,7 +35,7 @@ class NativeWorkletsModule : public NativeWorkletsModuleSpec {
const std::string valueUnpackerCode_;
const std::shared_ptr<MessageQueueThread> jsQueue_;
#ifndef NDEBUG
SingleInstanceChecker<NativeWorkletsModule> singleInstanceChecker_;
SingleInstanceChecker<WorkletsModuleProxy> singleInstanceChecker_;
#endif // NDEBUG
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <worklets/NativeModules/NativeWorkletsModuleSpec.h>
#include <worklets/NativeModules/WorkletsModuleProxySpec.h>

#include <utility>

#define WORKLETS_SPEC_PREFIX(FN_NAME) \
__hostFunction_NativeWorkletsModuleSpec_##FN_NAME
__hostFunction_WorkletsModuleProxySpec_##FN_NAME

namespace worklets {

Expand All @@ -12,12 +12,12 @@ static jsi::Value WORKLETS_SPEC_PREFIX(makeShareableClone)(
TurboModule &turboModule,
const jsi::Value *args,
size_t) {
return static_cast<NativeWorkletsModuleSpec *>(&turboModule)
return static_cast<WorkletsModuleProxySpec *>(&turboModule)
->makeShareableClone(
rt, std::move(args[0]), std::move(args[1]), std::move(args[2]));
}

NativeWorkletsModuleSpec::NativeWorkletsModuleSpec(
WorkletsModuleProxySpec::WorkletsModuleProxySpec(
const std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("NativeWorklets", jsInvoker) {
methodMap_["makeShareableClone"] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ using namespace react;

namespace worklets {

class JSI_EXPORT NativeWorkletsModuleSpec : public TurboModule {
class JSI_EXPORT WorkletsModuleProxySpec : public TurboModule {
protected:
explicit NativeWorkletsModuleSpec(
explicit WorkletsModuleProxySpec(
const std::shared_ptr<CallInvoker> jsInvoker);

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace worklets {

void RNRuntimeWorkletDecorator::decorate(
jsi::Runtime &rnRuntime,
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule) {
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy) {
rnRuntime.global().setProperty(
rnRuntime,
"__workletsModuleProxy",
jsi::Object::createFromHostObject(rnRuntime, nativeWorkletsModule));
jsi::Object::createFromHostObject(rnRuntime, workletsModuleProxy));
}

} // namespace worklets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <jsi/jsi.h>
#include <worklets/NativeModules/NativeWorkletsModule.h>
#include <worklets/NativeModules/WorkletsModuleProxy.h>
#include <memory>

using namespace facebook;
Expand All @@ -13,7 +13,7 @@ class RNRuntimeWorkletDecorator {
public:
static void decorate(
jsi::Runtime &rnRuntime,
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule);
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy);
};

} // namespace worklets
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ using namespace react;

NativeProxy::NativeProxy(
jni::alias_ref<NativeProxy::javaobject> jThis,
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime *rnRuntime,
const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker,
const std::shared_ptr<UIScheduler> &uiScheduler,
Expand All @@ -42,7 +42,7 @@ NativeProxy::NativeProxy(
: javaPart_(jni::make_global(jThis)),
rnRuntime_(rnRuntime),
reanimatedModuleProxy_(std::make_shared<ReanimatedModuleProxy>(
nativeWorkletsModule,
workletsModuleProxy,
*rnRuntime,
std::make_shared<JSScheduler>(*rnRuntime, jsCallInvoker),
uiScheduler,
Expand All @@ -58,7 +58,7 @@ NativeProxy::NativeProxy(
#ifdef RCT_NEW_ARCH_ENABLED
NativeProxy::NativeProxy(
jni::alias_ref<NativeProxy::javaobject> jThis,
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime *rnRuntime,
RuntimeExecutor runtimeExecutor,
const std::shared_ptr<UIScheduler> &uiScheduler,
Expand All @@ -68,7 +68,7 @@ NativeProxy::NativeProxy(
: javaPart_(jni::make_global(jThis)),
rnRuntime_(rnRuntime),
reanimatedModuleProxy_(std::make_shared<ReanimatedModuleProxy>(
nativeWorkletsModule,
workletsModuleProxy,
*rnRuntime,
std::make_shared<JSScheduler>(*rnRuntime, runtimeExecutor),
uiScheduler,
Expand Down Expand Up @@ -123,11 +123,10 @@ jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybrid(
) {
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
auto uiScheduler = androidUiScheduler->cthis()->getUIScheduler();
auto nativeWorkletsModule =
jWorkletsModule->cthis()->getNativeWorkletsModule();
auto workletsModuleProxy = jWorkletsModule->cthis()->getWorkletsModuleProxy();
return makeCxxInstance(
jThis,
nativeWorkletsModule,
workletsModuleProxy,
(jsi::Runtime *)jsContext,
jsCallInvoker,
uiScheduler,
Expand All @@ -151,11 +150,10 @@ jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybridBridgeless(
fabricUIManager) {
auto uiScheduler = androidUiScheduler->cthis()->getUIScheduler();
auto runtimeExecutor = runtimeExecutorHolder->cthis()->get();
auto nativeWorkletsModule =
jWorkletsModule->cthis()->getNativeWorkletsModule();
auto workletsModuleProxy = jWorkletsModule->cthis()->getWorkletsModuleProxy();
return makeCxxInstance(
jThis,
nativeWorkletsModule,
workletsModuleProxy,
(jsi::Runtime *)jsContext,
runtimeExecutor,
uiScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class NativeProxy : public jni::HybridClass<NativeProxy> {

explicit NativeProxy(
jni::alias_ref<NativeProxy::jhybridobject> jThis,
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime *rnRuntime,
const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker,
const std::shared_ptr<UIScheduler> &uiScheduler,
Expand All @@ -290,7 +290,7 @@ class NativeProxy : public jni::HybridClass<NativeProxy> {
#ifdef RCT_NEW_ARCH_ENABLED
explicit NativeProxy(
jni::alias_ref<NativeProxy::jhybridobject> jThis,
const std::shared_ptr<NativeWorkletsModule> &nativeWorkletsModule,
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime *rnRuntime,
RuntimeExecutor runtimeExecutor,
const std::shared_ptr<UIScheduler> &uiScheduler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ WorkletsModule::WorkletsModule(
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread)
: javaPart_(jni::make_global(jThis)),
rnRuntime_(rnRuntime),
nativeWorkletsModule_(std::make_shared<NativeWorkletsModule>(
workletsModuleProxy_(std::make_shared<WorkletsModuleProxy>(
valueUnpackerCode,
std::make_shared<JMessageQueueThread>(messageQueueThread))) {
RNRuntimeWorkletDecorator::decorate(*rnRuntime_, nativeWorkletsModule_);
RNRuntimeWorkletDecorator::decorate(*rnRuntime_, workletsModuleProxy_);
}

jni::local_ref<WorkletsModule::jhybriddata> WorkletsModule::initHybrid(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <react/jni/JMessageQueueThread.h>
#include <react/jni/WritableNativeMap.h>

#include <worklets/NativeModules/NativeWorkletsModule.h>
#include <worklets/NativeModules/WorkletsModuleProxy.h>

#include <memory>
#include <string>
Expand All @@ -36,15 +36,15 @@ class WorkletsModule : public jni::HybridClass<WorkletsModule> {

static void registerNatives();

inline std::shared_ptr<NativeWorkletsModule> getNativeWorkletsModule() {
return nativeWorkletsModule_;
inline std::shared_ptr<WorkletsModuleProxy> getWorkletsModuleProxy() {
return workletsModuleProxy_;
}

private:
friend HybridBase;
jni::global_ref<WorkletsModule::javaobject> javaPart_;
jsi::Runtime *rnRuntime_;
std::shared_ptr<NativeWorkletsModule> nativeWorkletsModule_;
std::shared_ptr<WorkletsModuleProxy> workletsModuleProxy_;

explicit WorkletsModule(
jni::alias_ref<WorkletsModule::jhybridobject> jThis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ static inline bool getIsReducedMotion()
std::shared_ptr<JSScheduler> jsScheduler = std::make_shared<JSScheduler>(rnRuntime, jsInvoker);
constexpr auto isBridgeless = false;

const auto nativeWorkletsModule = [workletsModule getNativeWorkletsModule];
const auto workletsModuleProxy = [workletsModule getWorkletsModuleProxy];

auto reanimatedModuleProxy = std::make_shared<ReanimatedModuleProxy>(
nativeWorkletsModule,
workletsModuleProxy,
rnRuntime,
jsScheduler,
uiScheduler,
Expand Down Expand Up @@ -109,13 +109,13 @@ static inline bool getIsReducedMotion()
PlatformDepMethodsHolder platformDepMethodsHolder =
makePlatformDepMethodsHolderBridgeless(moduleRegistry, nodesManager, reaModule);

const auto nativeWorkletsModule = [workletsModule getNativeWorkletsModule];
const auto workletsModuleProxy = [workletsModule getWorkletsModuleProxy];
auto uiScheduler = std::make_shared<REAIOSUIScheduler>();
auto jsScheduler = std::make_shared<JSScheduler>(runtime, runtimeExecutor);
constexpr auto isBridgeless = true;

auto reanimatedModuleProxy = std::make_shared<ReanimatedModuleProxy>(
nativeWorkletsModule,
workletsModuleProxy,
runtime,
jsScheduler,
uiScheduler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <worklets/NativeModules/NativeWorkletsModule.h>
#import <worklets/NativeModules/WorkletsModuleProxy.h>

@interface WorkletsModule : RCTEventEmitter <RCTBridgeModule>

- (std::shared_ptr<worklets::NativeWorkletsModule>)getNativeWorkletsModule;
- (std::shared_ptr<worklets::WorkletsModuleProxy>)getWorkletsModuleProxy;

@end
Loading

0 comments on commit 0162804

Please sign in to comment.