Skip to content

Commit

Permalink
Introduce ReactContext.getNativeModules()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Apr 2, 2022
1 parent 6e0fa5f commit b978308
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArraySet;

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

public Collection<NativeModule> getNativeModules() {
if (mCatalystInstance == null) {
raiseCatalystInstanceMissingException();
}
return mCatalystInstance.getNativeModules();
}

/** @return the instance of the specified module interface associated with this ReactContext. */
@Nullable
public <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface) {
Expand Down

0 comments on commit b978308

Please sign in to comment.