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

Use RuntimeExecutor from CatalystInstance in Fabric's Binding #28875

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -13,6 +13,7 @@
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.JavaScriptContextHolder;
import com.facebook.react.bridge.NativeMap;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.bridge.queue.MessageQueueThread;
import com.facebook.react.fabric.events.EventBeatManager;
import com.facebook.react.uimanager.PixelUtil;
Expand All @@ -35,6 +36,7 @@ public Binding() {

private native void installFabricUIManager(
long jsContextNativePointer,
RuntimeExecutor runtimeExecutor,
Object uiManager,
EventBeatManager eventBeatManager,
MessageQueueThread jsMessageQueueThread,
Expand Down Expand Up @@ -72,8 +74,10 @@ public native void setConstraints(

public native void driveCxxAnimations();

// TODO (T67721598) Remove the jsContext param once we've migrated to using RuntimeExecutor
public void register(
@NonNull JavaScriptContextHolder jsContext,
@NonNull RuntimeExecutor runtimeExecutor,
@NonNull FabricUIManager fabricUIManager,
@NonNull EventBeatManager eventBeatManager,
@NonNull MessageQueueThread jsMessageQueueThread,
Expand All @@ -82,6 +86,7 @@ public void register(
fabricUIManager.setBinding(this);
installFabricUIManager(
jsContext.get(),
runtimeExecutor,
fabricUIManager,
eventBeatManager,
jsMessageQueueThread,
Expand Down
Expand Up @@ -74,8 +74,10 @@ public UIManager get() {
.getCatalystInstance()
.getReactQueueConfiguration()
.getJSQueueThread();

binding.register(
mJSContext,
mReactApplicationContext.getCatalystInstance().getRuntimeExecutor(),
uiManager,
eventBeatManager,
jsMessageQueueThread,
Expand Down
Expand Up @@ -214,6 +214,7 @@ void Binding::setConstraints(

void Binding::installFabricUIManager(
jlong jsContextNativePointer,
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
jni::alias_ref<jobject> javaUIManager,
EventBeatManager *eventBeatManager,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
Expand Down Expand Up @@ -247,15 +248,23 @@ void Binding::installFabricUIManager(
auto sharedJSMessageQueueThread =
std::make_shared<JMessageQueueThread>(jsMessageQueueThread);

Runtime *runtime = (Runtime *)jsContextNativePointer;
RuntimeExecutor runtimeExecutor =
[runtime, sharedJSMessageQueueThread](
std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
sharedJSMessageQueueThread->runOnQueue(
[runtime, callback = std::move(callback)]() {
callback(*runtime);
});
};
bool useRuntimeExecutor =
config->getBool("react_fabric:use_shared_runtime_executor_android");

RuntimeExecutor runtimeExecutor;
if (useRuntimeExecutor) {
runtimeExecutor = runtimeExecutorHolder->cthis()->get();
} else {
Runtime *runtime = (Runtime *)jsContextNativePointer;
runtimeExecutor =
[runtime, sharedJSMessageQueueThread](
std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
sharedJSMessageQueueThread->runOnQueue(
[runtime, callback = std::move(callback)]() {
callback(*runtime);
});
};
}

// TODO: T31905686 Create synchronous Event Beat
jni::global_ref<jobject> localJavaUIManager = javaUIManager_;
Expand Down
Expand Up @@ -10,6 +10,7 @@
#include <fbjni/fbjni.h>
#include <react/animations/LayoutAnimationDriver.h>
#include <react/jni/JMessageQueueThread.h>
#include <react/jni/JRuntimeExecutor.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/scheduler/Scheduler.h>
#include <react/scheduler/SchedulerDelegate.h>
Expand Down Expand Up @@ -50,6 +51,7 @@ class Binding : public jni::HybridClass<Binding>,

void installFabricUIManager(
jlong jsContextNativePointer,
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutorHolder,
jni::alias_ref<jobject> javaUIManager,
EventBeatManager *eventBeatManager,
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
Expand Down