mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support emitting typed RCTDeviceEmitter events
Summary: This enables to code-gen base C++ types for custom exported JS types from a RN TM spec - which have been previously excluded from code-gen as these aren't used in any function. The only work around so far was to ‘register’ a random function using the custom type which should be used for RCTDeviceEventEmitter events Changelog: [Internal] Reviewed By: rshest Differential Revision: D56685903 fbshipit-source-id: add9ca40018b91c9fca98609ba3d1f85d3affec1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cfbee0b7ec
commit
c96c893374
@@ -180,15 +180,18 @@ void NativeCxxModuleExample::setMenu(jsi::Runtime& rt, MenuItem menuItem) {
|
||||
|
||||
void NativeCxxModuleExample::emitCustomDeviceEvent(
|
||||
jsi::Runtime& rt,
|
||||
jsi::String eventName) {
|
||||
const std::string& eventName) {
|
||||
// Test emitting device events (RCTDeviceEventEmitter.emit) from C++
|
||||
// TurboModule with arbitrary arguments
|
||||
// TurboModule with arbitrary arguments. This can be called from any thread
|
||||
emitDeviceEvent(
|
||||
eventName.utf8(rt).c_str(),
|
||||
[](jsi::Runtime& rt, std::vector<jsi::Value>& args) {
|
||||
eventName,
|
||||
[jsInvoker = jsInvoker_](
|
||||
jsi::Runtime& rt, std::vector<jsi::Value>& args) {
|
||||
args.emplace_back(jsi::Value(true));
|
||||
args.emplace_back(jsi::Value(42));
|
||||
args.emplace_back(jsi::String::createFromAscii(rt, "stringArg"));
|
||||
args.emplace_back(bridging::toJs(
|
||||
rt, CustomDeviceEvent{"one", 2, std::nullopt}, jsInvoker));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user