Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 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
Expand Up @@ -54,23 +54,21 @@ namespace reanimated {
ReanimatedModuleProxy::ReanimatedModuleProxy(
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<CallInvoker> &jsCallInvoker,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const bool isBridgeless,
const bool isReducedMotion)
: ReanimatedModuleProxySpec(
isBridgeless ? nullptr : jsScheduler->getJSCallInvoker()),
: ReanimatedModuleProxySpec(jsCallInvoker),
isBridgeless_(isBridgeless),
isReducedMotion_(isReducedMotion),
workletsModuleProxy_(workletsModuleProxy),
jsScheduler_(jsScheduler),
uiScheduler_(uiScheduler),
valueUnpackerCode_(workletsModuleProxy->getValueUnpackerCode()),
uiWorkletRuntime_(std::make_shared<WorkletRuntime>(
rnRuntime,
workletsModuleProxy->getJSQueue(),
jsScheduler_,
workletsModuleProxy->getJSScheduler(),
"Reanimated UI runtime",
true /* supportsLocking */,
valueUnpackerCode_)),
Expand All @@ -81,7 +79,8 @@ ReanimatedModuleProxy::ReanimatedModuleProxy(
onRender(timestampMs);
}),
animatedSensorModule_(platformDepMethodsHolder),
jsLogger_(std::make_shared<JSLogger>(jsScheduler_)),
jsLogger_(
std::make_shared<JSLogger>(workletsModuleProxy->getJSScheduler())),
layoutAnimationsManager_(
std::make_shared<LayoutAnimationsManager>(jsLogger_)),
#ifdef RCT_NEW_ARCH_ENABLED
Expand Down Expand Up @@ -235,7 +234,7 @@ jsi::Value ReanimatedModuleProxy::createWorkletRuntime(
auto workletRuntime = std::make_shared<WorkletRuntime>(
rt,
workletsModuleProxy_->getJSQueue(),
jsScheduler_,
workletsModuleProxy_->getJSScheduler(),
name.asString(rt).utf8(rt),
false /* supportsLocking */,
valueUnpackerCode_);
Expand Down Expand Up @@ -352,16 +351,17 @@ jsi::Value ReanimatedModuleProxy::getViewProp(
const auto funPtr = std::make_shared<jsi::Function>(
callback.getObject(rnRuntime).asFunction(rnRuntime));
const auto shadowNode = shadowNodeFromValue(rnRuntime, shadowNodeWrapper);
uiScheduler_->scheduleOnUI([=]() {
uiScheduler_->scheduleOnUI(COPY_CAPTURE_WITH_THIS {
jsi::Runtime &uiRuntime = uiWorkletRuntime_->getJSIRuntime();
const auto resultStr =
obtainPropFromShadowNode(uiRuntime, propNameStr, shadowNode);

jsScheduler_->scheduleOnJS([=](jsi::Runtime &rnRuntime) {
const auto resultValue =
jsi::String::createFromUtf8(rnRuntime, resultStr);
funPtr->call(rnRuntime, resultValue);
});
workletsModuleProxy_->getJSScheduler()->scheduleOnJS(
[=](jsi::Runtime &rnRuntime) {
const auto resultValue =
jsi::String::createFromUtf8(rnRuntime, resultStr);
funPtr->call(rnRuntime, resultValue);
});
});
return jsi::Value::undefined();
}
Expand Down Expand Up @@ -389,8 +389,8 @@ jsi::Value ReanimatedModuleProxy::getViewProp(
const auto resultValue =
obtainPropFunction_(uiRuntime, viewTagInt, propNameValue);
const auto resultStr = resultValue.asString(uiRuntime).utf8(uiRuntime);

jsScheduler_->scheduleOnJS([=](jsi::Runtime &rnRuntime) {
const auto jsScheduler = workletsModuleProxy_->getJSScheduler();
jsScheduler->scheduleOnJS([=](jsi::Runtime &rnRuntime) {
const auto resultValue =
jsi::String::createFromUtf8(rnRuntime, resultStr);
funPtr->call(rnRuntime, resultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ReanimatedModuleProxy : public ReanimatedModuleProxySpec {
ReanimatedModuleProxy(
const std::shared_ptr<WorkletsModuleProxy> &workletsModuleProxy,
jsi::Runtime &rnRuntime,
const std::shared_ptr<JSScheduler> &jsScheduler,
const std::shared_ptr<CallInvoker> &jsCallInvoker,
const std::shared_ptr<UIScheduler> &uiScheduler,
const PlatformDepMethodsHolder &platformDepMethodsHolder,
const bool isBridgeless,
Expand Down Expand Up @@ -194,7 +194,6 @@ class ReanimatedModuleProxy : public ReanimatedModuleProxySpec {
const bool isBridgeless_;
const bool isReducedMotion_;
const std::shared_ptr<WorkletsModuleProxy> workletsModuleProxy_;
const std::shared_ptr<JSScheduler> jsScheduler_;
const std::shared_ptr<UIScheduler> uiScheduler_;
const std::string valueUnpackerCode_;
std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ namespace worklets {

WorkletsModuleProxy::WorkletsModuleProxy(
const std::string &valueUnpackerCode,
const std::shared_ptr<MessageQueueThread> &jsQueue)
: WorkletsModuleProxySpec(nullptr),
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<CallInvoker> &jsCallInvoker,
const std::shared_ptr<JSScheduler> &jsScheduler)
: WorkletsModuleProxySpec(jsCallInvoker),
valueUnpackerCode_(valueUnpackerCode),
jsQueue_(jsQueue) {}
jsQueue_(jsQueue),
jsScheduler_(jsScheduler) {}

WorkletsModuleProxy::~WorkletsModuleProxy() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cxxreact/MessageQueueThread.h>
#include <worklets/NativeModules/WorkletsModuleProxySpec.h>
#include <worklets/Tools/JSScheduler.h>
#include <worklets/Tools/SingleInstanceChecker.h>
#include <worklets/WorkletRuntime/WorkletRuntime.h>
#include <memory>
Expand All @@ -13,7 +14,9 @@ class WorkletsModuleProxy : public WorkletsModuleProxySpec {
public:
explicit WorkletsModuleProxy(
const std::string &valueUnpackerCode,
const std::shared_ptr<MessageQueueThread> &jsQueue);
const std::shared_ptr<MessageQueueThread> &jsQueue,
const std::shared_ptr<CallInvoker> &jsCallInvoker,
const std::shared_ptr<JSScheduler> &jsScheduler);

~WorkletsModuleProxy();

Expand All @@ -31,9 +34,14 @@ class WorkletsModuleProxy : public WorkletsModuleProxySpec {
return jsQueue_;
}

[[nodiscard]] inline std::shared_ptr<JSScheduler> getJSScheduler() const {
return jsScheduler_;
}

private:
const std::string valueUnpackerCode_;
const std::shared_ptr<MessageQueueThread> jsQueue_;
const std::shared_ptr<JSScheduler> jsScheduler_;
#ifndef NDEBUG
SingleInstanceChecker<WorkletsModuleProxy> singleInstanceChecker_;
#endif // NDEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,4 @@ JSScheduler::JSScheduler(
rnRuntime_(rnRuntime),
jsCallInvoker_(jsCallInvoker) {}

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

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

} // namespace worklets
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,14 @@ class JSScheduler {
using Job = std::function<void(jsi::Runtime &rt)>;

public:
// With `jsCallInvoker`.
explicit JSScheduler(
jsi::Runtime &rnRuntime,
const std::shared_ptr<CallInvoker> &jsCallInvoker);

#ifdef RCT_NEW_ARCH_ENABLED
// With `runtimeExecutor`.
explicit JSScheduler(
jsi::Runtime &rnRuntime,
RuntimeExecutor runtimeExecutor);
#endif // RCT_NEW_ARCH_ENABLED

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

protected:
jsi::Runtime &rnRuntime_;
#ifdef RCT_NEW_ARCH_ENABLED
RuntimeExecutor runtimeExecutor_ = nullptr;
#endif // RCT_NEW_ARCH_ENABLED
const std::shared_ptr<CallInvoker> jsCallInvoker_ = nullptr;
};

Expand Down
16 changes: 0 additions & 16 deletions packages/react-native-reanimated/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -362,22 +362,6 @@ android {
}
}

if (IS_NEW_ARCHITECTURE_ENABLED) {
// RuntimeExecutor and CallInvokerHolder
if (REACT_NATIVE_MINOR_VERSION <= 74) {
srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/74"
} else {
srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/latest"
}
} else {
// CallInvokerHolder
if (REACT_NATIVE_MINOR_VERSION <= 74) {
srcDirs += "src/reactNativeVersionPatch/NativeProxyPaper/74"
} else {
srcDirs += "src/reactNativeVersionPatch/NativeProxyPaper/latest"
}
}

// BorderRadiiDrawableUtils
if (REACT_NATIVE_MINOR_VERSION <= 74) {
srcDirs += "src/reactNativeVersionPatch/BorderRadiiDrawableUtils/74"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.common.annotations.FrameworkAPI;
import com.facebook.react.fabric.FabricUIManager;
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
Expand All @@ -13,10 +12,14 @@
import com.swmansion.reanimated.layoutReanimation.LayoutAnimations;
import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder;
import com.swmansion.reanimated.nativeProxy.NativeProxyCommon;
import com.swmansion.worklets.JSCallInvokerResolver;
import com.swmansion.worklets.WorkletsModule;
import java.util.HashMap;
import java.util.Objects;

/**
* @noinspection JavaJniMissingFunction
*/
public class NativeProxy extends NativeProxyCommon {
@DoNotStrip
@SuppressWarnings("unused")
Expand All @@ -32,49 +35,32 @@ public class NativeProxy extends NativeProxyCommon {

LayoutAnimations LayoutAnimations = new LayoutAnimations(context);

if (context.isBridgeless()) {
RuntimeExecutor runtimeExecutor = context.getRuntimeExecutor();
mHybridData =
initHybridBridgeless(
workletsModule,
Objects.requireNonNull(context.getJavaScriptContextHolder()).get(),
runtimeExecutor,
mAndroidUIScheduler,
LayoutAnimations,
fabricUIManager);
} else {
CallInvokerHolderImpl callInvokerHolder =
(CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder();
mHybridData =
initHybrid(
workletsModule,
Objects.requireNonNull(context.getJavaScriptContextHolder()).get(),
callInvokerHolder,
mAndroidUIScheduler,
LayoutAnimations,
fabricUIManager);
}
CallInvokerHolderImpl callInvokerHolder = JSCallInvokerResolver.getJSCallInvokerHolder(context);
mHybridData =
initHybrid(
workletsModule,
Objects.requireNonNull(context.getJavaScriptContextHolder()).get(),
callInvokerHolder,
mAndroidUIScheduler,
LayoutAnimations,
context.isBridgeless(),
fabricUIManager);

prepareLayoutAnimations(LayoutAnimations);
installJSIBindings();
if (BuildConfig.DEBUG) {
checkCppVersion();
}
}

@OptIn(markerClass = FrameworkAPI.class)
private native HybridData initHybrid(
WorkletsModule workletsModule,
long jsContext,
CallInvokerHolderImpl jsCallInvokerHolder,
AndroidUIScheduler androidUIScheduler,
LayoutAnimations LayoutAnimations,
FabricUIManager fabricUIManager);

private native HybridData initHybridBridgeless(
WorkletsModule workletsModule,
long jsContext,
RuntimeExecutor runtimeExecutor,
AndroidUIScheduler androidUIScheduler,
LayoutAnimations LayoutAnimations,
boolean isBridgeless,
FabricUIManager fabricUIManager);

public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag);
Expand All @@ -86,7 +72,8 @@ protected HybridData getHybridData() {
return mHybridData;
}

public static NativeMethodsHolder createNativeMethodsHolder(LayoutAnimations layoutAnimations) {
public static NativeMethodsHolder createNativeMethodsHolder(
LayoutAnimations ignoredLayoutAnimations) {
return new NativeMethodsHolder() {
@Override
public void startAnimation(int tag, int type, HashMap<String, Object> values) {
Expand Down
Loading
Loading