Migrate CxxModuleWrapperBase to Kotlin (#50251)

Summary:
Migrate com.facebook.react.bridge.CxxModuleWrapperBase to Kotlin.

## Changelog:

[INTERNAL] - Migrate com.facebook.react.bridge.CxxModuleWrapperBase to Kotlin

Pull Request resolved: https://github.com/facebook/react-native/pull/50251

Test Plan:
```bash
yarn test-android
yarn android
```

Reviewed By: alanleedev

Differential Revision: D71830747

Pulled By: arushikesarwani94

fbshipit-source-id: 174dff86f6d1ad8228491c15e226986dad2edb1b
This commit is contained in:
Mateo Guzmán
2025-03-26 20:35:13 -07:00
committed by Facebook GitHub Bot
parent 4a7946bef5
commit d49ec1d79c
3 changed files with 57 additions and 64 deletions
@@ -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 {
@@ -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
*
* <p>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;
}
}
}
@@ -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)
}
}
}