diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js index 8e0b0fc5d7c..6d8471c4598 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/EventNestedObjectPropsNativeComponent.js @@ -23,6 +23,7 @@ type OnChangeEvent = $ReadOnly<{| source: {url: string, ...}, x: Int32, y: Int32, + arrayOfObjects: $ReadOnlyArray<{value: $ReadOnly<{str: string}>}>, ... }, |}>; diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterCpp-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterCpp-test.js.snap index a53541759bf..cd64459983a 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterCpp-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterCpp-test.js.snap @@ -161,6 +161,20 @@ void EventNestedObjectPropsNativeComponentViewEventEmitter::onChange(OnChange $e } location.setProperty(runtime, \\"x\\", $event.location.x); location.setProperty(runtime, \\"y\\", $event.location.y); + + auto arrayOfObjects = jsi::Array(runtime, $event.location.arrayOfObjects.size()); + size_t arrayOfObjectsIndex = 0; + for (auto arrayOfObjectsValue : $event.location.arrayOfObjects) { + auto arrayOfObjectsObject = jsi::Object(runtime); + { + auto value = jsi::Object(runtime); + value.setProperty(runtime, \\"str\\", arrayOfObjectsValue.value.str); + arrayOfObjectsObject.setProperty(runtime, \\"value\\", value); + } + arrayOfObjects.setValueAtIndex(runtime, arrayOfObjectsIndex++, arrayOfObjectsObject); + } + location.setProperty(runtime, \\"arrayOfObjects\\", arrayOfObjects); + $payload.setProperty(runtime, \\"location\\", location); } return $payload; diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap index 9ae54de91b3..d44312f48b6 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -199,10 +199,19 @@ class EventNestedObjectPropsNativeComponentViewEventEmitter : public ViewEventEm std::string url; }; + struct OnChangeLocationArrayOfObjectsValue { + std::string str; + }; + + struct OnChangeLocationArrayOfObjects { + OnChangeLocationArrayOfObjectsValue value; + }; + struct OnChangeLocation { OnChangeLocationSource source; int x; int y; + std::vector arrayOfObjects; }; struct OnChange { diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js index 2f2a829d199..d6fbdbaa952 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterCpp.js @@ -104,7 +104,7 @@ function generateSetter( ) { const eventChain = usingEvent ? `$event.${[...propertyParts, propertyName].join('.')}` - : [propertyParts, propertyName].join('.'); + : [...propertyParts, propertyName].join('.'); return `${variableName}.setProperty(runtime, "${propertyName}", ${valueMapper( eventChain, )});`; @@ -157,7 +157,7 @@ function generateArraySetter( ): string { const eventChain = usingEvent ? `$event.${[...propertyParts, propertyName].join('.')}` - : [propertyParts, propertyName].join('.'); + : [...propertyParts, propertyName].join('.'); const indexVar = `${propertyName}Index`; const innerLoopVar = `${propertyName}Value`; return `