Skip to content

Commit b978308

Browse files
RSNarafacebook-github-bot
authored andcommitted
Introduce ReactContext.getNativeModules()
Summary: ## Rationale The CatalystInstance exposes a public API that returns a list of all instantiated NativeModules: [CatalystInstance.getNativeModules()](https://www.internalfb.com/code/fbsource/[d9cd2e5dd41fc3e3022bfb777c8b31c92af8c537]/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java?lines=73). This enables a use-case: process all NativeModules that conform to a particular interface, to, for example, remove sensitive data before logging out. ## Changes This diff moves that CatalystInstance.getNativeModules() API into the ReactContext. This allows us to migrate NativeModules leveraging this use-case off of ReactContext.getCatalystInstance(), which makes them bridgeless-mode compatible. Changelog: [Android][Added] Introduce ReactContext.getNativeModules() Reviewed By: sshic Differential Revision: D35286940 fbshipit-source-id: 1b64351aa3f65ee59e6438a7a95974e219ccc69c
1 parent 6e0fa5f commit b978308

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.facebook.react.common.LifecycleState;
2525
import com.facebook.react.common.ReactConstants;
2626
import java.lang.ref.WeakReference;
27+
import java.util.Collection;
2728
import java.util.concurrent.CopyOnWriteArraySet;
2829

2930
/**
@@ -167,6 +168,13 @@ public <T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInt
167168
return mCatalystInstance.hasNativeModule(nativeModuleInterface);
168169
}
169170

171+
public Collection<NativeModule> getNativeModules() {
172+
if (mCatalystInstance == null) {
173+
raiseCatalystInstanceMissingException();
174+
}
175+
return mCatalystInstance.getNativeModules();
176+
}
177+
170178
/** @return the instance of the specified module interface associated with this ReactContext. */
171179
@Nullable
172180
public <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface) {

0 commit comments

Comments
 (0)