mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Implement callFunctionOnModule on BridgelessCatalystInstance (#56804)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56804 Implement `BridgelessCatalystInstance.callFunction` using the existing `ReactHostImpl.callFunctionOnModule` so callers that go through `CatalystInstance` (rather than directly through `JavaScriptModule` proxies) work in bridgeless mode. While here, propagate nullability of `args` through the call chain. `InvocationHandler.invoke` is documented to pass `null` when the proxied method has no parameters, and the existing `Arguments.fromJavaArgs(args)` would NPE in that case. The JNI layer substitutes an empty `folly::dynamic::array()` when `args` is null, so the JS call still has a well-formed argument list. Changelog: [Android][Fixed] JSModule method without args are correctly dispatched Reviewed By: mdvacca Differential Revision: D104901132 fbshipit-source-id: 4092bce9327a3d1991936076a9cb1df05d189a85
This commit is contained in:
1 parent
8dfd54838e
commit
949b8049df
5 files changed
+9
-7
No files matched your search
+1
-1
@@ -77,7 +77,7 @@ internal class BridgelessCatalystInstance(private val reactHost: ReactHostImpl)
|
||||
}
|
||||
|
||||
override fun callFunction(module: String, method: String, arguments: NativeArray?) {
|
||||
throw UnsupportedOperationException("Unimplemented method 'callFunction'")
|
||||
reactHost.callFunctionOnModule(module, method, arguments)
|
||||
}
|
||||
|
||||
override fun destroy() {
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@ import com.facebook.react.bridge.CatalystInstance
|
||||
import com.facebook.react.bridge.JavaScriptContextHolder
|
||||
import com.facebook.react.bridge.JavaScriptModule
|
||||
import com.facebook.react.bridge.JavaScriptModuleRegistry
|
||||
import com.facebook.react.bridge.NativeArray
|
||||
import com.facebook.react.bridge.NativeModule
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.facebook.react.bridge.ReactSoftExceptionLogger.logSoftException
|
||||
@@ -117,8 +116,8 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R
|
||||
private val reactHost: ReactHostImpl,
|
||||
private val jsModuleInterface: Class<out JavaScriptModule>,
|
||||
) : InvocationHandler {
|
||||
override fun invoke(proxy: Any, method: Method, args: Array<Any?>): Any? {
|
||||
val jsArgs: NativeArray = Arguments.fromJavaArgs(args)
|
||||
override fun invoke(proxy: Any, method: Method, args: Array<Any?>?): Any? {
|
||||
val jsArgs = if (args != null) Arguments.fromJavaArgs(args) else null
|
||||
reactHost.callFunctionOnModule(
|
||||
JavaScriptModuleRegistry.getJSModuleName(jsModuleInterface),
|
||||
method.name,
|
||||
|
||||
+1
-1
@@ -806,7 +806,7 @@ public class ReactHostImpl(
|
||||
internal fun callFunctionOnModule(
|
||||
moduleName: String,
|
||||
methodName: String,
|
||||
args: NativeArray,
|
||||
args: NativeArray?,
|
||||
): Task<Boolean> {
|
||||
val method = "callFunctionOnModule(\"$moduleName\", \"$methodName\")"
|
||||
return callWithExistingReactInstance(method) { reactInstance: ReactInstance ->
|
||||
|
||||
+1
-1
@@ -462,7 +462,7 @@ internal class ReactInstance(
|
||||
|
||||
private external fun getJavaScriptContext(): Long
|
||||
|
||||
external fun callFunctionOnModule(moduleName: String, methodName: String, args: NativeArray)
|
||||
external fun callFunctionOnModule(moduleName: String, methodName: String, args: NativeArray?)
|
||||
|
||||
private external fun registerSegmentNative(segmentId: Int, segmentPath: String)
|
||||
|
||||
|
||||
+4
-1
@@ -173,7 +173,10 @@ void JReactInstance::callFunctionOnModule(
|
||||
const std::string& moduleName,
|
||||
const std::string& methodName,
|
||||
NativeArray* args) {
|
||||
instance_->callFunctionOnModule(moduleName, methodName, args->consume());
|
||||
instance_->callFunctionOnModule(
|
||||
moduleName,
|
||||
methodName,
|
||||
args != nullptr ? args->consume() : folly::dynamic::array());
|
||||
}
|
||||
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject>
|
||||
|
||||
Reference in new issue
Block a user