Skip to content

Commit

Permalink
Fixed lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Jul 16, 2024
1 parent bf83773 commit acb518d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,14 @@ 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.
// Rather than reworking our code to use fbjni throughout, this code unpacks the C++ object from the Java
// 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);

Expand Down
2 changes: 1 addition & 1 deletion packages/realm/binding/android/src/main/cpp/jni_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ JNIEnv* JniUtils::get_env(bool attach_if_needed)
JNIEnv* env;
if (s_instance->m_vm->GetEnv(reinterpret_cast<void**>(&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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.realm.react;

import androidx.annotation.NonNull;

import android.content.res.AssetManager;

import com.facebook.react.bridge.JavaScriptContextHolder;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

0 comments on commit acb518d

Please sign in to comment.