Skip to content

Commit

Permalink
Add getNativeModule(String) to ReactContext interface
Browse files Browse the repository at this point in the history
Summary:
This method is available on the (deprecated) CatalystInstance interface, but not on ReactContext, even though it is trivially supported.

Changelog: [Android][Added] - Added getNativeModule(name) to ReactContext

Differential Revision: D58355135
  • Loading branch information
javache authored and facebook-github-bot committed Jun 10, 2024
1 parent 6937c70 commit 6903fb0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ public <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface
return mCatalystInstance.getNativeModule(nativeModuleInterface);
}

@Override
public @Nullable NativeModule getNativeModule(String moduleName) {
if (mCatalystInstance == null) {
raiseCatalystInstanceMissingException();
}
return mCatalystInstance.getNativeModule(moduleName);
}

@Override
public CatalystInstance getCatalystInstance() {
return Assertions.assertNotNull(mCatalystInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ public Object getSystemService(String name) {
@Nullable
public abstract <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface);

/**
* @return the instance of the specified module interface associated with this ReactContext.
*/
public abstract @Nullable NativeModule getNativeModule(String moduleName);

/**
* Calls RCTDeviceEventEmitter.emit to JavaScript, with given event name and an optional list of
* arguments.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public Collection<NativeModule> getNativeModules() {
return mReactHost.getNativeModule(nativeModuleInterface);
}

@Override
public @Nullable NativeModule getNativeModule(String name) {
return mReactHost.getNativeModule(name);
}

@Override
@FrameworkAPI
@UnstableReactNativeAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface
return mReactApplicationContext.getNativeModule(nativeModuleInterface);
}

@Nullable
@Override
public NativeModule getNativeModule(String moduleName) {
return mReactApplicationContext.getNativeModule(moduleName);
}

@Override
public CatalystInstance getCatalystInstance() {
return mReactApplicationContext.getCatalystInstance();
Expand Down

0 comments on commit 6903fb0

Please sign in to comment.