Skip to content

Commit cc1c697

Browse files
javachecipolleschi
authored andcommitted
Support more stubbed methods in BridgelessCatalystInstance (#44091)
Summary: Pull Request resolved: #44091 These can be stubbed easily using existing ReactHostImpl/ReactInstance API's Changelog: [Internal] Reviewed By: cortinico Differential Revision: D56139806 fbshipit-source-id: cefabe3aa0fb6556f8e296243ff233df07ddffee
1 parent 58b1f9b commit cc1c697

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessCatalystInstance.kt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,20 @@ public class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) :
9292
throw UnsupportedOperationException("Unimplemented method 'initialize'")
9393
}
9494

95-
override fun getReactQueueConfiguration(): ReactQueueConfiguration {
96-
throw UnsupportedOperationException("Unimplemented method 'getReactQueueConfiguration'")
97-
}
95+
override fun getReactQueueConfiguration(): ReactQueueConfiguration =
96+
reactHost.reactQueueConfiguration!!
9897

99-
override fun <T : JavaScriptModule> getJSModule(jsInterface: Class<T>): T {
100-
throw UnsupportedOperationException("Unimplemented method 'getJSModule'")
101-
}
98+
override fun <T : JavaScriptModule> getJSModule(jsInterface: Class<T>): T =
99+
reactHost.currentReactContext?.getJSModule(jsInterface)!!
102100

103-
override fun <T : NativeModule> hasNativeModule(nativeModuleInterface: Class<T>): Boolean {
104-
throw UnsupportedOperationException("Unimplemented method 'hasNativeModule'")
105-
}
101+
override fun <T : NativeModule> hasNativeModule(nativeModuleInterface: Class<T>): Boolean =
102+
reactHost.hasNativeModule(nativeModuleInterface)
106103

107-
override fun <T : NativeModule> getNativeModule(nativeModuleInterface: Class<T>): T? {
108-
throw UnsupportedOperationException("Unimplemented method 'getNativeModule'")
109-
}
104+
override fun <T : NativeModule> getNativeModule(nativeModuleInterface: Class<T>): T? =
105+
reactHost.getNativeModule(nativeModuleInterface)
110106

111-
override fun getNativeModule(moduleName: String): NativeModule? {
112-
throw UnsupportedOperationException("Unimplemented method 'getNativeModule'")
113-
}
107+
override fun getNativeModule(moduleName: String): NativeModule? =
108+
reactHost.getNativeModule(moduleName)
114109

115110
@Deprecated(
116111
message =
@@ -119,9 +114,7 @@ public class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) :
119114
throw UnsupportedOperationException("Unimplemented method 'getJSIModule'")
120115
}
121116

122-
override fun getNativeModules(): Collection<NativeModule> {
123-
throw UnsupportedOperationException("Unimplemented method 'getNativeModules'")
124-
}
117+
override fun getNativeModules(): Collection<NativeModule> = reactHost.getNativeModules()
125118

126119
override fun extendNativeModules(modules: NativeModuleRegistry) {
127120
throw UnsupportedOperationException("Unimplemented method 'extendNativeModules'")

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,16 @@ <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface) {
592592
return null;
593593
}
594594

595+
/* package */
596+
@Nullable
597+
NativeModule getNativeModule(String nativeModuleName) {
598+
final ReactInstance reactInstance = mReactInstanceTaskRef.get().getResult();
599+
if (reactInstance != null) {
600+
return reactInstance.getNativeModule(nativeModuleName);
601+
}
602+
return null;
603+
}
604+
595605
/* package */
596606
@Nullable
597607
RuntimeExecutor getRuntimeExecutor() {

0 commit comments

Comments
 (0)