From d0bb396ddb0c738524099b034276e0c3fb031347 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 15 May 2024 02:03:46 -0700 Subject: [PATCH] Shortcut emitDeviceEvent in bridgeless (#44574) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44574 `emitDeviceEvent` is frequently used for perf-critical operations such as sending network responses from native to JS. We don't need to go through JavaScriptModule Proxy (which is missing caching in bridgeless) and instead can immediately invoke the callable JS module. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D57329165 fbshipit-source-id: 6506a7afb522b672a1f3dc7d348c9b80e6734225 --- .../facebook/react/runtime/BridgelessReactContext.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.java index 97a1bedabef657..739555e2f7bca7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.java @@ -134,6 +134,8 @@ public T getJSModule(Class jsInterface) { && mInteropModuleRegistry.shouldReturnInteropModule(jsInterface)) { return mInteropModuleRegistry.getInteropModule(jsInterface); } + + // TODO T189052462: ReactContext caches JavaScriptModule instances JavaScriptModule interfaceProxy = (JavaScriptModule) Proxy.newProxyInstance( @@ -143,6 +145,13 @@ public T getJSModule(Class jsInterface) { return (T) interfaceProxy; } + /** Shortcut RCTDeviceEventEmitter.emit since it's frequently used */ + @Override + public void emitDeviceEvent(String eventName, @Nullable Object args) { + mReactHost.callFunctionOnModule( + "RCTDeviceEventEmitter", "emit", Arguments.fromJavaArgs(new Object[] {args})); + } + @Override public boolean hasNativeModule(Class nativeModuleInterface) { return mReactHost.hasNativeModule(nativeModuleInterface);