diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManager.kt index b7ae3fed8af..71ebba6e7cb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManager.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManager.kt @@ -62,7 +62,7 @@ public class TurboModuleManager( installJSIBindings(shouldEnableLegacyModuleInterop()) - eagerInitModuleNames = delegate?.eagerInitModuleNames ?: emptyList() + eagerInitModuleNames = delegate?.getEagerInitModuleNames() ?: emptyList() val nullProvider: ModuleProvider = ModuleProvider { _: String -> null } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.java deleted file mode 100644 index 2fd89a4d85b..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.internal.turbomodule.core; - -import androidx.annotation.Nullable; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.turbomodule.core.interfaces.TurboModule; -import com.facebook.soloader.SoLoader; -import java.util.Collections; -import java.util.List; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public abstract class TurboModuleManagerDelegate { - @DoNotStrip - @SuppressWarnings("unused") - private final HybridData mHybridData; - - static { - SoLoader.loadLibrary("turbomodulejsijni"); - } - - protected abstract HybridData initHybrid(); - - protected TurboModuleManagerDelegate() { - maybeLoadOtherSoLibraries(); - mHybridData = initHybrid(); - } - - protected TurboModuleManagerDelegate(HybridData hybridData) { - maybeLoadOtherSoLibraries(); - mHybridData = hybridData; - } - - /** - * Create and return a TurboModule Java object with name `moduleName`. If `moduleName` isn't a - * TurboModule, return null. - */ - @Nullable - public abstract TurboModule getModule(String moduleName); - - public abstract boolean unstable_isModuleRegistered(String moduleName); - - /** - * Create an return a legacy NativeModule with name `moduleName`. If `moduleName` is a - * TurboModule, return null. - */ - @Nullable - public NativeModule getLegacyModule(String moduleName) { - return null; - } - - public boolean unstable_isLegacyModuleRegistered(String moduleName) { - return false; - } - ; - - public List getEagerInitModuleNames() { - return Collections.emptyList(); - } - - /** Can the TurboModule system create legacy modules? */ - public boolean unstable_shouldEnableLegacyModuleInterop() { - return false; - } - - // TODO(T171231381): Consider removing this method: could we just use the static initializer - // of derived classes instead? - protected synchronized void maybeLoadOtherSoLibraries() {} -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.kt new file mode 100644 index 00000000000..d9eb6ca616c --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.kt @@ -0,0 +1,63 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.internal.turbomodule.core + +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStrip +import com.facebook.react.bridge.NativeModule +import com.facebook.react.turbomodule.core.interfaces.TurboModule +import com.facebook.soloader.SoLoader + +public abstract class TurboModuleManagerDelegate { + + // NOTE: This *must* be called "mHybridData" + @DoNotStrip @Suppress("unused", "NoHungarianNotation") private val mHybridData: HybridData + + protected abstract fun initHybrid(): HybridData + + protected constructor() { + maybeLoadOtherSoLibraries() + mHybridData = initHybrid() + } + + protected constructor(hybridData: HybridData) { + maybeLoadOtherSoLibraries() + this.mHybridData = hybridData + } + + /** + * Create and return a TurboModule Java object with name `moduleName`. If `moduleName` isn't a + * TurboModule, return null. + */ + public abstract fun getModule(moduleName: String?): TurboModule? + + public abstract fun unstable_isModuleRegistered(moduleName: String?): Boolean + + /** + * Create an return a legacy NativeModule with name `moduleName`. If `moduleName` is a + * TurboModule, return null. + */ + public open fun getLegacyModule(moduleName: String?): NativeModule? = null + + public open fun unstable_isLegacyModuleRegistered(moduleName: String?): Boolean = false + + public open fun getEagerInitModuleNames(): List = emptyList() + + /** Can the TurboModule system create legacy modules? */ + public open fun unstable_shouldEnableLegacyModuleInterop(): Boolean = false + + // TODO(T171231381): Consider removing this method: could we just use the static initializer + // of derived classes instead? + @Synchronized protected fun maybeLoadOtherSoLibraries(): Unit = Unit + + private companion object { + init { + SoLoader.loadLibrary("turbomodulejsijni") + } + } +}