diff --git a/packages/realm/binding/android/src/main/cpp/io_realm_react_RealmReactModule.cpp b/packages/realm/binding/android/src/main/cpp/io_realm_react_RealmReactModule.cpp index 48894cfdf4..71a3b31aab 100644 --- a/packages/realm/binding/android/src/main/cpp/io_realm_react_RealmReactModule.cpp +++ b/packages/realm/binding/android/src/main/cpp/io_realm_react_RealmReactModule.cpp @@ -111,10 +111,6 @@ extern "C" JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaul extern "C" JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_injectCallInvoker(JNIEnv* env, jobject thiz, jobject call_invoker) { - // TODO: Skip when the microtask queue is enabled: - // See - // https://github.com/facebook/react-native/pull/43396/files#diff-b7fda5d350ac535115fa683faa7317b43aa11f3448f95266ef9ff051c3753a6fR270-R281 - // React Native uses the fbjni library for handling JNI, which has the concept of "hybrid objects", // which are Java objects containing a pointer to a C++ object. The CallInvokerHolder, which has the // invokeAsync method we want access to, is one such hybrid object. @@ -122,7 +118,7 @@ extern "C" JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_injectCal // object `callInvokerHolderJavaObj` manually, based on reverse engineering the fbjni code. // 1. Get the Java object referred to by the mHybridData field of the Java holder object - auto callInvokerHolderClass = env->GetObjectClass(call_invoker); + auto callInvokerHolderClass = env->FindClass("com/facebook/react/turbomodule/core/CallInvokerHolderImpl"); auto hybridDataField = env->GetFieldID(callInvokerHolderClass, "mHybridData", "Lcom/facebook/jni/HybridData;"); auto hybridDataObj = env->GetObjectField(call_invoker, hybridDataField); diff --git a/packages/realm/binding/android/src/main/cpp/jni_utils.cpp b/packages/realm/binding/android/src/main/cpp/jni_utils.cpp index 58b667ac8d..a5b51e4d83 100644 --- a/packages/realm/binding/android/src/main/cpp/jni_utils.cpp +++ b/packages/realm/binding/android/src/main/cpp/jni_utils.cpp @@ -37,7 +37,7 @@ JNIEnv* JniUtils::get_env(bool attach_if_needed) JNIEnv* env; if (s_instance->m_vm->GetEnv(reinterpret_cast(&env), s_instance->m_vm_version) != JNI_OK) { if (attach_if_needed) { - jint ret = s_instance->m_vm->AttachCurrentThread(&env, nullptr); + s_instance->m_vm->AttachCurrentThread(&env, nullptr); } } diff --git a/packages/realm/binding/android/src/main/java/io/realm/react/RealmReactModule.java b/packages/realm/binding/android/src/main/java/io/realm/react/RealmReactModule.java index f9900859f4..3f122083d6 100644 --- a/packages/realm/binding/android/src/main/java/io/realm/react/RealmReactModule.java +++ b/packages/realm/binding/android/src/main/java/io/realm/react/RealmReactModule.java @@ -17,6 +17,7 @@ package io.realm.react; import androidx.annotation.NonNull; + import android.content.res.AssetManager; import com.facebook.react.bridge.JavaScriptContextHolder; @@ -25,7 +26,7 @@ import com.facebook.react.bridge.ReactMethod; import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags; import com.facebook.react.module.annotations.ReactModule; -import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; +import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; import com.facebook.soloader.SoLoader; import java.io.IOException; @@ -75,13 +76,7 @@ public boolean injectModuleIntoJSGlobal() { throw new IllegalStateException(e); } - // Since https://github.com/facebook/react-native/pull/43396 this should only be needed when bridgeless is not enabled. - // but unfortunately, that doesn't seem to be the case. - // See https://github.com/facebook/react-native/pull/43396#issuecomment-2178586017 for context - // If it was, we could use the enablement of "microtasks" to avoid the overhead of calling the invokeAsync on every call from C++ into JS. - // if (!ReactNativeFeatureFlags.enableMicrotasks()) - - CallInvokerHolderImpl jsCallInvokerHolder = (CallInvokerHolderImpl) reactContext.getCatalystInstance().getJSCallInvokerHolder(); + CallInvokerHolder jsCallInvokerHolder = reactContext.getCatalystInstance().getJSCallInvokerHolder(); injectCallInvoker(jsCallInvokerHolder); // Get the javascript runtime and inject our native module with it @@ -112,7 +107,7 @@ public boolean injectModuleIntoJSGlobal() { * This is needed as a workaround for https://github.com/facebook/react-native/issues/33006 * where we call the invokeAsync method to flush the React Native UI queue whenever we call from C++ to JS. */ - private native void injectCallInvoker(CallInvokerHolderImpl callInvoker); + private native void injectCallInvoker(CallInvokerHolder callInvoker); private native void invalidateCaches(); }