diff --git a/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js b/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js index 41a0d8a0fe4ce3..6950facf30caac 100644 --- a/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js +++ b/packages/react-native-codegen/e2e/__test_fixtures__/components/ArrayPropsNativeComponent.js @@ -37,6 +37,7 @@ type NativeProps = $ReadOnly<{| edgeInsets?: $ReadOnlyArray, sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>, object?: $ReadOnlyArray<$ReadOnly<{|prop: string|}>>, + arrayOfObjects?: $ReadOnlyArray<$ReadOnly<{|prop1: Float, prop2: Int32|}>>, |}>; export default (codegenNativeComponent( diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap index 8afd336efd2145..2a2b40668eda52 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap @@ -34,7 +34,8 @@ ArrayPropsNativeComponentViewProps::ArrayPropsNativeComponentViewProps( points(convertRawProp(context, rawProps, \\"points\\", sourceProps.points, {})), edgeInsets(convertRawProp(context, rawProps, \\"edgeInsets\\", sourceProps.edgeInsets, {})), sizes(convertRawProp(context, rawProps, \\"sizes\\", sourceProps.sizes, {static_cast(ArrayPropsNativeComponentViewSizes::Small)})), - object(convertRawProp(context, rawProps, \\"object\\", sourceProps.object, {})) + object(convertRawProp(context, rawProps, \\"object\\", sourceProps.object, {})), + arrayOfObjects(convertRawProp(context, rawProps, \\"arrayOfObjects\\", sourceProps.arrayOfObjects, {})) {} } // namespace react diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap index 4e8ff5866b2a8d..ff2d1cb247ed22 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap @@ -17,6 +17,7 @@ Object { #include #include #include +#include #include #include #include @@ -107,6 +108,38 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } + +struct ArrayPropsNativeComponentViewArrayOfObjectsStruct { + Float prop1; + int prop2; +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentViewArrayOfObjectsStruct &result) { + auto map = (butter::map)value; + + auto tmp_prop1 = map.find(\\"prop1\\"); + if (tmp_prop1 != map.end()) { + fromRawValue(context, tmp_prop1->second, result.prop1); + } + auto tmp_prop2 = map.find(\\"prop2\\"); + if (tmp_prop2 != map.end()) { + fromRawValue(context, tmp_prop2->second, result.prop2); + } +} + +static inline std::string toString(const ArrayPropsNativeComponentViewArrayOfObjectsStruct &value) { + return \\"[Object ArrayPropsNativeComponentViewArrayOfObjectsStruct]\\"; +} + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + ArrayPropsNativeComponentViewArrayOfObjectsStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + class JSI_EXPORT ArrayPropsNativeComponentViewProps final : public ViewProps { public: ArrayPropsNativeComponentViewProps() = default; @@ -124,6 +157,7 @@ class JSI_EXPORT ArrayPropsNativeComponentViewProps final : public ViewProps { std::vector edgeInsets{}; ArrayPropsNativeComponentViewSizesMask sizes{static_cast(ArrayPropsNativeComponentViewSizes::Small)}; std::vector object{}; + std::vector arrayOfObjects{}; }; } // namespace react diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsJavaDelegate-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsJavaDelegate-test.js.snap index 76fcd1483bd35f..ffa50ec492fe29 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsJavaDelegate-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsJavaDelegate-test.js.snap @@ -56,6 +56,9 @@ public class ArrayPropsNativeComponentViewManagerDelegate { void setEdgeInsets(T view, @Nullable ReadableArray value); void setSizes(T view, @Nullable ReadableArray value); void setObject(T view, @Nullable ReadableArray value); + void setArrayOfObjects(T view, @Nullable ReadableArray value); } ", } diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap index adbbe7a81aeb31..02e2c32048bafe 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -39,6 +39,7 @@ export const __INTERNAL_VIEW_CONFIG = { edgeInsets: true, sizes: true, object: true, + arrayOfObjects: true, }, }; diff --git a/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js b/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js index 22755be313d908..0f280f8ee1811f 100644 --- a/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js +++ b/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js @@ -270,8 +270,11 @@ function getLocalImports( typeAnnotation.type === 'ArrayTypeAnnotation' && typeAnnotation.elementType.type === 'ObjectTypeAnnotation' ) { + imports.add('#include '); const objectProps = typeAnnotation.elementType.properties; + // $FlowFixMe[incompatible-call] the type is guaranteed to be ObjectTypeAnnotation const objectImports = getImports(objectProps); + // $FlowFixMe[incompatible-call] the type is guaranteed to be ObjectTypeAnnotation const localImports = getLocalImports(objectProps); // $FlowFixMe[method-unbinding] added when improving typing for this parameters objectImports.forEach(imports.add, imports); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap index 621f2e95fa8eca..a1877816d08c19 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap @@ -17,6 +17,7 @@ Map { #include #include #include +#include #include #include #include @@ -234,6 +235,7 @@ Map { #include #include #include +#include #include #include #include