Skip to content

Commit

Permalink
Stable API - Make InteropModuleRegistry internal
Browse files Browse the repository at this point in the history
Summary:
I've converted this class to Kotlin + made it `internal` as it should not be exposed publicly.
This class is part of the iterop layer for the New Architecture.
Marked as breaking but I expect no meaningful breakages here.

Changelog:
[Android] [Breaking] - Stable API - Make InteropModuleRegistry internal

Differential Revision: D65421965
  • Loading branch information
cortinico authored and facebook-github-bot committed Nov 4, 2024
1 parent e1a1cea commit 3863629
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 65 deletions.
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,47 @@
/*
* 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

0 comments on commit 3863629

Please sign in to comment.