From e56ec0364418852bcd827ab20321608a98e8f7ed Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Thu, 7 Mar 2024 16:10:27 -0800 Subject: [PATCH] TurboModule::emitDeviceEvent doesn't require jsi::Runtime argument anymore (#43376) Summary: ## Changelog: [Internal] - Make it possible to call `emitDeviceEvent` from C++ TurboModules without the need to explicitly provide the reference to `jsi::Runtime`, as in some contexts (when we call e.g. not from the JS thread itself) it may be hard to get hold of. Reviewed By: rubennorte Differential Revision: D54643903 --- .../react/nativemodule/core/ReactCommon/TurboModule.cpp | 1 - .../react/nativemodule/core/ReactCommon/TurboModule.h | 9 ++++++++- .../NativeCxxModuleExample/NativeCxxModuleExample.cpp | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp index cf165e30e1215f..fe2411974d20cd 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp @@ -40,7 +40,6 @@ TurboModule::TurboModule( : name_(std::move(name)), jsInvoker_(std::move(jsInvoker)) {} void TurboModule::emitDeviceEvent( - jsi::Runtime& runtime, const std::string& eventName, ArgFactory argFactory) { jsInvoker_->invokeAsync([eventName, argFactory](jsi::Runtime& rt) { diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h index ccd9d1f85968ef..08f4fdbc5cef75 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h @@ -106,10 +106,17 @@ class JSI_EXPORT TurboModule : public facebook::jsi::HostObject { * }); */ void emitDeviceEvent( - jsi::Runtime& runtime, const std::string& eventName, ArgFactory argFactory = nullptr); + // Backwards compatibility version + void emitDeviceEvent( + jsi::Runtime& /*runtime*/, + const std::string& eventName, + ArgFactory argFactory = nullptr) { + emitDeviceEvent(eventName, std::move(argFactory)); + } + virtual jsi::Value create( jsi::Runtime& runtime, const jsi::PropNameID& propName) { diff --git a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp index abec005d02e00b..0bbc831d838156 100644 --- a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp +++ b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp @@ -184,7 +184,6 @@ void NativeCxxModuleExample::emitCustomDeviceEvent( // Test emitting device events (RCTDeviceEventEmitter.emit) from C++ // TurboModule with arbitrary arguments emitDeviceEvent( - rt, eventName.utf8(rt).c_str(), [](jsi::Runtime& rt, std::vector& args) { args.emplace_back(jsi::Value(true));