-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 (#47374)
Summary: Pull Request resolved: #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
- Loading branch information
1 parent
44f2a08
commit cba1d4b
Showing
5 changed files
with
52 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.
49 changes: 49 additions & 0 deletions
49
...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,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() | ||
} |
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