forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stable API - Make InteropModuleRegistry internal
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
1 parent
e1a1cea
commit 3863629
Showing
5 changed files
with
50 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
...e/ReactAndroid/src/main/java/com/facebook/react/bridge/interop/InteropModuleRegistry.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...ive/ReactAndroid/src/main/java/com/facebook/react/bridge/interop/InteropModuleRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters