diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/hermes/HermesInstance.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/hermes/HermesInstance.kt index 2f7697b249405b..41f3b4b83854c0 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/hermes/HermesInstance.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/hermes/HermesInstance.kt @@ -9,13 +9,17 @@ package com.facebook.react.runtime.hermes import com.facebook.jni.HybridData import com.facebook.jni.annotations.DoNotStrip +import com.facebook.react.fabric.ReactNativeConfig import com.facebook.react.runtime.JSEngineInstance import com.facebook.soloader.SoLoader -class HermesInstance : JSEngineInstance(initHybrid()!!) { +class HermesInstance constructor(reactNativeConfig: ReactNativeConfig?) : + JSEngineInstance(initHybrid(reactNativeConfig as Object?)) { + + constructor() : this(null) companion object { - @JvmStatic @DoNotStrip protected external fun initHybrid(): HybridData? + @JvmStatic @DoNotStrip protected external fun initHybrid(reactNativeConfig: Object?): HybridData init { SoLoader.loadLibrary("hermesinstancejni") diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.cpp index 1de9439dc87024..3d8a9f74652443 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.cpp @@ -8,12 +8,18 @@ #include "JHermesInstance.h" #include +#include namespace facebook::react { jni::local_ref JHermesInstance::initHybrid( - jni::alias_ref) { - return makeCxxInstance(); + jni::alias_ref /* unused */, + jni::alias_ref reactNativeConfig) { + std::shared_ptr config = reactNativeConfig != nullptr + ? std::make_shared(reactNativeConfig) + : nullptr; + + return makeCxxInstance(config); } void JHermesInstance::registerNatives() { @@ -24,8 +30,8 @@ void JHermesInstance::registerNatives() { std::unique_ptr JHermesInstance::createJSRuntime( std::shared_ptr msgQueueThread) noexcept { - // TODO T105438175 Pass ReactNativeConfig to init Hermes with MobileConfig - return HermesInstance::createJSRuntime(nullptr, nullptr, msgQueueThread); + return HermesInstance::createJSRuntime( + reactNativeConfig_, nullptr, msgQueueThread); } } // namespace facebook::react diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.h b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.h index db12cfc4d5fcb8..9d500aaa3c3c30 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/JHermesInstance.h @@ -8,12 +8,12 @@ #pragma once #include -#include #include #include #include #include +#include #include #include #include "../../jni/JJSEngineInstance.h" @@ -26,10 +26,15 @@ class JHermesInstance static constexpr auto kJavaDescriptor = "Lcom/facebook/react/runtime/hermes/HermesInstance;"; - static jni::local_ref initHybrid(jni::alias_ref); + static jni::local_ref initHybrid( + jni::alias_ref /* unused */, + jni::alias_ref reactNativeConfig); static void registerNatives(); + JHermesInstance(std::shared_ptr reactNativeConfig) + : reactNativeConfig_(reactNativeConfig){}; + std::unique_ptr createJSRuntime( std::shared_ptr msgQueueThread) noexcept; @@ -37,6 +42,8 @@ class JHermesInstance private: friend HybridBase; + + std::shared_ptr reactNativeConfig_; }; } // namespace facebook::react