Skip to content
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
64 changes: 8 additions & 56 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ bool CoreFeatures::useNativeState;

namespace reanimated {

// With `jsInvoker`.
NativeReanimatedModule::NativeReanimatedModule(
jsi::Runtime &rnRuntime,
const std::shared_ptr<CallInvoker> &jsInvoker,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode)
: NativeReanimatedModuleSpec(jsInvoker),
const std::string &valueUnpackerCode,
const bool isBridgeless)
: NativeReanimatedModuleSpec(
isBridgeless ? nullptr : jsScheduler->getJSCallInvoker()),
isBridgeless_(isBridgeless),
jsQueue_(jsQueue),
jsScheduler_(std::make_shared<JSScheduler>(rnRuntime, jsInvoker)),
jsScheduler_(jsScheduler),
uiScheduler_(uiScheduler),
uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
rnRuntime,
Expand Down Expand Up @@ -86,60 +88,10 @@ NativeReanimatedModule::NativeReanimatedModule(
subscribeForKeyboardEventsFunction_(
platformDepMethodsHolder.subscribeForKeyboardEvents),
unsubscribeFromKeyboardEventsFunction_(
platformDepMethodsHolder.unsubscribeFromKeyboardEvents),
isBridgeless_(false) {
platformDepMethodsHolder.unsubscribeFromKeyboardEvents) {
commonInit(platformDepMethodsHolder);
}

#if REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
// With `runtimeExecutor`.
NativeReanimatedModule::NativeReanimatedModule(
jsi::Runtime &rnRuntime,
RuntimeExecutor runtimeExecutor,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode)
: NativeReanimatedModuleSpec(nullptr),
jsQueue_(jsQueue),
jsScheduler_(std::make_shared<JSScheduler>(rnRuntime, runtimeExecutor)),
uiScheduler_(uiScheduler),
uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
rnRuntime,
jsQueue,
jsScheduler_,
"Reanimated UI runtime",
true /* supportsLocking */,
valueUnpackerCode)),
valueUnpackerCode_(valueUnpackerCode),
eventHandlerRegistry_(std::make_unique<EventHandlerRegistry>()),
requestRender_(platformDepMethodsHolder.requestRender),
onRenderCallback_([this](const double timestampMs) {
renderRequested_ = false;
onRender(timestampMs);
}),
animatedSensorModule_(platformDepMethodsHolder),
jsLogger_(std::make_shared<JSLogger>(jsScheduler_)),
layoutAnimationsManager_(jsLogger_),
#ifdef RCT_NEW_ARCH_ENABLED
synchronouslyUpdateUIPropsFunction_(
platformDepMethodsHolder.synchronouslyUpdateUIPropsFunction),
propsRegistry_(std::make_shared<PropsRegistry>()),
#else
obtainPropFunction_(platformDepMethodsHolder.obtainPropFunction),
configurePropsPlatformFunction_(
platformDepMethodsHolder.configurePropsFunction),
updatePropsFunction_(platformDepMethodsHolder.updatePropsFunction),
#endif
subscribeForKeyboardEventsFunction_(
platformDepMethodsHolder.subscribeForKeyboardEvents),
unsubscribeFromKeyboardEventsFunction_(
platformDepMethodsHolder.unsubscribeFromKeyboardEvents),
isBridgeless_(true) {
commonInit(platformDepMethodsHolder);
}
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)

void NativeReanimatedModule::commonInit(
const PlatformDepMethodsHolder &platformDepMethodsHolder) {
auto requestAnimationFrame =
Expand Down
19 changes: 4 additions & 15 deletions Common/cpp/NativeModules/NativeReanimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,14 @@ namespace reanimated {

class NativeReanimatedModule : public NativeReanimatedModuleSpec {
public:
// With `jsInvoker`.
NativeReanimatedModule(
jsi::Runtime &rnRuntime,
const std::shared_ptr<CallInvoker> &jsInvoker,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode);

#if REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
// With `runtimeExecutor`.
NativeReanimatedModule(
jsi::Runtime &rnRuntime,
RuntimeExecutor runtimeExecutor,
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const std::string &valueUnpackerCode);
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED
const std::string &valueUnpackerCode,
const bool isBridgeless);

~NativeReanimatedModule();

Expand Down Expand Up @@ -195,6 +184,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
const jsi::Value &props);
#endif // RCT_NEW_ARCH_ENABLED

const bool isBridgeless_;
const std::shared_ptr<MessageQueueThread> jsQueue_;
const std::shared_ptr<JSScheduler> jsScheduler_;
const std::shared_ptr<UIScheduler> uiScheduler_;
Expand Down Expand Up @@ -244,7 +234,6 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {
#ifndef NDEBUG
SingleInstanceChecker<NativeReanimatedModule> singleInstanceChecker_;
#endif
const bool isBridgeless_;
};

} // namespace reanimated
24 changes: 15 additions & 9 deletions Common/cpp/Tools/JSScheduler.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
#include "JSScheduler.h"

using namespace facebook;
using namespace react;

namespace reanimated {
JSScheduler::JSScheduler(
jsi::Runtime &rnRuntime,
const std::shared_ptr<CallInvoker> &jsCallInvoker)
: rnRuntime_(rnRuntime),
jsCallInvoker_(jsCallInvoker),
scheduleOnJS([&](Job job) {
: scheduleOnJS([&](Job job) {
jsCallInvoker_->invokeAsync(
[job = std::move(job), &rt = rnRuntime_] { job(rt); });
}) {}
}),
rnRuntime_(rnRuntime),
jsCallInvoker_(jsCallInvoker) {}

#if REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
// With `runtimeExecutor`.
JSScheduler::JSScheduler(
jsi::Runtime &rnRuntime,
RuntimeExecutor runtimeExecutor)
: rnRuntime_(rnRuntime),
runtimeExecutor_(runtimeExecutor),
scheduleOnJS([&](Job job) {
: scheduleOnJS([&](Job job) {
runtimeExecutor_(
[job = std::move(job)](jsi::Runtime &runtime) { job(runtime); });
}) {}
}),
rnRuntime_(rnRuntime),
runtimeExecutor_(runtimeExecutor) {}
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED

const std::shared_ptr<CallInvoker> JSScheduler::getJSCallInvoker() const {
assert(
jsCallInvoker_ != nullptr &&
"[Reanimated] Expected jsCallInvoker, got nullptr instead.");
return jsCallInvoker_;
}

} // namespace reanimated
8 changes: 4 additions & 4 deletions Common/cpp/Tools/JSScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class JSScheduler {
RuntimeExecutor runtimeExecutor);
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED

const std::function<void(Job)> scheduleOnJS = nullptr;
const std::shared_ptr<CallInvoker> getJSCallInvoker() const;

protected:
jsi::Runtime &rnRuntime_;
const std::shared_ptr<CallInvoker> jsCallInvoker_ = nullptr;
#if REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED)
RuntimeExecutor runtimeExecutor_ = nullptr;
#endif // REACT_NATIVE_MINOR_VERSION >= 74 && defined(RCT_NEW_ARCH_ENABLED

public:
const std::function<void(Job)> scheduleOnJS = nullptr;
const std::shared_ptr<CallInvoker> jsCallInvoker_ = nullptr;
};

} // namespace reanimated
11 changes: 6 additions & 5 deletions android/src/main/cpp/NativeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ NativeProxy::NativeProxy(
rnRuntime_(rnRuntime),
nativeReanimatedModule_(std::make_shared<NativeReanimatedModule>(
*rnRuntime,
jsCallInvoker,
std::make_shared<JSScheduler>(*rnRuntime, jsCallInvoker),
std::make_shared<JMessageQueueThread>(messageQueueThread),
uiScheduler,
getPlatformDependentMethods(),
valueUnpackerCode)),
valueUnpackerCode,
/* isBridgeless */ false)),
layoutAnimations_(std::move(layoutAnimations)) {
#ifdef RCT_NEW_ARCH_ENABLED
commonInit(fabricUIManager);
Expand All @@ -65,17 +66,17 @@ NativeProxy::NativeProxy(
jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
jni::alias_ref<facebook::react::JFabricUIManager::javaobject>
fabricUIManager,

const std::string &valueUnpackerCode)
: javaPart_(jni::make_global(jThis)),
rnRuntime_(rnRuntime),
nativeReanimatedModule_(std::make_shared<NativeReanimatedModule>(
*rnRuntime,
runtimeExecutor,
std::make_shared<JSScheduler>(*rnRuntime, runtimeExecutor),
std::make_shared<JMessageQueueThread>(messageQueueThread),
uiScheduler,
getPlatformDependentMethods(),
valueUnpackerCode)),
valueUnpackerCode,
/* isBridgeless */ true)),
layoutAnimations_(std::move(layoutAnimations)) {
commonInit(fabricUIManager);
}
Expand Down
16 changes: 10 additions & 6 deletions apple/native/NativeProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ - (void *)runtime;
throw error;
});

std::shared_ptr<UIScheduler> uiScheduler = std::make_shared<REAIOSUIScheduler>();

PlatformDepMethodsHolder platformDepMethodsHolder = makePlatformDepMethodsHolder(bridge, nodesManager, reaModule);

std::shared_ptr<UIScheduler> uiScheduler = std::make_shared<REAIOSUIScheduler>();
std::shared_ptr<JSScheduler> jsScheduler = std::make_shared<JSScheduler>(rnRuntime, jsInvoker);
constexpr bool isBridgeless = false;

auto nativeReanimatedModule = std::make_shared<NativeReanimatedModule>(
rnRuntime, jsInvoker, jsQueue, uiScheduler, platformDepMethodsHolder, valueUnpackerCode);
rnRuntime, jsScheduler, jsQueue, uiScheduler, platformDepMethodsHolder, valueUnpackerCode, isBridgeless);

commonInit(reaModule, nativeReanimatedModule);
// Layout Animation callbacks setup
Expand Down Expand Up @@ -95,13 +97,15 @@ - (void *)runtime;
throw error;
});

std::shared_ptr<UIScheduler> uiScheduler = std::make_shared<REAIOSUIScheduler>();

PlatformDepMethodsHolder platformDepMethodsHolder =
makePlatformDepMethodsHolderBridgeless(moduleRegistry, nodesManager, reaModule);

auto uiScheduler = std::make_shared<REAIOSUIScheduler>();
auto jsScheduler = std::make_shared<JSScheduler>(runtime, runtimeExecutor);
constexpr bool isBridgeless = true;

auto nativeReanimatedModule = std::make_shared<NativeReanimatedModule>(
runtime, runtimeExecutor, jsQueue, uiScheduler, platformDepMethodsHolder, valueUnpackerCode);
runtime, jsScheduler, jsQueue, uiScheduler, platformDepMethodsHolder, valueUnpackerCode, isBridgeless);

commonInit(reaModule, nativeReanimatedModule);

Expand Down