Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1644,13 +1644,6 @@ public final class com/facebook/react/bridge/WritableNativeMap : com/facebook/re
public fun putString (Ljava/lang/String;Ljava/lang/String;)V
}

public class com/facebook/react/bridge/interop/InteropModuleRegistry {
public fun <init> ()V
public fun getInteropModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun registerInteropModule (Ljava/lang/Class;Ljava/lang/Object;)V
public fun shouldReturnInteropModule (Ljava/lang/Class;)Z
}

public abstract interface class com/facebook/react/bridge/queue/MessageQueueThread {
public abstract fun assertIsOnThread ()V
public abstract fun assertIsOnThread (Ljava/lang/String;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public interface RCTDeviceEventEmitter extends JavaScriptModule {
private @Nullable JSExceptionHandler mExceptionHandlerWrapper;
private @Nullable WeakReference<Activity> mCurrentActivity;

// NOTE: When converted to Kotlin, this field should be made internal due to
// visibility restriction on InteropModuleRegistry otherwise it will be exposed to the public API.
protected @Nullable InteropModuleRegistry mInteropModuleRegistry;
private boolean mIsInitialized = false;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.interop

import com.facebook.react.bridge.JavaScriptModule
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags.enableFabricRenderer
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags.useFabricInterop

/**
* A utility class that takes care of returning [JavaScriptModule] which are used for the Fabric
* Interop Layer. This allows us to override the returned classes once the user is invoking
* `ReactContext.getJsModule()`.
*
* Currently we only support a `RCTEventEmitter` re-implementation, being `InteropEventEmitter` but
* this class can support other re-implementation in the future.
*/
internal class InteropModuleRegistry {
private val supportedModules = mutableMapOf<Class<*>, Any?>()

fun <T : JavaScriptModule?> shouldReturnInteropModule(requestedModule: Class<T>): Boolean {
return checkReactFeatureFlagsConditions() && supportedModules.containsKey(requestedModule)
}

fun <T : JavaScriptModule?> getInteropModule(requestedModule: Class<T>): T? {
return if (checkReactFeatureFlagsConditions()) {
@Suppress("UNCHECKED_CAST")
supportedModules[requestedModule] as? T?
} else {
null
}
}

fun <T : JavaScriptModule?> registerInteropModule(
interopModuleInterface: Class<T>,
interopModule: Any
) {
if (checkReactFeatureFlagsConditions()) {
supportedModules[interopModuleInterface] = interopModule
}
}

private fun checkReactFeatureFlagsConditions(): Boolean =
enableFabricRenderer() && useFabricInterop()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.junit.Test
@OptIn(UnstableReactNativeAPI::class)
class InteropModuleRegistryTest {

lateinit var underTest: InteropModuleRegistry
private lateinit var underTest: InteropModuleRegistry

@Before
fun setup() {
Expand Down