diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index 5d0fff680ee..cae56f30050 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -407,14 +407,16 @@ function generateEnumString(componentName: string, component): string { } if (prop.typeAnnotation.type === 'ObjectTypeAnnotation') { - // TODO: Int32 Enums return prop.typeAnnotation.properties - .filter( - property => - property.typeAnnotation.type === 'StringEnumTypeAnnotation', - ) .map(property => { - return generateStringEnum(componentName, property); + if (property.typeAnnotation.type === 'StringEnumTypeAnnotation') { + return generateStringEnum(componentName, property); + } else if ( + property.typeAnnotation.type === 'Int32EnumTypeAnnotation' + ) { + return generateIntEnum(componentName, property); + } + return null; }) .filter(Boolean) .join('\n'); diff --git a/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js index fb266ec03fb..fff75aa497e 100644 --- a/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/generators/components/__test_fixtures__/fixtures.js @@ -777,6 +777,19 @@ const OBJECT_PROPS: SchemaType = { ], }, }, + { + name: 'intEnumProp', + optional: true, + typeAnnotation: { + type: 'Int32EnumTypeAnnotation', + default: 0, + options: [ + { + value: 0, + }, + ], + }, + }, { name: 'objectArrayProp', optional: false, 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 e8d8e92b493..0af5c6986eb 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 @@ -816,6 +816,24 @@ static inline std::string toString(const ObjectPropsStringEnumProp &value) { case ObjectPropsStringEnumProp::Option1: return \\"option1\\"; } } +enum class ObjectPropsIntEnumProp { IntEnumProp0 = 0 }; + +static inline void fromRawValue(const RawValue &value, ObjectPropsIntEnumProp &result) { + assert(value.hasType()); + auto integerValue = (int)value; + switch (integerValue) { + case 0: + result = ObjectPropsIntEnumProp::IntEnumProp0; + return; + } + abort(); +} + +static inline std::string toString(const ObjectPropsIntEnumProp &value) { + switch (value) { + case ObjectPropsIntEnumProp::IntEnumProp0: return \\"0\\"; + } +} struct ObjectPropsObjectPropObjectArrayPropStruct { std::vector array; }; @@ -944,6 +962,7 @@ struct ObjectPropsObjectPropStruct { Float floatProp; int intProp; ObjectPropsStringEnumProp stringEnumProp; + ObjectPropsIntEnumProp intEnumProp; ObjectPropsObjectPropObjectArrayPropStruct objectArrayProp; ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct objectPrimitiveRequiredProp; ObjectPropsObjectPropNestedPropAStruct nestedPropA; @@ -973,6 +992,10 @@ static inline void fromRawValue(const RawValue &value, ObjectPropsObjectPropStru if (stringEnumProp != map.end()) { fromRawValue(stringEnumProp->second, result.stringEnumProp); } + auto intEnumProp = map.find(\\"intEnumProp\\"); + if (intEnumProp != map.end()) { + fromRawValue(intEnumProp->second, result.intEnumProp); + } auto objectArrayProp = map.find(\\"objectArrayProp\\"); if (objectArrayProp != map.end()) { fromRawValue(objectArrayProp->second, result.objectArrayProp);