Skip to content

Commit

Permalink
Add getNativeModule(String) to ReactContext interface (#44851)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44851

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

Reviewed By: cortinico

Differential Revision: D58355135

fbshipit-source-id: 0cc76bb2da2b49510dc626cb8b3a3e93db5a16b0
  • Loading branch information
javache authored and facebook-github-bot committed Jun 10, 2024
1 parent e94852f commit fdb2427
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public class com/facebook/react/bridge/BridgeReactContext : com/facebook/react/b
public fun getJSCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/CallInvokerHolder;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModule (Ljava/lang/String;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModules ()Ljava/util/Collection;
public fun getSourceURL ()Ljava/lang/String;
public fun handleException (Ljava/lang/Exception;)V
Expand Down Expand Up @@ -1106,6 +1107,7 @@ public abstract class com/facebook/react/bridge/ReactContext : android/content/C
public abstract fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getLifecycleState ()Lcom/facebook/react/common/LifecycleState;
public abstract fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public abstract fun getNativeModule (Ljava/lang/String;)Lcom/facebook/react/bridge/NativeModule;
public abstract fun getNativeModules ()Ljava/util/Collection;
public fun getNativeModulesMessageQueueThread ()Lcom/facebook/react/bridge/queue/MessageQueueThread;
public abstract fun getSourceURL ()Ljava/lang/String;
Expand Down Expand Up @@ -4968,6 +4970,7 @@ public class com/facebook/react/uimanager/ThemedReactContext : com/facebook/reac
public fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getModuleName ()Ljava/lang/String;
public fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModule (Ljava/lang/String;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModules ()Ljava/util/Collection;
public fun getReactApplicationContext ()Lcom/facebook/react/bridge/ReactApplicationContext;
public fun getSourceURL ()Ljava/lang/String;
Expand Down
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 fdb2427

Please sign in to comment.