mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Stable API - Make InteropModuleRegistry internal (#47374)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47374 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 Reviewed By: javache Differential Revision: D65421965 fbshipit-source-id: 207be5379ebe3a31530cfea75b4623787f5ae7cf
This commit is contained in:
1 parent
44f2a08371
commit
cba1d4bae7
5 files changed
+52
-65
No files matched your search
@@ -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
|
||||
|
||||
+2
@@ -63,6 +63,8 @@ public abstract class ReactContext extends ContextWrapper {
|
||||
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;
|
||||
|
||||
|
||||
-57
@@ -1,57 +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.interop;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A utility class that takes care of returning {@link JavaScriptModule} which are used for the
|
||||
* Fabric Interop Layer. This allows us to override the returned classes once the user is invoking
|
||||
* `ReactContext.getJsModule()`.
|
||||
*
|
||||
* <p>Currently we only support a `RCTEventEmitter` re-implementation, being `InteropEventEmitter`
|
||||
* but this class can support other re-implementation in the future.
|
||||
*/
|
||||
public class InteropModuleRegistry {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final HashMap<Class, Object> supportedModules;
|
||||
|
||||
public InteropModuleRegistry() {
|
||||
supportedModules = new HashMap<>();
|
||||
}
|
||||
|
||||
public <T extends JavaScriptModule> boolean shouldReturnInteropModule(Class<T> requestedModule) {
|
||||
return checkReactFeatureFlagsConditions() && supportedModules.containsKey(requestedModule);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends JavaScriptModule> T getInteropModule(Class<T> requestedModule) {
|
||||
if (checkReactFeatureFlagsConditions()) {
|
||||
//noinspection unchecked
|
||||
return (T) supportedModules.get(requestedModule);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends JavaScriptModule> void registerInteropModule(
|
||||
Class<T> interopModuleInterface, Object interopModule) {
|
||||
if (checkReactFeatureFlagsConditions()) {
|
||||
supportedModules.put(interopModuleInterface, interopModule);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkReactFeatureFlagsConditions() {
|
||||
return ReactNativeFeatureFlags.enableFabricRenderer()
|
||||
&& ReactNativeFeatureFlags.useFabricInterop();
|
||||
}
|
||||
}
|
||||
+49
@@ -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()
|
||||
}
|
||||
+1
-1
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user