diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 1e7016d6bd9..85c5c5d0903 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -693,7 +693,7 @@ public class com/facebook/react/bridge/CxxModuleWrapperBase : com/facebook/react public fun getName ()Ljava/lang/String; public fun initialize ()V public fun invalidate ()V - protected fun resetModule (Lcom/facebook/jni/HybridData;)V + protected final fun resetModule (Lcom/facebook/jni/HybridData;)V } public final class com/facebook/react/bridge/DefaultJSExceptionHandler : com/facebook/react/bridge/JSExceptionHandler { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.java deleted file mode 100644 index 02ede8cd01b..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.java +++ /dev/null @@ -1,63 +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.bridge; - -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.common.annotations.internal.LegacyArchitecture; -import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel; -import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger; - -/** - * A Java Object which represents a cross-platform C++ module - * - *
This module implements the NativeModule interface but will never be invoked from Java, instead - * the underlying Cxx module will be extracted by the bridge and called directly. - */ -@DoNotStrip -@LegacyArchitecture -public class CxxModuleWrapperBase implements NativeModule { - static { - ReactBridge.staticInit(); - LegacyArchitectureLogger.assertWhenLegacyArchitectureMinifyingEnabled( - "CxxModuleWrapperBase", LegacyArchitectureLogLevel.WARNING); - } - - @DoNotStrip private HybridData mHybridData; - - @Override - public native String getName(); - - @Override - public void initialize() { - // do nothing - } - - @Override - public boolean canOverrideExistingModule() { - return false; - } - - @Override - public void invalidate() { - mHybridData.resetNative(); - } - - // For creating a wrapper from C++, or from a derived class. - protected CxxModuleWrapperBase(HybridData hd) { - mHybridData = hd; - } - - // Replace the current native module held by this wrapper by a new instance - protected void resetModule(HybridData hd) { - if (hd != mHybridData) { - mHybridData.resetNative(); - mHybridData = hd; - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.kt new file mode 100644 index 00000000000..02b3a13c02d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/CxxModuleWrapperBase.kt @@ -0,0 +1,56 @@ +/* + * 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.bridge + +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStrip +import com.facebook.react.common.annotations.internal.LegacyArchitecture +import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel +import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger + +/** + * A Java Object which represents a cross-platform C++ module + * + * This module implements the [NativeModule] interface but will never be invoked from Java, instead + * the underlying Cxx module will be extracted by the bridge and called directly. + */ +@DoNotStrip +@LegacyArchitecture +public open class CxxModuleWrapperBase +protected constructor( + // For creating a wrapper from C++, or from a derived class. + @Suppress("NoHungarianNotation") @DoNotStrip private var mHybridData: HybridData +) : NativeModule { + external override fun getName(): String + + override fun initialize() { + // do nothing + } + + override fun canOverrideExistingModule(): Boolean = false + + override fun invalidate() { + mHybridData.resetNative() + } + + // Replace the current native module held by this wrapper by a new instance + protected fun resetModule(hd: HybridData) { + if (hd !== mHybridData) { + mHybridData.resetNative() + mHybridData = hd + } + } + + private companion object { + init { + ReactBridge.staticInit() + LegacyArchitectureLogger.assertWhenLegacyArchitectureMinifyingEnabled( + "CxxModuleWrapperBase", LegacyArchitectureLogLevel.WARNING) + } + } +}