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 6be534fee9e..f061b59c9ed 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 @@ -1916,502 +1916,6 @@ const EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES: SchemaType = { }, }; -const ARRAY_PROPS_WITH_OPTIONAL_GEN: SchemaType = { - modules: { - Slider: { - type: 'Component', - components: { - ArrayPropsNativeComponent: { - generateOptionalProperties: true, - extendsProps: [ - { - type: 'ReactNativeBuiltInType', - knownTypeName: 'ReactNativeCoreViewProps', - }, - ], - events: [], - props: [ - { - name: 'names', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'StringTypeAnnotation', - }, - }, - }, - { - name: 'disableds', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'BooleanTypeAnnotation', - }, - }, - }, - { - name: 'progress', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'Int32TypeAnnotation', - }, - }, - }, - { - name: 'radii', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'FloatTypeAnnotation', - }, - }, - }, - { - name: 'colors', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'ColorPrimitive', - }, - }, - }, - { - name: 'srcs', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'ImageSourcePrimitive', - }, - }, - }, - { - name: 'points', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'PointPrimitive', - }, - }, - }, - { - name: 'dimensions', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'DimensionPrimitive', - }, - }, - }, - { - name: 'sizes', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'StringEnumTypeAnnotation', - default: 'small', - options: ['small', 'large'], - }, - }, - }, - { - name: 'object', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'stringProp', - optional: true, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: '', - }, - }, - ], - }, - }, - }, - { - name: 'array', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ObjectTypeAnnotation', - properties: [ - { - // This needs to stay the same as the object above - // to confirm that the structs are generated - // with unique non-colliding names - name: 'object', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'stringProp', - optional: true, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: '', - }, - }, - ], - }, - }, - }, - ], - }, - }, - }, - { - name: 'arrayOfArrayOfObject', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'stringProp', - optional: true, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: '', - }, - }, - ], - }, - }, - }, - }, - { - name: 'arrayOfMixed', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'MixedTypeAnnotation', - }, - }, - }, - ], - commands: [], - }, - }, - }, - }, -}; - -const ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN: SchemaType = { - modules: { - Slider: { - type: 'Component', - components: { - ArrayPropsNativeComponent: { - generateOptionalProperties: true, - extendsProps: [ - { - type: 'ReactNativeBuiltInType', - knownTypeName: 'ReactNativeCoreViewProps', - }, - ], - events: [], - props: [ - { - name: 'nativePrimitives', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'colors', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'ColorPrimitive', - }, - }, - }, - { - name: 'srcs', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'ImageSourcePrimitive', - }, - }, - }, - { - name: 'points', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ReservedPropTypeAnnotation', - name: 'PointPrimitive', - }, - }, - }, - ], - }, - }, - }, - ], - commands: [], - }, - }, - }, - }, -}; - -const OBJECT_PROPS_WITH_OPTIONAL_GEN: SchemaType = { - modules: { - ObjectPropsNativeComponent: { - type: 'Component', - components: { - ObjectProps: { - generateOptionalProperties: true, - extendsProps: [ - { - type: 'ReactNativeBuiltInType', - knownTypeName: 'ReactNativeCoreViewProps', - }, - ], - events: [], - props: [ - { - name: 'objectProp', - optional: true, - typeAnnotation: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'stringProp', - optional: true, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: '', - }, - }, - { - name: 'booleanProp', - optional: true, - typeAnnotation: { - type: 'BooleanTypeAnnotation', - default: false, - }, - }, - { - name: 'floatProp', - optional: true, - typeAnnotation: { - type: 'FloatTypeAnnotation', - default: 0.0, - }, - }, - { - name: 'intProp', - optional: true, - typeAnnotation: { - type: 'Int32TypeAnnotation', - default: 0, - }, - }, - { - name: 'stringUserDefaultProp', - optional: true, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: 'user_default', - }, - }, - { - name: 'booleanUserDefaultProp', - optional: true, - typeAnnotation: { - type: 'BooleanTypeAnnotation', - default: true, - }, - }, - { - name: 'floatUserDefaultProp', - optional: true, - typeAnnotation: { - type: 'FloatTypeAnnotation', - default: 3.14, - }, - }, - { - name: 'intUserDefaultProp', - optional: true, - typeAnnotation: { - type: 'Int32TypeAnnotation', - default: 9999, - }, - }, - { - name: 'stringEnumProp', - optional: true, - typeAnnotation: { - type: 'StringEnumTypeAnnotation', - default: 'option1', - options: ['option1'], - }, - }, - { - name: 'intEnumProp', - optional: true, - typeAnnotation: { - type: 'Int32EnumTypeAnnotation', - default: 0, - options: [0], - }, - }, - { - name: 'objectArrayProp', - optional: false, - typeAnnotation: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'array', - optional: true, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'StringTypeAnnotation', - }, - }, - }, - ], - }, - }, - { - name: 'objectPrimitiveRequiredProp', - optional: false, - typeAnnotation: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'image', - optional: true, - typeAnnotation: { - type: 'ReservedPropTypeAnnotation', - name: 'ImageSourcePrimitive', - }, - }, - { - name: 'color', - optional: true, - typeAnnotation: { - type: 'ReservedPropTypeAnnotation', - name: 'ColorPrimitive', - }, - }, - { - name: 'point', - optional: true, - typeAnnotation: { - type: 'ReservedPropTypeAnnotation', - name: 'PointPrimitive', - }, - }, - ], - }, - }, - { - name: 'nestedPropA', - optional: false, - typeAnnotation: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'nestedPropB', - optional: false, - typeAnnotation: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'nestedPropC', - optional: true, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: '', - }, - }, - ], - }, - }, - ], - }, - }, - { - name: 'nestedArrayAsProperty', - optional: false, - typeAnnotation: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'arrayProp', - optional: false, - typeAnnotation: { - type: 'ArrayTypeAnnotation', - elementType: { - type: 'ObjectTypeAnnotation', - properties: [ - { - name: 'stringProp', - optional: false, - typeAnnotation: { - type: 'StringTypeAnnotation', - default: '', - }, - }, - ], - }, - }, - }, - ], - }, - }, - ], - }, - }, - ], - commands: [], - }, - }, - }, - }, -}; - const ALL_PROP: SchemaType = { modules: { AllPropsNativeComponent: { @@ -2557,6 +2061,54 @@ const ALL_PROP: SchemaType = { typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [ + { + name: 'string', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: 'defaultString', + }, + }, + { + name: 'boolean', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'float', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 3.14, + }, + }, + { + name: 'stringNoDefault', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: null, + }, + }, + { + name: 'booleanNoDefault', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: null, + }, + }, + { + name: 'floatNoDefault', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: null, + }, + }, { name: 'image', optional: true, @@ -2793,6 +2345,54 @@ const ALL_PROP_WITH_OPTIONAL_GEN: SchemaType = { typeAnnotation: { type: 'ObjectTypeAnnotation', properties: [ + { + name: 'string', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: 'defaultString', + }, + }, + { + name: 'boolean', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'float', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 3.14, + }, + }, + { + name: 'stringNoDefault', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: null, + }, + }, + { + name: 'booleanNoDefault', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: null, + }, + }, + { + name: 'floatNoDefault', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: null, + }, + }, { name: 'image', optional: true, @@ -2883,6 +2483,1286 @@ const ALL_PROP_WITH_OPTIONAL_GEN: SchemaType = { }, }; +const ALL_PROP_WITH_OPTIONAL_OBJECT_GEN: SchemaType = { + modules: { + AllPropsNativeComponent: { + type: 'Component', + components: { + AllPropWithOptionalObjectGen: { + generateOptionalProperties: true, + generateOptionalObjectProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'stringPropNoDefault', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: null, + }, + }, + { + name: 'booleanPropNoDefault', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: null, + }, + }, + { + name: 'floatPropNoDefault', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: null, + }, + }, + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + { + name: 'booleanProp', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'floatProp', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 0.0, + }, + }, + { + name: 'intProp', + optional: true, + typeAnnotation: { + type: 'Int32TypeAnnotation', + default: 0, + }, + }, + { + name: 'stringUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: 'user_default', + }, + }, + { + name: 'booleanUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: true, + }, + }, + { + name: 'floatUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 3.14, + }, + }, + { + name: 'intUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'Int32TypeAnnotation', + default: 9999, + }, + }, + { + name: 'stringEnumProp', + optional: true, + typeAnnotation: { + type: 'StringEnumTypeAnnotation', + default: 'option1', + options: ['option1'], + }, + }, + { + name: 'intEnumProp', + optional: true, + typeAnnotation: { + type: 'Int32EnumTypeAnnotation', + default: 0, + options: [0], + }, + }, + { + name: 'objectArrayProp', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'array', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringTypeAnnotation', + }, + }, + }, + ], + }, + }, + { + name: 'objectPrimitiveRequiredProp', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'string', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: 'defaultString', + }, + }, + { + name: 'boolean', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'float', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 3.14, + }, + }, + { + name: 'stringNoDefault', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: null, + }, + }, + { + name: 'booleanNoDefault', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: null, + }, + }, + { + name: 'floatNoDefault', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: null, + }, + }, + { + name: 'image', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + { + name: 'color', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + { + name: 'point', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + ], + }, + }, + { + name: 'nestedPropA', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'nestedPropB', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'nestedPropC', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + ], + }, + }, + { + name: 'nestedArrayAsProperty', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'arrayProp', + optional: false, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: false, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + ], + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + +const ARRAY_PROPS_WITH_OPTIONAL_GEN: SchemaType = { + modules: { + Slider: { + type: 'Component', + components: { + ArrayPropsWithOptionalGenNativeComponent: { + generateOptionalProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'names', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringTypeAnnotation', + }, + }, + }, + { + name: 'disableds', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'BooleanTypeAnnotation', + }, + }, + }, + { + name: 'progress', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'Int32TypeAnnotation', + }, + }, + }, + { + name: 'radii', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'FloatTypeAnnotation', + }, + }, + }, + { + name: 'colors', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + }, + { + name: 'srcs', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + }, + { + name: 'points', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + }, + { + name: 'dimensions', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'DimensionPrimitive', + }, + }, + }, + { + name: 'sizes', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringEnumTypeAnnotation', + default: 'small', + options: ['small', 'large'], + }, + }, + }, + { + name: 'object', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + { + name: 'array', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + // This needs to stay the same as the object above + // to confirm that the structs are generated + // with unique non-colliding names + name: 'object', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + ], + }, + }, + }, + { + name: 'arrayOfArrayOfObject', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + }, + { + name: 'arrayOfMixed', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'MixedTypeAnnotation', + }, + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + +const ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN: SchemaType = { + modules: { + Slider: { + type: 'Component', + components: { + ArrayPropsWithOptionalObjectGenNativeComponent: { + generateOptionalProperties: true, + generateOptionalObjectProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'names', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringTypeAnnotation', + }, + }, + }, + { + name: 'disableds', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'BooleanTypeAnnotation', + }, + }, + }, + { + name: 'progress', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'Int32TypeAnnotation', + }, + }, + }, + { + name: 'radii', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'FloatTypeAnnotation', + }, + }, + }, + { + name: 'colors', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + }, + { + name: 'srcs', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + }, + { + name: 'points', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + }, + { + name: 'dimensions', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'DimensionPrimitive', + }, + }, + }, + { + name: 'sizes', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringEnumTypeAnnotation', + default: 'small', + options: ['small', 'large'], + }, + }, + }, + { + name: 'object', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + { + name: 'array', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + // This needs to stay the same as the object above + // to confirm that the structs are generated + // with unique non-colliding names + name: 'object', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + ], + }, + }, + }, + { + name: 'arrayOfArrayOfObject', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + }, + { + name: 'arrayOfMixed', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'MixedTypeAnnotation', + }, + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + +const ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN: SchemaType = { + modules: { + Slider: { + type: 'Component', + components: { + ArrayPropsOptionalGenNativeComponent: { + generateOptionalProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'nativePrimitives', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'colors', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + }, + { + name: 'srcs', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + }, + { + name: 'points', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + }, + ], + }, + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + +const ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN: SchemaType = { + modules: { + Slider: { + type: 'Component', + components: { + ArrayPropsOptionalObjectGenNativeComponent: { + generateOptionalProperties: true, + generateOptionalObjectProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'nativePrimitives', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'colors', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + }, + { + name: 'srcs', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + }, + { + name: 'points', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + }, + ], + }, + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + +const OBJECT_PROPS_WITH_OPTIONAL_GEN: SchemaType = { + modules: { + ObjectPropsNativeComponent: { + type: 'Component', + components: { + ObjectPropsWithOptionalGen: { + generateOptionalProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'objectProp', + optional: true, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + { + name: 'booleanProp', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'floatProp', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 0.0, + }, + }, + { + name: 'intProp', + optional: true, + typeAnnotation: { + type: 'Int32TypeAnnotation', + default: 0, + }, + }, + { + name: 'stringUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: 'user_default', + }, + }, + { + name: 'booleanUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: true, + }, + }, + { + name: 'floatUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 3.14, + }, + }, + { + name: 'intUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'Int32TypeAnnotation', + default: 9999, + }, + }, + { + name: 'stringEnumProp', + optional: true, + typeAnnotation: { + type: 'StringEnumTypeAnnotation', + default: 'option1', + options: ['option1'], + }, + }, + { + name: 'intEnumProp', + optional: true, + typeAnnotation: { + type: 'Int32EnumTypeAnnotation', + default: 0, + options: [0], + }, + }, + { + name: 'objectArrayProp', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'array', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringTypeAnnotation', + }, + }, + }, + ], + }, + }, + { + name: 'objectPrimitiveRequiredProp', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'image', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + { + name: 'color', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + { + name: 'point', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + ], + }, + }, + { + name: 'nestedPropA', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'nestedPropB', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'nestedPropC', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + ], + }, + }, + { + name: 'nestedArrayAsProperty', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'arrayProp', + optional: false, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: false, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + ], + }, + }, + ], + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + +const OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN: SchemaType = { + modules: { + ObjectPropsNativeComponent: { + type: 'Component', + components: { + ObjectPropsWithOptionalObjectGen: { + generateOptionalProperties: true, + generateOptionalObjectProperties: true, + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'objectProp', + optional: true, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + { + name: 'booleanProp', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'floatProp', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 0.0, + }, + }, + { + name: 'intProp', + optional: true, + typeAnnotation: { + type: 'Int32TypeAnnotation', + default: 0, + }, + }, + { + name: 'stringUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: 'user_default', + }, + }, + { + name: 'booleanUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: true, + }, + }, + { + name: 'floatUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'FloatTypeAnnotation', + default: 3.14, + }, + }, + { + name: 'intUserDefaultProp', + optional: true, + typeAnnotation: { + type: 'Int32TypeAnnotation', + default: 9999, + }, + }, + { + name: 'stringEnumProp', + optional: true, + typeAnnotation: { + type: 'StringEnumTypeAnnotation', + default: 'option1', + options: ['option1'], + }, + }, + { + name: 'intEnumProp', + optional: true, + typeAnnotation: { + type: 'Int32EnumTypeAnnotation', + default: 0, + options: [0], + }, + }, + { + name: 'objectArrayProp', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'array', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'StringTypeAnnotation', + }, + }, + }, + ], + }, + }, + { + name: 'objectPrimitiveRequiredProp', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'image', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + { + name: 'color', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + { + name: 'point', + optional: true, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }, + }, + ], + }, + }, + { + name: 'nestedPropA', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'nestedPropB', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'nestedPropC', + optional: true, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + ], + }, + }, + { + name: 'nestedArrayAsProperty', + optional: false, + typeAnnotation: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'arrayProp', + optional: false, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: [ + { + name: 'stringProp', + optional: false, + typeAnnotation: { + type: 'StringTypeAnnotation', + default: '', + }, + }, + ], + }, + }, + }, + ], + }, + }, + ], + }, + }, + ], + commands: [], + }, + }, + }, + }, +}; + module.exports = { NO_PROPS_NO_EVENTS, INTERFACE_ONLY, @@ -2913,9 +3793,13 @@ module.exports = { EXCLUDE_ANDROID, EXCLUDE_ANDROID_IOS, EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES, - ARRAY_PROPS_WITH_OPTIONAL_GEN, - ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN, - OBJECT_PROPS_WITH_OPTIONAL_GEN, ALL_PROP, ALL_PROP_WITH_OPTIONAL_GEN, + ALL_PROP_WITH_OPTIONAL_OBJECT_GEN, + ARRAY_PROPS_WITH_OPTIONAL_GEN, + ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN, + ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN, + ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN, + OBJECT_PROPS_WITH_OPTIONAL_GEN, + OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN, }; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorCpp-test.js.snap index 06e0e9942c2..6800b176061 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorCpp-test.js.snap @@ -56,6 +56,34 @@ registry->add(concreteComponentDescriptorProvider " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorCpp.js + */ + +#include +#include +#include + +namespace facebook::react { + +void ALL_PROP_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry) { +registry->add(concreteComponentDescriptorProvider()); +} + +} // namespace facebook::react +", +} +`; + exports[`GenerateComponentDescriptorCpp can generate fixture ARRAY_PROPS 1`] = ` Map { "ComponentDescriptors.cpp" => " @@ -132,7 +160,35 @@ namespace facebook::react { void ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( std::shared_ptr registry) { -registry->add(concreteComponentDescriptorProvider()); +registry->add(concreteComponentDescriptorProvider()); +} + +} // namespace facebook::react +", +} +`; + +exports[`GenerateComponentDescriptorCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorCpp.js + */ + +#include +#include +#include + +namespace facebook::react { + +void ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry) { +registry->add(concreteComponentDescriptorProvider()); } } // namespace facebook::react @@ -160,7 +216,35 @@ namespace facebook::react { void ARRAY_PROPS_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( std::shared_ptr registry) { -registry->add(concreteComponentDescriptorProvider()); +registry->add(concreteComponentDescriptorProvider()); +} + +} // namespace facebook::react +", +} +`; + +exports[`GenerateComponentDescriptorCpp can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorCpp.js + */ + +#include +#include +#include + +namespace facebook::react { + +void ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry) { +registry->add(concreteComponentDescriptorProvider()); } } // namespace facebook::react @@ -805,7 +889,35 @@ namespace facebook::react { void OBJECT_PROPS_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( std::shared_ptr registry) { -registry->add(concreteComponentDescriptorProvider()); +registry->add(concreteComponentDescriptorProvider()); +} + +} // namespace facebook::react +", +} +`; + +exports[`GenerateComponentDescriptorCpp can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorCpp.js + */ + +#include +#include +#include + +namespace facebook::react { + +void OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry) { +registry->add(concreteComponentDescriptorProvider()); } } // namespace facebook::react diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap index 382340f857a..8657a4701bf 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap @@ -60,6 +60,36 @@ void ALL_PROP_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( } `; +exports[`GenerateComponentDescriptorH can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorH.js + */ + +#pragma once + +#include +#include +#include + +namespace facebook::react { + +using AllPropWithOptionalObjectGenComponentDescriptor = ConcreteComponentDescriptor; + +void ALL_PROP_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry); + +} // namespace facebook::react +", +} +`; + exports[`GenerateComponentDescriptorH can generate fixture ARRAY_PROPS 1`] = ` Map { "ComponentDescriptors.h" => " @@ -140,7 +170,7 @@ Map { namespace facebook::react { -using ArrayPropsNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using ArrayPropsOptionalGenNativeComponentComponentDescriptor = ConcreteComponentDescriptor; void ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( std::shared_ptr registry); @@ -150,6 +180,36 @@ void ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN_registerComponentDescripto } `; +exports[`GenerateComponentDescriptorH can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorH.js + */ + +#pragma once + +#include +#include +#include + +namespace facebook::react { + +using ArrayPropsOptionalObjectGenNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +void ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry); + +} // namespace facebook::react +", +} +`; + exports[`GenerateComponentDescriptorH can generate fixture ARRAY_PROPS_WITH_OPTIONAL_GEN 1`] = ` Map { "ComponentDescriptors.h" => " @@ -170,7 +230,7 @@ Map { namespace facebook::react { -using ArrayPropsNativeComponentComponentDescriptor = ConcreteComponentDescriptor; +using ArrayPropsWithOptionalGenNativeComponentComponentDescriptor = ConcreteComponentDescriptor; void ARRAY_PROPS_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( std::shared_ptr registry); @@ -180,6 +240,36 @@ void ARRAY_PROPS_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( } `; +exports[`GenerateComponentDescriptorH can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorH.js + */ + +#pragma once + +#include +#include +#include + +namespace facebook::react { + +using ArrayPropsWithOptionalObjectGenNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +void ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry); + +} // namespace facebook::react +", +} +`; + exports[`GenerateComponentDescriptorH can generate fixture BOOLEAN_PROP 1`] = ` Map { "ComponentDescriptors.h" => " @@ -861,7 +951,7 @@ Map { namespace facebook::react { -using ObjectPropsComponentDescriptor = ConcreteComponentDescriptor; +using ObjectPropsWithOptionalGenComponentDescriptor = ConcreteComponentDescriptor; void OBJECT_PROPS_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( std::shared_ptr registry); @@ -871,6 +961,36 @@ void OBJECT_PROPS_WITH_OPTIONAL_GEN_registerComponentDescriptorsFromCodegen( } `; +exports[`GenerateComponentDescriptorH can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateComponentDescriptorH.js + */ + +#pragma once + +#include +#include +#include + +namespace facebook::react { + +using ObjectPropsWithOptionalObjectGenComponentDescriptor = ConcreteComponentDescriptor; + +void OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN_registerComponentDescriptorsFromCodegen( + std::shared_ptr registry); + +} // namespace facebook::react +", +} +`; + exports[`GenerateComponentDescriptorH can generate fixture POINT_PROP 1`] = ` Map { "ComponentDescriptors.h" => " diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap index 3b4436fe56e..2038213ab7b 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateComponentHObjCpp-test.js.snap @@ -50,6 +50,31 @@ NS_ASSUME_NONNULL_END", } `; +exports[`GenerateComponentHObjCpp can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "RCTComponentViewHelpers.h" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GenerateComponentHObjCpp.js +*/ + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol RCTAllPropWithOptionalObjectGenViewProtocol + +@end + +NS_ASSUME_NONNULL_END", +} +`; + exports[`GenerateComponentHObjCpp can generate fixture ARRAY_PROPS 1`] = ` Map { "RCTComponentViewHelpers.h" => "/** @@ -117,7 +142,32 @@ Map { NS_ASSUME_NONNULL_BEGIN -@protocol RCTArrayPropsNativeComponentViewProtocol +@protocol RCTArrayPropsOptionalGenNativeComponentViewProtocol + +@end + +NS_ASSUME_NONNULL_END", +} +`; + +exports[`GenerateComponentHObjCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "RCTComponentViewHelpers.h" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GenerateComponentHObjCpp.js +*/ + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol RCTArrayPropsOptionalObjectGenNativeComponentViewProtocol @end @@ -142,7 +192,32 @@ Map { NS_ASSUME_NONNULL_BEGIN -@protocol RCTArrayPropsNativeComponentViewProtocol +@protocol RCTArrayPropsWithOptionalGenNativeComponentViewProtocol + +@end + +NS_ASSUME_NONNULL_END", +} +`; + +exports[`GenerateComponentHObjCpp can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "RCTComponentViewHelpers.h" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GenerateComponentHObjCpp.js +*/ + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol RCTArrayPropsWithOptionalObjectGenNativeComponentViewProtocol @end @@ -880,7 +955,32 @@ Map { NS_ASSUME_NONNULL_BEGIN -@protocol RCTObjectPropsViewProtocol +@protocol RCTObjectPropsWithOptionalGenViewProtocol + +@end + +NS_ASSUME_NONNULL_END", +} +`; + +exports[`GenerateComponentHObjCpp can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "RCTComponentViewHelpers.h" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GenerateComponentHObjCpp.js +*/ + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol RCTObjectPropsWithOptionalObjectGenViewProtocol @end diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap index 051df30ffd6..b7511e59fa0 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap @@ -37,6 +37,28 @@ Map { #include +namespace facebook::react { + +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterCpp.js + */ + +#include + + namespace facebook::react { } // namespace facebook::react @@ -103,6 +125,28 @@ Map { #include +namespace facebook::react { + +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterCpp.js + */ + +#include + + namespace facebook::react { } // namespace facebook::react @@ -125,6 +169,28 @@ Map { #include +namespace facebook::react { + +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterCpp.js + */ + +#include + + namespace facebook::react { } // namespace facebook::react @@ -780,6 +846,28 @@ Map { #include +namespace facebook::react { + +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterCpp.js + */ + +#include + + namespace facebook::react { } // namespace facebook::react diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap index cedfb282318..618ec42e3e6 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -52,6 +52,35 @@ class AllPropWithOptionalGenEventEmitter : public ViewEventEmitter { +}; +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterH.js + */ +#pragma once + +#include + + +namespace facebook::react { +class AllPropWithOptionalObjectGenEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + }; } // namespace facebook::react ", @@ -133,7 +162,36 @@ Map { namespace facebook::react { -class ArrayPropsNativeComponentEventEmitter : public ViewEventEmitter { +class ArrayPropsOptionalGenNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterH.js + */ +#pragma once + +#include + + +namespace facebook::react { +class ArrayPropsOptionalObjectGenNativeComponentEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -162,7 +220,36 @@ Map { namespace facebook::react { -class ArrayPropsNativeComponentEventEmitter : public ViewEventEmitter { +class ArrayPropsWithOptionalGenNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterH.js + */ +#pragma once + +#include + + +namespace facebook::react { +class ArrayPropsWithOptionalObjectGenNativeComponentEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -923,7 +1010,36 @@ Map { namespace facebook::react { -class ObjectPropsEventEmitter : public ViewEventEmitter { +class ObjectPropsWithOptionalGenEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; +} // namespace facebook::react +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "EventEmitters.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateEventEmitterH.js + */ +#pragma once + +#include + + +namespace facebook::react { +class ObjectPropsWithOptionalObjectGenEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap index 34a27a53597..fbf62c1c987 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap @@ -282,6 +282,154 @@ folly::dynamic AllPropWithOptionalGenProps::getDiffProps( } `; +exports[`GeneratePropsCpp can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsCpp.js + */ + +#include +#include +#include +#include + +namespace facebook::react { + +AllPropWithOptionalObjectGenProps::AllPropWithOptionalObjectGenProps( + const PropsParserContext &context, + const AllPropWithOptionalObjectGenProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), + + stringPropNoDefault(convertRawProp(context, rawProps, \\"stringPropNoDefault\\", sourceProps.stringPropNoDefault, {})), + booleanPropNoDefault(convertRawProp(context, rawProps, \\"booleanPropNoDefault\\", sourceProps.booleanPropNoDefault, {})), + floatPropNoDefault(convertRawProp(context, rawProps, \\"floatPropNoDefault\\", sourceProps.floatPropNoDefault, {})), + stringProp(convertRawProp(context, rawProps, \\"stringProp\\", sourceProps.stringProp, {std::string{\\"\\"}})), + booleanProp(convertRawProp(context, rawProps, \\"booleanProp\\", sourceProps.booleanProp, {false})), + floatProp(convertRawProp(context, rawProps, \\"floatProp\\", sourceProps.floatProp, {0.0})), + intProp(convertRawProp(context, rawProps, \\"intProp\\", sourceProps.intProp, {0})), + stringUserDefaultProp(convertRawProp(context, rawProps, \\"stringUserDefaultProp\\", sourceProps.stringUserDefaultProp, {std::string{\\"user_default\\"}})), + booleanUserDefaultProp(convertRawProp(context, rawProps, \\"booleanUserDefaultProp\\", sourceProps.booleanUserDefaultProp, {true})), + floatUserDefaultProp(convertRawProp(context, rawProps, \\"floatUserDefaultProp\\", sourceProps.floatUserDefaultProp, {3.14})), + intUserDefaultProp(convertRawProp(context, rawProps, \\"intUserDefaultProp\\", sourceProps.intUserDefaultProp, {9999})), + stringEnumProp(convertRawProp(context, rawProps, \\"stringEnumProp\\", sourceProps.stringEnumProp, {AllPropWithOptionalObjectGenStringEnumProp::Option1})), + intEnumProp(convertRawProp(context, rawProps, \\"intEnumProp\\", sourceProps.intEnumProp, {AllPropWithOptionalObjectGenIntEnumProp::IntEnumProp0})), + objectArrayProp(convertRawProp(context, rawProps, \\"objectArrayProp\\", sourceProps.objectArrayProp, {})), + objectPrimitiveRequiredProp(convertRawProp(context, rawProps, \\"objectPrimitiveRequiredProp\\", sourceProps.objectPrimitiveRequiredProp, {})), + nestedPropA(convertRawProp(context, rawProps, \\"nestedPropA\\", sourceProps.nestedPropA, {})), + nestedArrayAsProperty(convertRawProp(context, rawProps, \\"nestedArrayAsProperty\\", sourceProps.nestedArrayAsProperty, {})) {} + +#ifdef RN_SERIALIZABLE_STATE +ComponentName AllPropWithOptionalObjectGenProps::getDiffPropsImplementationTarget() const { + return \\"AllPropWithOptionalObjectGen\\"; +} + +folly::dynamic AllPropWithOptionalObjectGenProps::getDiffProps( + const Props* prevProps) const { + static const auto defaultProps = AllPropWithOptionalObjectGenProps(); + const AllPropWithOptionalObjectGenProps* oldProps = prevProps == nullptr + ? &defaultProps + : static_cast(prevProps); + if (this == oldProps) { + return folly::dynamic::object(); + } + folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + + if (stringPropNoDefault != oldProps->stringPropNoDefault) { + if (stringPropNoDefault.has_value()) { + result[\\"stringPropNoDefault\\"] = stringPropNoDefault.value(); + } else { + result[\\"stringPropNoDefault\\"] = folly::dynamic(nullptr); + } + } + + if (booleanPropNoDefault != oldProps->booleanPropNoDefault) { + if (booleanPropNoDefault.has_value()) { + result[\\"booleanPropNoDefault\\"] = booleanPropNoDefault.value(); + } else { + result[\\"booleanPropNoDefault\\"] = folly::dynamic(nullptr); + } + } + + if ((floatPropNoDefault != oldProps->floatPropNoDefault)) { + if (floatPropNoDefault.has_value()) { + if (!oldProps->floatPropNoDefault.has_value() || !(std::isnan(floatPropNoDefault.value()) && std::isnan(oldProps->floatPropNoDefault.value()))) { + result[\\"floatPropNoDefault\\"] = floatPropNoDefault.value(); + } + } else { + result[\\"floatPropNoDefault\\"] = folly::dynamic(nullptr); + } + } + + if (stringProp != oldProps->stringProp) { + result[\\"stringProp\\"] = stringProp; + } + + if (booleanProp != oldProps->booleanProp) { + result[\\"booleanProp\\"] = booleanProp; + } + + if ((floatProp != oldProps->floatProp) && !(std::isnan(floatProp) && std::isnan(oldProps->floatProp))) { + result[\\"floatProp\\"] = floatProp; + } + + if (intProp != oldProps->intProp) { + result[\\"intProp\\"] = intProp; + } + + if (stringUserDefaultProp != oldProps->stringUserDefaultProp) { + result[\\"stringUserDefaultProp\\"] = stringUserDefaultProp; + } + + if (booleanUserDefaultProp != oldProps->booleanUserDefaultProp) { + result[\\"booleanUserDefaultProp\\"] = booleanUserDefaultProp; + } + + if ((floatUserDefaultProp != oldProps->floatUserDefaultProp) && !(std::isnan(floatUserDefaultProp) && std::isnan(oldProps->floatUserDefaultProp))) { + result[\\"floatUserDefaultProp\\"] = floatUserDefaultProp; + } + + if (intUserDefaultProp != oldProps->intUserDefaultProp) { + result[\\"intUserDefaultProp\\"] = intUserDefaultProp; + } + + if (stringEnumProp != oldProps->stringEnumProp) { + result[\\"stringEnumProp\\"] = toDynamic(stringEnumProp); + } + + if (intEnumProp != oldProps->intEnumProp) { + result[\\"intEnumProp\\"] = toDynamic(intEnumProp); + } + + if (objectArrayProp != oldProps->objectArrayProp) { + result[\\"objectArrayProp\\"] = toDynamic(objectArrayProp); + } + + if (objectPrimitiveRequiredProp != oldProps->objectPrimitiveRequiredProp) { + result[\\"objectPrimitiveRequiredProp\\"] = toDynamic(objectPrimitiveRequiredProp); + } + + if (nestedPropA != oldProps->nestedPropA) { + result[\\"nestedPropA\\"] = toDynamic(nestedPropA); + } + + if (nestedArrayAsProperty != oldProps->nestedArrayAsProperty) { + result[\\"nestedArrayAsProperty\\"] = toDynamic(nestedArrayAsProperty); + } + return result; +} +#endif + +} // namespace facebook::react +", +} +`; + exports[`GeneratePropsCpp can generate fixture ARRAY_PROPS 1`] = ` Map { "Props.cpp" => " @@ -468,24 +616,81 @@ Map { namespace facebook::react { -ArrayPropsNativeComponentProps::ArrayPropsNativeComponentProps( +ArrayPropsOptionalGenNativeComponentProps::ArrayPropsOptionalGenNativeComponentProps( const PropsParserContext &context, - const ArrayPropsNativeComponentProps &sourceProps, + const ArrayPropsOptionalGenNativeComponentProps &sourceProps, const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), nativePrimitives(convertRawProp(context, rawProps, \\"nativePrimitives\\", sourceProps.nativePrimitives, {})) {} #ifdef RN_SERIALIZABLE_STATE -ComponentName ArrayPropsNativeComponentProps::getDiffPropsImplementationTarget() const { - return \\"ArrayPropsNativeComponent\\"; +ComponentName ArrayPropsOptionalGenNativeComponentProps::getDiffPropsImplementationTarget() const { + return \\"ArrayPropsOptionalGenNativeComponent\\"; } -folly::dynamic ArrayPropsNativeComponentProps::getDiffProps( +folly::dynamic ArrayPropsOptionalGenNativeComponentProps::getDiffProps( const Props* prevProps) const { - static const auto defaultProps = ArrayPropsNativeComponentProps(); - const ArrayPropsNativeComponentProps* oldProps = prevProps == nullptr + static const auto defaultProps = ArrayPropsOptionalGenNativeComponentProps(); + const ArrayPropsOptionalGenNativeComponentProps* oldProps = prevProps == nullptr ? &defaultProps - : static_cast(prevProps); + : static_cast(prevProps); + if (this == oldProps) { + return folly::dynamic::object(); + } + folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + + if (nativePrimitives != oldProps->nativePrimitives) { + if (nativePrimitives.has_value()) { + result[\\"nativePrimitives\\"] = toDynamic(nativePrimitives.value()); + } else { + result[\\"nativePrimitives\\"] = folly::dynamic(nullptr); + } + } + return result; +} +#endif + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsCpp.js + */ + +#include +#include +#include + +namespace facebook::react { + +ArrayPropsOptionalObjectGenNativeComponentProps::ArrayPropsOptionalObjectGenNativeComponentProps( + const PropsParserContext &context, + const ArrayPropsOptionalObjectGenNativeComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), + + nativePrimitives(convertRawProp(context, rawProps, \\"nativePrimitives\\", sourceProps.nativePrimitives, {})) {} + +#ifdef RN_SERIALIZABLE_STATE +ComponentName ArrayPropsOptionalObjectGenNativeComponentProps::getDiffPropsImplementationTarget() const { + return \\"ArrayPropsOptionalObjectGenNativeComponent\\"; +} + +folly::dynamic ArrayPropsOptionalObjectGenNativeComponentProps::getDiffProps( + const Props* prevProps) const { + static const auto defaultProps = ArrayPropsOptionalObjectGenNativeComponentProps(); + const ArrayPropsOptionalObjectGenNativeComponentProps* oldProps = prevProps == nullptr + ? &defaultProps + : static_cast(prevProps); if (this == oldProps) { return folly::dynamic::object(); } @@ -527,9 +732,9 @@ Map { namespace facebook::react { -ArrayPropsNativeComponentProps::ArrayPropsNativeComponentProps( +ArrayPropsWithOptionalGenNativeComponentProps::ArrayPropsWithOptionalGenNativeComponentProps( const PropsParserContext &context, - const ArrayPropsNativeComponentProps &sourceProps, + const ArrayPropsWithOptionalGenNativeComponentProps &sourceProps, const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), names(convertRawProp(context, rawProps, \\"names\\", sourceProps.names, {})), @@ -540,23 +745,190 @@ ArrayPropsNativeComponentProps::ArrayPropsNativeComponentProps( srcs(convertRawProp(context, rawProps, \\"srcs\\", sourceProps.srcs, {})), points(convertRawProp(context, rawProps, \\"points\\", sourceProps.points, {})), dimensions(convertRawProp(context, rawProps, \\"dimensions\\", sourceProps.dimensions, {})), - sizes(convertRawProp(context, rawProps, \\"sizes\\", ArrayPropsNativeComponentSizesMaskWrapped{ .value = sourceProps.sizes }, {static_cast(ArrayPropsNativeComponentSizes::Small)}).value), + sizes(convertRawProp(context, rawProps, \\"sizes\\", ArrayPropsWithOptionalGenNativeComponentSizesMaskWrapped{ .value = sourceProps.sizes }, {static_cast(ArrayPropsWithOptionalGenNativeComponentSizes::Small)}).value), object(convertRawProp(context, rawProps, \\"object\\", sourceProps.object, {})), array(convertRawProp(context, rawProps, \\"array\\", sourceProps.array, {})), arrayOfArrayOfObject(convertRawProp(context, rawProps, \\"arrayOfArrayOfObject\\", sourceProps.arrayOfArrayOfObject, {})), arrayOfMixed(convertRawProp(context, rawProps, \\"arrayOfMixed\\", sourceProps.arrayOfMixed, {})) {} #ifdef RN_SERIALIZABLE_STATE -ComponentName ArrayPropsNativeComponentProps::getDiffPropsImplementationTarget() const { - return \\"ArrayPropsNativeComponent\\"; +ComponentName ArrayPropsWithOptionalGenNativeComponentProps::getDiffPropsImplementationTarget() const { + return \\"ArrayPropsWithOptionalGenNativeComponent\\"; } -folly::dynamic ArrayPropsNativeComponentProps::getDiffProps( +folly::dynamic ArrayPropsWithOptionalGenNativeComponentProps::getDiffProps( const Props* prevProps) const { - static const auto defaultProps = ArrayPropsNativeComponentProps(); - const ArrayPropsNativeComponentProps* oldProps = prevProps == nullptr + static const auto defaultProps = ArrayPropsWithOptionalGenNativeComponentProps(); + const ArrayPropsWithOptionalGenNativeComponentProps* oldProps = prevProps == nullptr ? &defaultProps - : static_cast(prevProps); + : static_cast(prevProps); + if (this == oldProps) { + return folly::dynamic::object(); + } + folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + + if (names != oldProps->names) { + if (names.has_value()) { + result[\\"names\\"] = toDynamic(names.value()); + } else { + result[\\"names\\"] = folly::dynamic(nullptr); + } + } + + if (disableds != oldProps->disableds) { + if (disableds.has_value()) { + result[\\"disableds\\"] = toDynamic(disableds.value()); + } else { + result[\\"disableds\\"] = folly::dynamic(nullptr); + } + } + + if (progress != oldProps->progress) { + if (progress.has_value()) { + result[\\"progress\\"] = toDynamic(progress.value()); + } else { + result[\\"progress\\"] = folly::dynamic(nullptr); + } + } + + if (radii != oldProps->radii) { + if (radii.has_value()) { + result[\\"radii\\"] = toDynamic(radii.value()); + } else { + result[\\"radii\\"] = folly::dynamic(nullptr); + } + } + + if (colors != oldProps->colors) { + if (colors.has_value()) { + result[\\"colors\\"] = toDynamic(colors.value()); + } else { + result[\\"colors\\"] = folly::dynamic(nullptr); + } + } + + if (srcs != oldProps->srcs) { + if (srcs.has_value()) { + result[\\"srcs\\"] = toDynamic(srcs.value()); + } else { + result[\\"srcs\\"] = folly::dynamic(nullptr); + } + } + + if (points != oldProps->points) { + if (points.has_value()) { + result[\\"points\\"] = toDynamic(points.value()); + } else { + result[\\"points\\"] = folly::dynamic(nullptr); + } + } + + if (dimensions != oldProps->dimensions) { + if (dimensions.has_value()) { + result[\\"dimensions\\"] = toDynamic(dimensions.value()); + } else { + result[\\"dimensions\\"] = folly::dynamic(nullptr); + } + } + + if (sizes != oldProps->sizes) { + if (sizes.has_value()) { + result[\\"sizes\\"] = toDynamic(sizes.value()); + } else { + result[\\"sizes\\"] = folly::dynamic(nullptr); + } + } + + if (object != oldProps->object) { + if (object.has_value()) { + result[\\"object\\"] = toDynamic(object.value()); + } else { + result[\\"object\\"] = folly::dynamic(nullptr); + } + } + + if (array != oldProps->array) { + if (array.has_value()) { + result[\\"array\\"] = toDynamic(array.value()); + } else { + result[\\"array\\"] = folly::dynamic(nullptr); + } + } + + if (arrayOfArrayOfObject != oldProps->arrayOfArrayOfObject) { + if (arrayOfArrayOfObject.has_value()) { + result[\\"arrayOfArrayOfObject\\"] = toDynamic(arrayOfArrayOfObject.value()); + } else { + result[\\"arrayOfArrayOfObject\\"] = folly::dynamic(nullptr); + } + } + + if (arrayOfMixed != oldProps->arrayOfMixed) { + if (arrayOfMixed.has_value()) { + result[\\"arrayOfMixed\\"] = toDynamic(arrayOfMixed.value()); + } else { + result[\\"arrayOfMixed\\"] = folly::dynamic(nullptr); + } + } + return result; +} +#endif + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsCpp can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsCpp.js + */ + +#include +#include +#include +#include +#include + +namespace facebook::react { + +ArrayPropsWithOptionalObjectGenNativeComponentProps::ArrayPropsWithOptionalObjectGenNativeComponentProps( + const PropsParserContext &context, + const ArrayPropsWithOptionalObjectGenNativeComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), + + names(convertRawProp(context, rawProps, \\"names\\", sourceProps.names, {})), + disableds(convertRawProp(context, rawProps, \\"disableds\\", sourceProps.disableds, {})), + progress(convertRawProp(context, rawProps, \\"progress\\", sourceProps.progress, {})), + radii(convertRawProp(context, rawProps, \\"radii\\", sourceProps.radii, {})), + colors(convertRawProp(context, rawProps, \\"colors\\", sourceProps.colors, {})), + srcs(convertRawProp(context, rawProps, \\"srcs\\", sourceProps.srcs, {})), + points(convertRawProp(context, rawProps, \\"points\\", sourceProps.points, {})), + dimensions(convertRawProp(context, rawProps, \\"dimensions\\", sourceProps.dimensions, {})), + sizes(convertRawProp(context, rawProps, \\"sizes\\", ArrayPropsWithOptionalObjectGenNativeComponentSizesMaskWrapped{ .value = sourceProps.sizes }, {static_cast(ArrayPropsWithOptionalObjectGenNativeComponentSizes::Small)}).value), + object(convertRawProp(context, rawProps, \\"object\\", sourceProps.object, {})), + array(convertRawProp(context, rawProps, \\"array\\", sourceProps.array, {})), + arrayOfArrayOfObject(convertRawProp(context, rawProps, \\"arrayOfArrayOfObject\\", sourceProps.arrayOfArrayOfObject, {})), + arrayOfMixed(convertRawProp(context, rawProps, \\"arrayOfMixed\\", sourceProps.arrayOfMixed, {})) {} + +#ifdef RN_SERIALIZABLE_STATE +ComponentName ArrayPropsWithOptionalObjectGenNativeComponentProps::getDiffPropsImplementationTarget() const { + return \\"ArrayPropsWithOptionalObjectGenNativeComponent\\"; +} + +folly::dynamic ArrayPropsWithOptionalObjectGenNativeComponentProps::getDiffProps( + const Props* prevProps) const { + static const auto defaultProps = ArrayPropsWithOptionalObjectGenNativeComponentProps(); + const ArrayPropsWithOptionalObjectGenNativeComponentProps* oldProps = prevProps == nullptr + ? &defaultProps + : static_cast(prevProps); if (this == oldProps) { return folly::dynamic::object(); } @@ -1950,24 +2322,82 @@ Map { namespace facebook::react { -ObjectPropsProps::ObjectPropsProps( +ObjectPropsWithOptionalGenProps::ObjectPropsWithOptionalGenProps( const PropsParserContext &context, - const ObjectPropsProps &sourceProps, + const ObjectPropsWithOptionalGenProps &sourceProps, const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), objectProp(convertRawProp(context, rawProps, \\"objectProp\\", sourceProps.objectProp, {})) {} #ifdef RN_SERIALIZABLE_STATE -ComponentName ObjectPropsProps::getDiffPropsImplementationTarget() const { - return \\"ObjectProps\\"; +ComponentName ObjectPropsWithOptionalGenProps::getDiffPropsImplementationTarget() const { + return \\"ObjectPropsWithOptionalGen\\"; } -folly::dynamic ObjectPropsProps::getDiffProps( +folly::dynamic ObjectPropsWithOptionalGenProps::getDiffProps( const Props* prevProps) const { - static const auto defaultProps = ObjectPropsProps(); - const ObjectPropsProps* oldProps = prevProps == nullptr + static const auto defaultProps = ObjectPropsWithOptionalGenProps(); + const ObjectPropsWithOptionalGenProps* oldProps = prevProps == nullptr ? &defaultProps - : static_cast(prevProps); + : static_cast(prevProps); + if (this == oldProps) { + return folly::dynamic::object(); + } + folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + + if (objectProp != oldProps->objectProp) { + if (objectProp.has_value()) { + result[\\"objectProp\\"] = toDynamic(objectProp.value()); + } else { + result[\\"objectProp\\"] = folly::dynamic(nullptr); + } + } + return result; +} +#endif + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsCpp can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsCpp.js + */ + +#include +#include +#include +#include + +namespace facebook::react { + +ObjectPropsWithOptionalObjectGenProps::ObjectPropsWithOptionalObjectGenProps( + const PropsParserContext &context, + const ObjectPropsWithOptionalObjectGenProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), + + objectProp(convertRawProp(context, rawProps, \\"objectProp\\", sourceProps.objectProp, {})) {} + +#ifdef RN_SERIALIZABLE_STATE +ComponentName ObjectPropsWithOptionalObjectGenProps::getDiffPropsImplementationTarget() const { + return \\"ObjectPropsWithOptionalObjectGen\\"; +} + +folly::dynamic ObjectPropsWithOptionalObjectGenProps::getDiffProps( + const Props* prevProps) const { + static const auto defaultProps = ObjectPropsWithOptionalObjectGenProps(); + const ObjectPropsWithOptionalObjectGenProps* oldProps = prevProps == nullptr + ? &defaultProps + : static_cast(prevProps); if (this == oldProps) { return folly::dynamic::object(); } 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 06e042555b0..9caeed3455d 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 @@ -112,6 +112,12 @@ static inline folly::dynamic toDynamic(const AllPropObjectArrayPropStruct &value #endif struct AllPropObjectPrimitiveRequiredPropStruct { + std::string string{std::string{\\"defaultString\\"}}; + bool boolean{false}; + Float float{3.14}; + std::string stringNoDefault{}; + bool booleanNoDefault{}; + Float floatNoDefault{}; ImageSource image{}; SharedColor color{}; Point point{}; @@ -122,6 +128,12 @@ struct AllPropObjectPrimitiveRequiredPropStruct { folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); + result[\\"string\\"] = string; + result[\\"boolean\\"] = boolean; + result[\\"float\\"] = float; + result[\\"stringNoDefault\\"] = stringNoDefault; + result[\\"booleanNoDefault\\"] = booleanNoDefault; + result[\\"floatNoDefault\\"] = floatNoDefault; result[\\"image\\"] = ::facebook::react::toDynamic(image); result[\\"color\\"] = ::facebook::react::toDynamic(color); result[\\"point\\"] = ::facebook::react::toDynamic(point); @@ -133,6 +145,30 @@ struct AllPropObjectPrimitiveRequiredPropStruct { static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropObjectPrimitiveRequiredPropStruct &result) { auto map = (std::unordered_map)value; + auto tmp_string = map.find(\\"string\\"); + if (tmp_string != map.end()) { + fromRawValue(context, tmp_string->second, result.string); + } + auto tmp_boolean = map.find(\\"boolean\\"); + if (tmp_boolean != map.end()) { + fromRawValue(context, tmp_boolean->second, result.boolean); + } + auto tmp_float = map.find(\\"float\\"); + if (tmp_float != map.end()) { + fromRawValue(context, tmp_float->second, result.float); + } + auto tmp_stringNoDefault = map.find(\\"stringNoDefault\\"); + if (tmp_stringNoDefault != map.end()) { + fromRawValue(context, tmp_stringNoDefault->second, result.stringNoDefault); + } + auto tmp_booleanNoDefault = map.find(\\"booleanNoDefault\\"); + if (tmp_booleanNoDefault != map.end()) { + fromRawValue(context, tmp_booleanNoDefault->second, result.booleanNoDefault); + } + auto tmp_floatNoDefault = map.find(\\"floatNoDefault\\"); + if (tmp_floatNoDefault != map.end()) { + fromRawValue(context, tmp_floatNoDefault->second, result.floatNoDefault); + } auto tmp_image = map.find(\\"image\\"); if (tmp_image != map.end()) { fromRawValue(context, tmp_image->second, result.image); @@ -453,6 +489,12 @@ static inline folly::dynamic toDynamic(const AllPropWithOptionalGenObjectArrayPr #endif struct AllPropWithOptionalGenObjectPrimitiveRequiredPropStruct { + std::string string{std::string{\\"defaultString\\"}}; + bool boolean{false}; + Float float{3.14}; + std::string stringNoDefault{}; + bool booleanNoDefault{}; + Float floatNoDefault{}; ImageSource image{}; SharedColor color{}; Point point{}; @@ -463,6 +505,12 @@ struct AllPropWithOptionalGenObjectPrimitiveRequiredPropStruct { folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); + result[\\"string\\"] = string; + result[\\"boolean\\"] = boolean; + result[\\"float\\"] = float; + result[\\"stringNoDefault\\"] = stringNoDefault; + result[\\"booleanNoDefault\\"] = booleanNoDefault; + result[\\"floatNoDefault\\"] = floatNoDefault; result[\\"image\\"] = ::facebook::react::toDynamic(image); result[\\"color\\"] = ::facebook::react::toDynamic(color); result[\\"point\\"] = ::facebook::react::toDynamic(point); @@ -474,6 +522,30 @@ struct AllPropWithOptionalGenObjectPrimitiveRequiredPropStruct { static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalGenObjectPrimitiveRequiredPropStruct &result) { auto map = (std::unordered_map)value; + auto tmp_string = map.find(\\"string\\"); + if (tmp_string != map.end()) { + fromRawValue(context, tmp_string->second, result.string); + } + auto tmp_boolean = map.find(\\"boolean\\"); + if (tmp_boolean != map.end()) { + fromRawValue(context, tmp_boolean->second, result.boolean); + } + auto tmp_float = map.find(\\"float\\"); + if (tmp_float != map.end()) { + fromRawValue(context, tmp_float->second, result.float); + } + auto tmp_stringNoDefault = map.find(\\"stringNoDefault\\"); + if (tmp_stringNoDefault != map.end()) { + fromRawValue(context, tmp_stringNoDefault->second, result.stringNoDefault); + } + auto tmp_booleanNoDefault = map.find(\\"booleanNoDefault\\"); + if (tmp_booleanNoDefault != map.end()) { + fromRawValue(context, tmp_booleanNoDefault->second, result.booleanNoDefault); + } + auto tmp_floatNoDefault = map.find(\\"floatNoDefault\\"); + if (tmp_floatNoDefault != map.end()) { + fromRawValue(context, tmp_floatNoDefault->second, result.floatNoDefault); + } auto tmp_image = map.find(\\"image\\"); if (tmp_image != map.end()) { fromRawValue(context, tmp_image->second, result.image); @@ -675,6 +747,397 @@ class AllPropWithOptionalGenProps final : public ViewProps { #endif +}; + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsH can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsH.js + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook::react { + +enum class AllPropWithOptionalObjectGenStringEnumProp { Option1 }; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenStringEnumProp &result) { + auto string = (std::string)value; + if (string == \\"option1\\") { result = AllPropWithOptionalObjectGenStringEnumProp::Option1; return; } + abort(); +} + +static inline std::string toString(const AllPropWithOptionalObjectGenStringEnumProp &value) { + switch (value) { + case AllPropWithOptionalObjectGenStringEnumProp::Option1: return \\"option1\\"; + default: + abort(); + } +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenStringEnumProp &value) { + return toString(value); +} +#endif +enum class AllPropWithOptionalObjectGenIntEnumProp { IntEnumProp0 = 0 }; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenIntEnumProp &result) { + assert(value.hasType()); + auto integerValue = (int)value; + switch (integerValue) { + case 0: + result = AllPropWithOptionalObjectGenIntEnumProp::IntEnumProp0; + return; + default: + abort(); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenIntEnumProp &value) { + switch (value) { + case AllPropWithOptionalObjectGenIntEnumProp::IntEnumProp0: return \\"0\\"; + default: + abort(); + } +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenIntEnumProp &value) { + switch (value) { + case AllPropWithOptionalObjectGenIntEnumProp::IntEnumProp0: return 0; + default: + abort(); + } +} +#endif +struct AllPropWithOptionalObjectGenObjectArrayPropStruct { + std::optional> array{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const AllPropWithOptionalObjectGenObjectArrayPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + if (array.has_value()) { + result[\\"array\\"] = ::facebook::react::toDynamic(array.value()); + } + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenObjectArrayPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_array = map.find(\\"array\\"); + if (tmp_array != map.end()) { + fromRawValue(context, tmp_array->second, result.array); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenObjectArrayPropStruct &value) { + return \\"[Object AllPropWithOptionalObjectGenObjectArrayPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenObjectArrayPropStruct &value) { + return value.toDynamic(); +} +#endif + +struct AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct { + std::string string{std::string{\\"defaultString\\"}}; + bool boolean{false}; + Float float{3.14}; + std::optional stringNoDefault{}; + std::optional booleanNoDefault{}; + std::optional floatNoDefault{}; + std::optional image{}; + std::optional color{}; + std::optional point{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"string\\"] = string; + result[\\"boolean\\"] = boolean; + result[\\"float\\"] = float; + if (stringNoDefault.has_value()) { + result[\\"stringNoDefault\\"] = stringNoDefault.value(); + } + if (booleanNoDefault.has_value()) { + result[\\"booleanNoDefault\\"] = booleanNoDefault.value(); + } + if (floatNoDefault.has_value()) { + result[\\"floatNoDefault\\"] = floatNoDefault.value(); + } + if (image.has_value()) { + result[\\"image\\"] = ::facebook::react::toDynamic(image.value()); + } + if (color.has_value()) { + result[\\"color\\"] = ::facebook::react::toDynamic(color.value()); + } + if (point.has_value()) { + result[\\"point\\"] = ::facebook::react::toDynamic(point.value()); + } + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_string = map.find(\\"string\\"); + if (tmp_string != map.end()) { + fromRawValue(context, tmp_string->second, result.string); + } + auto tmp_boolean = map.find(\\"boolean\\"); + if (tmp_boolean != map.end()) { + fromRawValue(context, tmp_boolean->second, result.boolean); + } + auto tmp_float = map.find(\\"float\\"); + if (tmp_float != map.end()) { + fromRawValue(context, tmp_float->second, result.float); + } + auto tmp_stringNoDefault = map.find(\\"stringNoDefault\\"); + if (tmp_stringNoDefault != map.end()) { + fromRawValue(context, tmp_stringNoDefault->second, result.stringNoDefault); + } + auto tmp_booleanNoDefault = map.find(\\"booleanNoDefault\\"); + if (tmp_booleanNoDefault != map.end()) { + fromRawValue(context, tmp_booleanNoDefault->second, result.booleanNoDefault); + } + auto tmp_floatNoDefault = map.find(\\"floatNoDefault\\"); + if (tmp_floatNoDefault != map.end()) { + fromRawValue(context, tmp_floatNoDefault->second, result.floatNoDefault); + } + auto tmp_image = map.find(\\"image\\"); + if (tmp_image != map.end()) { + fromRawValue(context, tmp_image->second, result.image); + } + auto tmp_color = map.find(\\"color\\"); + if (tmp_color != map.end()) { + fromRawValue(context, tmp_color->second, result.color); + } + auto tmp_point = map.find(\\"point\\"); + if (tmp_point != map.end()) { + fromRawValue(context, tmp_point->second, result.point); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct &value) { + return \\"[Object AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct &value) { + return value.toDynamic(); +} +#endif + +struct AllPropWithOptionalObjectGenNestedPropANestedPropBStruct { + std::string nestedPropC{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const AllPropWithOptionalObjectGenNestedPropANestedPropBStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"nestedPropC\\"] = nestedPropC; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenNestedPropANestedPropBStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_nestedPropC = map.find(\\"nestedPropC\\"); + if (tmp_nestedPropC != map.end()) { + fromRawValue(context, tmp_nestedPropC->second, result.nestedPropC); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenNestedPropANestedPropBStruct &value) { + return \\"[Object AllPropWithOptionalObjectGenNestedPropANestedPropBStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenNestedPropANestedPropBStruct &value) { + return value.toDynamic(); +} +#endif + +struct AllPropWithOptionalObjectGenNestedPropAStruct { + AllPropWithOptionalObjectGenNestedPropANestedPropBStruct nestedPropB{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const AllPropWithOptionalObjectGenNestedPropAStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"nestedPropB\\"] = ::facebook::react::toDynamic(nestedPropB); + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenNestedPropAStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_nestedPropB = map.find(\\"nestedPropB\\"); + if (tmp_nestedPropB != map.end()) { + fromRawValue(context, tmp_nestedPropB->second, result.nestedPropB); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenNestedPropAStruct &value) { + return \\"[Object AllPropWithOptionalObjectGenNestedPropAStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenNestedPropAStruct &value) { + return value.toDynamic(); +} +#endif + +struct AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct { + std::string stringProp{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"stringProp\\"] = stringProp; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_stringProp = map.find(\\"stringProp\\"); + if (tmp_stringProp != map.end()) { + fromRawValue(context, tmp_stringProp->second, result.stringProp); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct &value) { + return \\"[Object AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + AllPropWithOptionalObjectGenNestedArrayAsPropertyArrayPropStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + + +struct AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct { + std::vector arrayProp{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"arrayProp\\"] = ::facebook::react::toDynamic(arrayProp); + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_arrayProp = map.find(\\"arrayProp\\"); + if (tmp_arrayProp != map.end()) { + fromRawValue(context, tmp_arrayProp->second, result.arrayProp); + } +} + +static inline std::string toString(const AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct &value) { + return \\"[Object AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct &value) { + return value.toDynamic(); +} +#endif +class AllPropWithOptionalObjectGenProps final : public ViewProps { + public: + AllPropWithOptionalObjectGenProps() = default; + AllPropWithOptionalObjectGenProps(const PropsParserContext& context, const AllPropWithOptionalObjectGenProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::optional stringPropNoDefault{}; + std::optional booleanPropNoDefault{}; + std::optional floatPropNoDefault{}; + std::string stringProp{std::string{\\"\\"}}; + bool booleanProp{false}; + Float floatProp{0.0}; + int intProp{0}; + std::string stringUserDefaultProp{std::string{\\"user_default\\"}}; + bool booleanUserDefaultProp{true}; + Float floatUserDefaultProp{3.14}; + int intUserDefaultProp{9999}; + AllPropWithOptionalObjectGenStringEnumProp stringEnumProp{AllPropWithOptionalObjectGenStringEnumProp::Option1}; + AllPropWithOptionalObjectGenIntEnumProp intEnumProp{AllPropWithOptionalObjectGenIntEnumProp::IntEnumProp0}; + AllPropWithOptionalObjectGenObjectArrayPropStruct objectArrayProp{}; + AllPropWithOptionalObjectGenObjectPrimitiveRequiredPropStruct objectPrimitiveRequiredProp{}; + AllPropWithOptionalObjectGenNestedPropAStruct nestedPropA{}; + AllPropWithOptionalObjectGenNestedArrayAsPropertyStruct nestedArrayAsProperty{}; + + #ifdef RN_SERIALIZABLE_STATE + ComponentName getDiffPropsImplementationTarget() const override; + + folly::dynamic getDiffProps(const Props* prevProps) const override; + #endif + + }; } // namespace facebook::react @@ -1110,14 +1573,14 @@ Map { namespace facebook::react { -struct ArrayPropsNativeComponentNativePrimitivesStruct { +struct ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct { std::vector colors{}; std::vector srcs{}; std::vector points{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ArrayPropsNativeComponentNativePrimitivesStruct&) const = default; + bool operator==(const ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -1129,7 +1592,7 @@ struct ArrayPropsNativeComponentNativePrimitivesStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentNativePrimitivesStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct &result) { auto map = (std::unordered_map)value; auto tmp_colors = map.find(\\"colors\\"); @@ -1146,33 +1609,142 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ArrayPropsNativeComponentNativePrimitivesStruct &value) { - return \\"[Object ArrayPropsNativeComponentNativePrimitivesStruct]\\"; +static inline std::string toString(const ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct &value) { + return \\"[Object ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ArrayPropsNativeComponentNativePrimitivesStruct &value) { +static inline folly::dynamic toDynamic(const ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct &value) { return value.toDynamic(); } #endif -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { auto items = (std::vector)value; for (const auto &item : items) { - ArrayPropsNativeComponentNativePrimitivesStruct newItem; + ArrayPropsOptionalGenNativeComponentNativePrimitivesStruct newItem; fromRawValue(context, item, newItem); result.emplace_back(newItem); } } -class ArrayPropsNativeComponentProps final : public ViewProps { +class ArrayPropsOptionalGenNativeComponentProps final : public ViewProps { public: - ArrayPropsNativeComponentProps() = default; - ArrayPropsNativeComponentProps(const PropsParserContext& context, const ArrayPropsNativeComponentProps &sourceProps, const RawProps &rawProps); + ArrayPropsOptionalGenNativeComponentProps() = default; + ArrayPropsOptionalGenNativeComponentProps(const PropsParserContext& context, const ArrayPropsOptionalGenNativeComponentProps &sourceProps, const RawProps &rawProps); #pragma mark - Props - std::optional> nativePrimitives{}; + std::optional> nativePrimitives{}; + + #ifdef RN_SERIALIZABLE_STATE + ComponentName getDiffPropsImplementationTarget() const override; + + folly::dynamic getDiffProps(const Props* prevProps) const override; + #endif + + +}; + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsH can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsH.js + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook::react { + +struct ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct { + std::optional> colors{}; + std::optional> srcs{}; + std::optional> points{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + if (colors.has_value()) { + result[\\"colors\\"] = ::facebook::react::toDynamic(colors.value()); + } + if (srcs.has_value()) { + result[\\"srcs\\"] = ::facebook::react::toDynamic(srcs.value()); + } + if (points.has_value()) { + result[\\"points\\"] = ::facebook::react::toDynamic(points.value()); + } + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_colors = map.find(\\"colors\\"); + if (tmp_colors != map.end()) { + fromRawValue(context, tmp_colors->second, result.colors); + } + auto tmp_srcs = map.find(\\"srcs\\"); + if (tmp_srcs != map.end()) { + fromRawValue(context, tmp_srcs->second, result.srcs); + } + auto tmp_points = map.find(\\"points\\"); + if (tmp_points != map.end()) { + fromRawValue(context, tmp_points->second, result.points); + } +} + +static inline std::string toString(const ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct &value) { + return \\"[Object ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + ArrayPropsOptionalObjectGenNativeComponentNativePrimitivesStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + +class ArrayPropsOptionalObjectGenNativeComponentProps final : public ViewProps { + public: + ArrayPropsOptionalObjectGenNativeComponentProps() = default; + ArrayPropsOptionalObjectGenNativeComponentProps(const PropsParserContext& context, const ArrayPropsOptionalObjectGenNativeComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::optional> nativePrimitives{}; #ifdef RN_SERIALIZABLE_STATE ComponentName getDiffPropsImplementationTarget() const override; @@ -1215,58 +1787,58 @@ Map { namespace facebook::react { -using ArrayPropsNativeComponentSizesMask = uint32_t; +using ArrayPropsWithOptionalGenNativeComponentSizesMask = uint32_t; -struct ArrayPropsNativeComponentSizesMaskWrapped { - ArrayPropsNativeComponentSizesMask value; +struct ArrayPropsWithOptionalGenNativeComponentSizesMaskWrapped { + ArrayPropsWithOptionalGenNativeComponentSizesMask value; }; -enum class ArrayPropsNativeComponentSizes: ArrayPropsNativeComponentSizesMask { +enum class ArrayPropsWithOptionalGenNativeComponentSizes: ArrayPropsWithOptionalGenNativeComponentSizesMask { Small = 1 << 0, Large = 1 << 1 }; constexpr bool operator&( - ArrayPropsNativeComponentSizesMask const lhs, - enum ArrayPropsNativeComponentSizes const rhs) { - return lhs & static_cast(rhs); + ArrayPropsWithOptionalGenNativeComponentSizesMask const lhs, + enum ArrayPropsWithOptionalGenNativeComponentSizes const rhs) { + return lhs & static_cast(rhs); } -constexpr ArrayPropsNativeComponentSizesMask operator|( - ArrayPropsNativeComponentSizesMask const lhs, - enum ArrayPropsNativeComponentSizes const rhs) { - return lhs | static_cast(rhs); +constexpr ArrayPropsWithOptionalGenNativeComponentSizesMask operator|( + ArrayPropsWithOptionalGenNativeComponentSizesMask const lhs, + enum ArrayPropsWithOptionalGenNativeComponentSizes const rhs) { + return lhs | static_cast(rhs); } constexpr void operator|=( - ArrayPropsNativeComponentSizesMask &lhs, - enum ArrayPropsNativeComponentSizes const rhs) { - lhs = lhs | static_cast(rhs); + ArrayPropsWithOptionalGenNativeComponentSizesMask &lhs, + enum ArrayPropsWithOptionalGenNativeComponentSizes const rhs) { + lhs = lhs | static_cast(rhs); } -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentSizesMaskWrapped &wrapped) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalGenNativeComponentSizesMaskWrapped &wrapped) { auto items = std::vector{value}; for (const auto &item : items) { if (item == \\"small\\") { - wrapped.value |= ArrayPropsNativeComponentSizes::Small; + wrapped.value |= ArrayPropsWithOptionalGenNativeComponentSizes::Small; continue; } if (item == \\"large\\") { - wrapped.value |= ArrayPropsNativeComponentSizes::Large; + wrapped.value |= ArrayPropsWithOptionalGenNativeComponentSizes::Large; continue; } abort(); } } -static inline std::string toString(const ArrayPropsNativeComponentSizesMaskWrapped &wrapped) { +static inline std::string toString(const ArrayPropsWithOptionalGenNativeComponentSizesMaskWrapped &wrapped) { auto result = std::string{}; auto separator = std::string{\\", \\"}; - if (wrapped.value & ArrayPropsNativeComponentSizes::Small) { + if (wrapped.value & ArrayPropsWithOptionalGenNativeComponentSizes::Small) { result += \\"small\\" + separator; } - if (wrapped.value & ArrayPropsNativeComponentSizes::Large) { + if (wrapped.value & ArrayPropsWithOptionalGenNativeComponentSizes::Large) { result += \\"large\\" + separator; } if (!result.empty()) { @@ -1274,12 +1846,12 @@ static inline std::string toString(const ArrayPropsNativeComponentSizesMaskWrapp } return result; } -struct ArrayPropsNativeComponentObjectStruct { +struct ArrayPropsWithOptionalGenNativeComponentObjectStruct { std::string stringProp{std::string{\\"\\"}}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ArrayPropsNativeComponentObjectStruct&) const = default; + bool operator==(const ArrayPropsWithOptionalGenNativeComponentObjectStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -1289,7 +1861,7 @@ struct ArrayPropsNativeComponentObjectStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentObjectStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalGenNativeComponentObjectStruct &result) { auto map = (std::unordered_map)value; auto tmp_stringProp = map.find(\\"stringProp\\"); @@ -1298,32 +1870,32 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ArrayPropsNativeComponentObjectStruct &value) { - return \\"[Object ArrayPropsNativeComponentObjectStruct]\\"; +static inline std::string toString(const ArrayPropsWithOptionalGenNativeComponentObjectStruct &value) { + return \\"[Object ArrayPropsWithOptionalGenNativeComponentObjectStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ArrayPropsNativeComponentObjectStruct &value) { +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalGenNativeComponentObjectStruct &value) { return value.toDynamic(); } #endif -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { auto items = (std::vector)value; for (const auto &item : items) { - ArrayPropsNativeComponentObjectStruct newItem; + ArrayPropsWithOptionalGenNativeComponentObjectStruct newItem; fromRawValue(context, item, newItem); result.emplace_back(newItem); } } -struct ArrayPropsNativeComponentArrayObjectStruct { +struct ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct { std::string stringProp{std::string{\\"\\"}}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ArrayPropsNativeComponentArrayObjectStruct&) const = default; + bool operator==(const ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -1333,7 +1905,7 @@ struct ArrayPropsNativeComponentArrayObjectStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentArrayObjectStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct &result) { auto map = (std::unordered_map)value; auto tmp_stringProp = map.find(\\"stringProp\\"); @@ -1342,32 +1914,32 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ArrayPropsNativeComponentArrayObjectStruct &value) { - return \\"[Object ArrayPropsNativeComponentArrayObjectStruct]\\"; +static inline std::string toString(const ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct &value) { + return \\"[Object ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ArrayPropsNativeComponentArrayObjectStruct &value) { +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct &value) { return value.toDynamic(); } #endif -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { auto items = (std::vector)value; for (const auto &item : items) { - ArrayPropsNativeComponentArrayObjectStruct newItem; + ArrayPropsWithOptionalGenNativeComponentArrayObjectStruct newItem; fromRawValue(context, item, newItem); result.emplace_back(newItem); } } -struct ArrayPropsNativeComponentArrayStruct { - std::vector object{}; +struct ArrayPropsWithOptionalGenNativeComponentArrayStruct { + std::vector object{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ArrayPropsNativeComponentArrayStruct&) const = default; + bool operator==(const ArrayPropsWithOptionalGenNativeComponentArrayStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -1377,7 +1949,7 @@ struct ArrayPropsNativeComponentArrayStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentArrayStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalGenNativeComponentArrayStruct &result) { auto map = (std::unordered_map)value; auto tmp_object = map.find(\\"object\\"); @@ -1386,32 +1958,32 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ArrayPropsNativeComponentArrayStruct &value) { - return \\"[Object ArrayPropsNativeComponentArrayStruct]\\"; +static inline std::string toString(const ArrayPropsWithOptionalGenNativeComponentArrayStruct &value) { + return \\"[Object ArrayPropsWithOptionalGenNativeComponentArrayStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ArrayPropsNativeComponentArrayStruct &value) { +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalGenNativeComponentArrayStruct &value) { return value.toDynamic(); } #endif -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { auto items = (std::vector)value; for (const auto &item : items) { - ArrayPropsNativeComponentArrayStruct newItem; + ArrayPropsWithOptionalGenNativeComponentArrayStruct newItem; fromRawValue(context, item, newItem); result.emplace_back(newItem); } } -struct ArrayPropsNativeComponentArrayOfArrayOfObjectStruct { +struct ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct { std::string stringProp{std::string{\\"\\"}}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ArrayPropsNativeComponentArrayOfArrayOfObjectStruct&) const = default; + bool operator==(const ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -1421,7 +1993,7 @@ struct ArrayPropsNativeComponentArrayOfArrayOfObjectStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsNativeComponentArrayOfArrayOfObjectStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct &result) { auto map = (std::unordered_map)value; auto tmp_stringProp = map.find(\\"stringProp\\"); @@ -1430,22 +2002,22 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ArrayPropsNativeComponentArrayOfArrayOfObjectStruct &value) { - return \\"[Object ArrayPropsNativeComponentArrayOfArrayOfObjectStruct]\\"; +static inline std::string toString(const ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct &value) { + return \\"[Object ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ArrayPropsNativeComponentArrayOfArrayOfObjectStruct &value) { +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct &value) { return value.toDynamic(); } #endif -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector> &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector> &result) { auto items = (std::vector>)value; for (const std::vector &item : items) { - auto nestedArray = std::vector{}; + auto nestedArray = std::vector{}; for (const RawValue &nestedItem : item) { - ArrayPropsNativeComponentArrayOfArrayOfObjectStruct newItem; + ArrayPropsWithOptionalGenNativeComponentArrayOfArrayOfObjectStruct newItem; fromRawValue(context, nestedItem, newItem); nestedArray.emplace_back(newItem); } @@ -1453,10 +2025,10 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -class ArrayPropsNativeComponentProps final : public ViewProps { +class ArrayPropsWithOptionalGenNativeComponentProps final : public ViewProps { public: - ArrayPropsNativeComponentProps() = default; - ArrayPropsNativeComponentProps(const PropsParserContext& context, const ArrayPropsNativeComponentProps &sourceProps, const RawProps &rawProps); + ArrayPropsWithOptionalGenNativeComponentProps() = default; + ArrayPropsWithOptionalGenNativeComponentProps(const PropsParserContext& context, const ArrayPropsWithOptionalGenNativeComponentProps &sourceProps, const RawProps &rawProps); #pragma mark - Props @@ -1468,10 +2040,312 @@ class ArrayPropsNativeComponentProps final : public ViewProps { std::optional> srcs{}; std::optional> points{}; std::optional> dimensions{}; - std::optional sizes{static_cast(ArrayPropsNativeComponentSizes::Small)}; - std::optional> object{}; - std::optional> array{}; - std::optional>> arrayOfArrayOfObject{}; + std::optional sizes{static_cast(ArrayPropsWithOptionalGenNativeComponentSizes::Small)}; + std::optional> object{}; + std::optional> array{}; + std::optional>> arrayOfArrayOfObject{}; + std::optional> arrayOfMixed{}; + + #ifdef RN_SERIALIZABLE_STATE + ComponentName getDiffPropsImplementationTarget() const override; + + folly::dynamic getDiffProps(const Props* prevProps) const override; + #endif + + +}; + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsH can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsH.js + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook::react { + +using ArrayPropsWithOptionalObjectGenNativeComponentSizesMask = uint32_t; + +struct ArrayPropsWithOptionalObjectGenNativeComponentSizesMaskWrapped { + ArrayPropsWithOptionalObjectGenNativeComponentSizesMask value; +}; + +enum class ArrayPropsWithOptionalObjectGenNativeComponentSizes: ArrayPropsWithOptionalObjectGenNativeComponentSizesMask { + Small = 1 << 0, + Large = 1 << 1 +}; + +constexpr bool operator&( + ArrayPropsWithOptionalObjectGenNativeComponentSizesMask const lhs, + enum ArrayPropsWithOptionalObjectGenNativeComponentSizes const rhs) { + return lhs & static_cast(rhs); +} + +constexpr ArrayPropsWithOptionalObjectGenNativeComponentSizesMask operator|( + ArrayPropsWithOptionalObjectGenNativeComponentSizesMask const lhs, + enum ArrayPropsWithOptionalObjectGenNativeComponentSizes const rhs) { + return lhs | static_cast(rhs); +} + +constexpr void operator|=( + ArrayPropsWithOptionalObjectGenNativeComponentSizesMask &lhs, + enum ArrayPropsWithOptionalObjectGenNativeComponentSizes const rhs) { + lhs = lhs | static_cast(rhs); +} + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalObjectGenNativeComponentSizesMaskWrapped &wrapped) { + auto items = std::vector{value}; + for (const auto &item : items) { + if (item == \\"small\\") { + wrapped.value |= ArrayPropsWithOptionalObjectGenNativeComponentSizes::Small; + continue; + } + if (item == \\"large\\") { + wrapped.value |= ArrayPropsWithOptionalObjectGenNativeComponentSizes::Large; + continue; + } + abort(); + } +} + +static inline std::string toString(const ArrayPropsWithOptionalObjectGenNativeComponentSizesMaskWrapped &wrapped) { + auto result = std::string{}; + auto separator = std::string{\\", \\"}; + + if (wrapped.value & ArrayPropsWithOptionalObjectGenNativeComponentSizes::Small) { + result += \\"small\\" + separator; + } + if (wrapped.value & ArrayPropsWithOptionalObjectGenNativeComponentSizes::Large) { + result += \\"large\\" + separator; + } + if (!result.empty()) { + result.erase(result.length() - separator.length()); + } + return result; +} +struct ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct { + std::string stringProp{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"stringProp\\"] = stringProp; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_stringProp = map.find(\\"stringProp\\"); + if (tmp_stringProp != map.end()) { + fromRawValue(context, tmp_stringProp->second, result.stringProp); + } +} + +static inline std::string toString(const ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct &value) { + return \\"[Object ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + ArrayPropsWithOptionalObjectGenNativeComponentObjectStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + + +struct ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct { + std::string stringProp{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"stringProp\\"] = stringProp; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_stringProp = map.find(\\"stringProp\\"); + if (tmp_stringProp != map.end()) { + fromRawValue(context, tmp_stringProp->second, result.stringProp); + } +} + +static inline std::string toString(const ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct &value) { + return \\"[Object ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + ArrayPropsWithOptionalObjectGenNativeComponentArrayObjectStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + + +struct ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct { + std::optional> object{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + if (object.has_value()) { + result[\\"object\\"] = ::facebook::react::toDynamic(object.value()); + } + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_object = map.find(\\"object\\"); + if (tmp_object != map.end()) { + fromRawValue(context, tmp_object->second, result.object); + } +} + +static inline std::string toString(const ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct &value) { + return \\"[Object ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + ArrayPropsWithOptionalObjectGenNativeComponentArrayStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + + +struct ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct { + std::string stringProp{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"stringProp\\"] = stringProp; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_stringProp = map.find(\\"stringProp\\"); + if (tmp_stringProp != map.end()) { + fromRawValue(context, tmp_stringProp->second, result.stringProp); + } +} + +static inline std::string toString(const ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct &value) { + return \\"[Object ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector> &result) { + auto items = (std::vector>)value; + for (const std::vector &item : items) { + auto nestedArray = std::vector{}; + for (const RawValue &nestedItem : item) { + ArrayPropsWithOptionalObjectGenNativeComponentArrayOfArrayOfObjectStruct newItem; + fromRawValue(context, nestedItem, newItem); + nestedArray.emplace_back(newItem); + } + result.emplace_back(nestedArray); + } +} + +class ArrayPropsWithOptionalObjectGenNativeComponentProps final : public ViewProps { + public: + ArrayPropsWithOptionalObjectGenNativeComponentProps() = default; + ArrayPropsWithOptionalObjectGenNativeComponentProps(const PropsParserContext& context, const ArrayPropsWithOptionalObjectGenNativeComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::optional> names{}; + std::optional> disableds{}; + std::optional> progress{}; + std::optional> radii{}; + std::optional> colors{}; + std::optional> srcs{}; + std::optional> points{}; + std::optional> dimensions{}; + std::optional sizes{static_cast(ArrayPropsWithOptionalObjectGenNativeComponentSizes::Small)}; + std::optional> object{}; + std::optional> array{}; + std::optional>> arrayOfArrayOfObject{}; std::optional> arrayOfMixed{}; #ifdef RN_SERIALIZABLE_STATE @@ -2915,64 +3789,64 @@ Map { namespace facebook::react { -enum class ObjectPropsStringEnumProp { Option1 }; +enum class ObjectPropsWithOptionalGenStringEnumProp { Option1 }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsStringEnumProp &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenStringEnumProp &result) { auto string = (std::string)value; - if (string == \\"option1\\") { result = ObjectPropsStringEnumProp::Option1; return; } + if (string == \\"option1\\") { result = ObjectPropsWithOptionalGenStringEnumProp::Option1; return; } abort(); } -static inline std::string toString(const ObjectPropsStringEnumProp &value) { +static inline std::string toString(const ObjectPropsWithOptionalGenStringEnumProp &value) { switch (value) { - case ObjectPropsStringEnumProp::Option1: return \\"option1\\"; + case ObjectPropsWithOptionalGenStringEnumProp::Option1: return \\"option1\\"; default: abort(); } } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsStringEnumProp &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenStringEnumProp &value) { return toString(value); } #endif -enum class ObjectPropsIntEnumProp { IntEnumProp0 = 0 }; +enum class ObjectPropsWithOptionalGenIntEnumProp { IntEnumProp0 = 0 }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsIntEnumProp &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenIntEnumProp &result) { assert(value.hasType()); auto integerValue = (int)value; switch (integerValue) { case 0: - result = ObjectPropsIntEnumProp::IntEnumProp0; + result = ObjectPropsWithOptionalGenIntEnumProp::IntEnumProp0; return; default: abort(); } } -static inline std::string toString(const ObjectPropsIntEnumProp &value) { +static inline std::string toString(const ObjectPropsWithOptionalGenIntEnumProp &value) { switch (value) { - case ObjectPropsIntEnumProp::IntEnumProp0: return \\"0\\"; + case ObjectPropsWithOptionalGenIntEnumProp::IntEnumProp0: return \\"0\\"; default: abort(); } } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsIntEnumProp &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenIntEnumProp &value) { switch (value) { - case ObjectPropsIntEnumProp::IntEnumProp0: return 0; + case ObjectPropsWithOptionalGenIntEnumProp::IntEnumProp0: return 0; default: abort(); } } #endif -struct ObjectPropsObjectPropObjectArrayPropStruct { +struct ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct { std::vector array{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropObjectArrayPropStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -2982,7 +3856,7 @@ struct ObjectPropsObjectPropObjectArrayPropStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropObjectArrayPropStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct &result) { auto map = (std::unordered_map)value; auto tmp_array = map.find(\\"array\\"); @@ -2991,24 +3865,24 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropObjectArrayPropStruct &value) { - return \\"[Object ObjectPropsObjectPropObjectArrayPropStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropObjectArrayPropStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct &value) { return value.toDynamic(); } #endif -struct ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct { +struct ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct { ImageSource image{}; SharedColor color{}; Point point{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -3020,7 +3894,7 @@ struct ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct &result) { auto map = (std::unordered_map)value; auto tmp_image = map.find(\\"image\\"); @@ -3037,22 +3911,22 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct &value) { - return \\"[Object ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct &value) { return value.toDynamic(); } #endif -struct ObjectPropsObjectPropNestedPropANestedPropBStruct { +struct ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct { std::string nestedPropC{std::string{\\"\\"}}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropNestedPropANestedPropBStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -3062,7 +3936,7 @@ struct ObjectPropsObjectPropNestedPropANestedPropBStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropNestedPropANestedPropBStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct &result) { auto map = (std::unordered_map)value; auto tmp_nestedPropC = map.find(\\"nestedPropC\\"); @@ -3071,22 +3945,22 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropNestedPropANestedPropBStruct &value) { - return \\"[Object ObjectPropsObjectPropNestedPropANestedPropBStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropNestedPropANestedPropBStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct &value) { return value.toDynamic(); } #endif -struct ObjectPropsObjectPropNestedPropAStruct { - ObjectPropsObjectPropNestedPropANestedPropBStruct nestedPropB{}; +struct ObjectPropsWithOptionalGenObjectPropNestedPropAStruct { + ObjectPropsWithOptionalGenObjectPropNestedPropANestedPropBStruct nestedPropB{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropNestedPropAStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropNestedPropAStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -3096,7 +3970,7 @@ struct ObjectPropsObjectPropNestedPropAStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropNestedPropAStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropNestedPropAStruct &result) { auto map = (std::unordered_map)value; auto tmp_nestedPropB = map.find(\\"nestedPropB\\"); @@ -3105,22 +3979,22 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropNestedPropAStruct &value) { - return \\"[Object ObjectPropsObjectPropNestedPropAStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropNestedPropAStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropNestedPropAStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropNestedPropAStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropNestedPropAStruct &value) { return value.toDynamic(); } #endif -struct ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct { +struct ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct { std::string stringProp{std::string{\\"\\"}}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -3130,7 +4004,7 @@ struct ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct &result) { auto map = (std::unordered_map)value; auto tmp_stringProp = map.find(\\"stringProp\\"); @@ -3139,32 +4013,32 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct &value) { - return \\"[Object ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct &value) { return value.toDynamic(); } #endif -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { auto items = (std::vector)value; for (const auto &item : items) { - ObjectPropsObjectPropNestedArrayAsPropertyArrayPropStruct newItem; + ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyArrayPropStruct newItem; fromRawValue(context, item, newItem); result.emplace_back(newItem); } } -struct ObjectPropsObjectPropNestedArrayAsPropertyStruct { - std::vector arrayProp{}; +struct ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct { + std::vector arrayProp{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropNestedArrayAsPropertyStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -3174,7 +4048,7 @@ struct ObjectPropsObjectPropNestedArrayAsPropertyStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropNestedArrayAsPropertyStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct &result) { auto map = (std::unordered_map)value; auto tmp_arrayProp = map.find(\\"arrayProp\\"); @@ -3183,17 +4057,17 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropNestedArrayAsPropertyStruct &value) { - return \\"[Object ObjectPropsObjectPropNestedArrayAsPropertyStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropNestedArrayAsPropertyStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct &value) { return value.toDynamic(); } #endif -struct ObjectPropsObjectPropStruct { +struct ObjectPropsWithOptionalGenObjectPropStruct { std::string stringProp{std::string{\\"\\"}}; bool booleanProp{false}; Float floatProp{0.0}; @@ -3202,16 +4076,16 @@ struct ObjectPropsObjectPropStruct { bool booleanUserDefaultProp{true}; Float floatUserDefaultProp{3.14}; int intUserDefaultProp{9999}; - ObjectPropsStringEnumProp stringEnumProp{ObjectPropsStringEnumProp::Option1}; - ObjectPropsIntEnumProp intEnumProp{ObjectPropsIntEnumProp::IntEnumProp0}; - ObjectPropsObjectPropObjectArrayPropStruct objectArrayProp{}; - ObjectPropsObjectPropObjectPrimitiveRequiredPropStruct objectPrimitiveRequiredProp{}; - ObjectPropsObjectPropNestedPropAStruct nestedPropA{}; - ObjectPropsObjectPropNestedArrayAsPropertyStruct nestedArrayAsProperty{}; + ObjectPropsWithOptionalGenStringEnumProp stringEnumProp{ObjectPropsWithOptionalGenStringEnumProp::Option1}; + ObjectPropsWithOptionalGenIntEnumProp intEnumProp{ObjectPropsWithOptionalGenIntEnumProp::IntEnumProp0}; + ObjectPropsWithOptionalGenObjectPropObjectArrayPropStruct objectArrayProp{}; + ObjectPropsWithOptionalGenObjectPropObjectPrimitiveRequiredPropStruct objectPrimitiveRequiredProp{}; + ObjectPropsWithOptionalGenObjectPropNestedPropAStruct nestedPropA{}; + ObjectPropsWithOptionalGenObjectPropNestedArrayAsPropertyStruct nestedArrayAsProperty{}; #ifdef RN_SERIALIZABLE_STATE - bool operator==(const ObjectPropsObjectPropStruct&) const = default; + bool operator==(const ObjectPropsWithOptionalGenObjectPropStruct&) const = default; folly::dynamic toDynamic() const { folly::dynamic result = folly::dynamic::object(); @@ -3234,7 +4108,7 @@ struct ObjectPropsObjectPropStruct { #endif }; -static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsObjectPropStruct &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalGenObjectPropStruct &result) { auto map = (std::unordered_map)value; auto tmp_stringProp = map.find(\\"stringProp\\"); @@ -3295,23 +4169,468 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -static inline std::string toString(const ObjectPropsObjectPropStruct &value) { - return \\"[Object ObjectPropsObjectPropStruct]\\"; +static inline std::string toString(const ObjectPropsWithOptionalGenObjectPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalGenObjectPropStruct]\\"; } #ifdef RN_SERIALIZABLE_STATE -static inline folly::dynamic toDynamic(const ObjectPropsObjectPropStruct &value) { +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalGenObjectPropStruct &value) { return value.toDynamic(); } #endif -class ObjectPropsProps final : public ViewProps { +class ObjectPropsWithOptionalGenProps final : public ViewProps { public: - ObjectPropsProps() = default; - ObjectPropsProps(const PropsParserContext& context, const ObjectPropsProps &sourceProps, const RawProps &rawProps); + ObjectPropsWithOptionalGenProps() = default; + ObjectPropsWithOptionalGenProps(const PropsParserContext& context, const ObjectPropsWithOptionalGenProps &sourceProps, const RawProps &rawProps); #pragma mark - Props - std::optional objectProp{}; + std::optional objectProp{}; + + #ifdef RN_SERIALIZABLE_STATE + ComponentName getDiffPropsImplementationTarget() const override; + + folly::dynamic getDiffProps(const Props* prevProps) const override; + #endif + + +}; + +} // namespace facebook::react +", +} +`; + +exports[`GeneratePropsH can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Props.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GeneratePropsH.js + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook::react { + +enum class ObjectPropsWithOptionalObjectGenStringEnumProp { Option1 }; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenStringEnumProp &result) { + auto string = (std::string)value; + if (string == \\"option1\\") { result = ObjectPropsWithOptionalObjectGenStringEnumProp::Option1; return; } + abort(); +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenStringEnumProp &value) { + switch (value) { + case ObjectPropsWithOptionalObjectGenStringEnumProp::Option1: return \\"option1\\"; + default: + abort(); + } +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenStringEnumProp &value) { + return toString(value); +} +#endif +enum class ObjectPropsWithOptionalObjectGenIntEnumProp { IntEnumProp0 = 0 }; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenIntEnumProp &result) { + assert(value.hasType()); + auto integerValue = (int)value; + switch (integerValue) { + case 0: + result = ObjectPropsWithOptionalObjectGenIntEnumProp::IntEnumProp0; + return; + default: + abort(); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenIntEnumProp &value) { + switch (value) { + case ObjectPropsWithOptionalObjectGenIntEnumProp::IntEnumProp0: return \\"0\\"; + default: + abort(); + } +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenIntEnumProp &value) { + switch (value) { + case ObjectPropsWithOptionalObjectGenIntEnumProp::IntEnumProp0: return 0; + default: + abort(); + } +} +#endif +struct ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct { + std::optional> array{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + if (array.has_value()) { + result[\\"array\\"] = ::facebook::react::toDynamic(array.value()); + } + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_array = map.find(\\"array\\"); + if (tmp_array != map.end()) { + fromRawValue(context, tmp_array->second, result.array); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct &value) { + return value.toDynamic(); +} +#endif + +struct ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct { + std::optional image{}; + std::optional color{}; + std::optional point{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + if (image.has_value()) { + result[\\"image\\"] = ::facebook::react::toDynamic(image.value()); + } + if (color.has_value()) { + result[\\"color\\"] = ::facebook::react::toDynamic(color.value()); + } + if (point.has_value()) { + result[\\"point\\"] = ::facebook::react::toDynamic(point.value()); + } + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_image = map.find(\\"image\\"); + if (tmp_image != map.end()) { + fromRawValue(context, tmp_image->second, result.image); + } + auto tmp_color = map.find(\\"color\\"); + if (tmp_color != map.end()) { + fromRawValue(context, tmp_color->second, result.color); + } + auto tmp_point = map.find(\\"point\\"); + if (tmp_point != map.end()) { + fromRawValue(context, tmp_point->second, result.point); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct &value) { + return value.toDynamic(); +} +#endif + +struct ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct { + std::string nestedPropC{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"nestedPropC\\"] = nestedPropC; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_nestedPropC = map.find(\\"nestedPropC\\"); + if (tmp_nestedPropC != map.end()) { + fromRawValue(context, tmp_nestedPropC->second, result.nestedPropC); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct &value) { + return value.toDynamic(); +} +#endif + +struct ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct { + ObjectPropsWithOptionalObjectGenObjectPropNestedPropANestedPropBStruct nestedPropB{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"nestedPropB\\"] = ::facebook::react::toDynamic(nestedPropB); + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_nestedPropB = map.find(\\"nestedPropB\\"); + if (tmp_nestedPropB != map.end()) { + fromRawValue(context, tmp_nestedPropB->second, result.nestedPropB); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct &value) { + return value.toDynamic(); +} +#endif + +struct ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct { + std::string stringProp{std::string{\\"\\"}}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"stringProp\\"] = stringProp; + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_stringProp = map.find(\\"stringProp\\"); + if (tmp_stringProp != map.end()) { + fromRawValue(context, tmp_stringProp->second, result.stringProp); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct &value) { + return value.toDynamic(); +} +#endif + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector &result) { + auto items = (std::vector)value; + for (const auto &item : items) { + ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyArrayPropStruct newItem; + fromRawValue(context, item, newItem); + result.emplace_back(newItem); + } +} + + +struct ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct { + std::vector arrayProp{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"arrayProp\\"] = ::facebook::react::toDynamic(arrayProp); + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_arrayProp = map.find(\\"arrayProp\\"); + if (tmp_arrayProp != map.end()) { + fromRawValue(context, tmp_arrayProp->second, result.arrayProp); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct &value) { + return value.toDynamic(); +} +#endif + +struct ObjectPropsWithOptionalObjectGenObjectPropStruct { + std::string stringProp{std::string{\\"\\"}}; + bool booleanProp{false}; + Float floatProp{0.0}; + int intProp{0}; + std::string stringUserDefaultProp{std::string{\\"user_default\\"}}; + bool booleanUserDefaultProp{true}; + Float floatUserDefaultProp{3.14}; + int intUserDefaultProp{9999}; + ObjectPropsWithOptionalObjectGenStringEnumProp stringEnumProp{ObjectPropsWithOptionalObjectGenStringEnumProp::Option1}; + ObjectPropsWithOptionalObjectGenIntEnumProp intEnumProp{ObjectPropsWithOptionalObjectGenIntEnumProp::IntEnumProp0}; + ObjectPropsWithOptionalObjectGenObjectPropObjectArrayPropStruct objectArrayProp{}; + ObjectPropsWithOptionalObjectGenObjectPropObjectPrimitiveRequiredPropStruct objectPrimitiveRequiredProp{}; + ObjectPropsWithOptionalObjectGenObjectPropNestedPropAStruct nestedPropA{}; + ObjectPropsWithOptionalObjectGenObjectPropNestedArrayAsPropertyStruct nestedArrayAsProperty{}; + + +#ifdef RN_SERIALIZABLE_STATE + bool operator==(const ObjectPropsWithOptionalObjectGenObjectPropStruct&) const = default; + + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result[\\"stringProp\\"] = stringProp; + result[\\"booleanProp\\"] = booleanProp; + result[\\"floatProp\\"] = floatProp; + result[\\"intProp\\"] = intProp; + result[\\"stringUserDefaultProp\\"] = stringUserDefaultProp; + result[\\"booleanUserDefaultProp\\"] = booleanUserDefaultProp; + result[\\"floatUserDefaultProp\\"] = floatUserDefaultProp; + result[\\"intUserDefaultProp\\"] = intUserDefaultProp; + result[\\"stringEnumProp\\"] = ::facebook::react::toDynamic(stringEnumProp); + result[\\"intEnumProp\\"] = ::facebook::react::toDynamic(intEnumProp); + result[\\"objectArrayProp\\"] = ::facebook::react::toDynamic(objectArrayProp); + result[\\"objectPrimitiveRequiredProp\\"] = ::facebook::react::toDynamic(objectPrimitiveRequiredProp); + result[\\"nestedPropA\\"] = ::facebook::react::toDynamic(nestedPropA); + result[\\"nestedArrayAsProperty\\"] = ::facebook::react::toDynamic(nestedArrayAsProperty); + return result; + } +#endif +}; + +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ObjectPropsWithOptionalObjectGenObjectPropStruct &result) { + auto map = (std::unordered_map)value; + + auto tmp_stringProp = map.find(\\"stringProp\\"); + if (tmp_stringProp != map.end()) { + fromRawValue(context, tmp_stringProp->second, result.stringProp); + } + auto tmp_booleanProp = map.find(\\"booleanProp\\"); + if (tmp_booleanProp != map.end()) { + fromRawValue(context, tmp_booleanProp->second, result.booleanProp); + } + auto tmp_floatProp = map.find(\\"floatProp\\"); + if (tmp_floatProp != map.end()) { + fromRawValue(context, tmp_floatProp->second, result.floatProp); + } + auto tmp_intProp = map.find(\\"intProp\\"); + if (tmp_intProp != map.end()) { + fromRawValue(context, tmp_intProp->second, result.intProp); + } + auto tmp_stringUserDefaultProp = map.find(\\"stringUserDefaultProp\\"); + if (tmp_stringUserDefaultProp != map.end()) { + fromRawValue(context, tmp_stringUserDefaultProp->second, result.stringUserDefaultProp); + } + auto tmp_booleanUserDefaultProp = map.find(\\"booleanUserDefaultProp\\"); + if (tmp_booleanUserDefaultProp != map.end()) { + fromRawValue(context, tmp_booleanUserDefaultProp->second, result.booleanUserDefaultProp); + } + auto tmp_floatUserDefaultProp = map.find(\\"floatUserDefaultProp\\"); + if (tmp_floatUserDefaultProp != map.end()) { + fromRawValue(context, tmp_floatUserDefaultProp->second, result.floatUserDefaultProp); + } + auto tmp_intUserDefaultProp = map.find(\\"intUserDefaultProp\\"); + if (tmp_intUserDefaultProp != map.end()) { + fromRawValue(context, tmp_intUserDefaultProp->second, result.intUserDefaultProp); + } + auto tmp_stringEnumProp = map.find(\\"stringEnumProp\\"); + if (tmp_stringEnumProp != map.end()) { + fromRawValue(context, tmp_stringEnumProp->second, result.stringEnumProp); + } + auto tmp_intEnumProp = map.find(\\"intEnumProp\\"); + if (tmp_intEnumProp != map.end()) { + fromRawValue(context, tmp_intEnumProp->second, result.intEnumProp); + } + auto tmp_objectArrayProp = map.find(\\"objectArrayProp\\"); + if (tmp_objectArrayProp != map.end()) { + fromRawValue(context, tmp_objectArrayProp->second, result.objectArrayProp); + } + auto tmp_objectPrimitiveRequiredProp = map.find(\\"objectPrimitiveRequiredProp\\"); + if (tmp_objectPrimitiveRequiredProp != map.end()) { + fromRawValue(context, tmp_objectPrimitiveRequiredProp->second, result.objectPrimitiveRequiredProp); + } + auto tmp_nestedPropA = map.find(\\"nestedPropA\\"); + if (tmp_nestedPropA != map.end()) { + fromRawValue(context, tmp_nestedPropA->second, result.nestedPropA); + } + auto tmp_nestedArrayAsProperty = map.find(\\"nestedArrayAsProperty\\"); + if (tmp_nestedArrayAsProperty != map.end()) { + fromRawValue(context, tmp_nestedArrayAsProperty->second, result.nestedArrayAsProperty); + } +} + +static inline std::string toString(const ObjectPropsWithOptionalObjectGenObjectPropStruct &value) { + return \\"[Object ObjectPropsWithOptionalObjectGenObjectPropStruct]\\"; +} + +#ifdef RN_SERIALIZABLE_STATE +static inline folly::dynamic toDynamic(const ObjectPropsWithOptionalObjectGenObjectPropStruct &value) { + return value.toDynamic(); +} +#endif +class ObjectPropsWithOptionalObjectGenProps final : public ViewProps { + public: + ObjectPropsWithOptionalObjectGenProps() = default; + ObjectPropsWithOptionalObjectGenProps(const PropsParserContext& context, const ObjectPropsWithOptionalObjectGenProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::optional objectProp{}; #ifdef RN_SERIALIZABLE_STATE ComponentName getDiffPropsImplementationTarget() const override; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap index ccb712e66c5..d75596b7c43 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaDelegate-test.js.snap @@ -176,6 +176,94 @@ public class AllPropWithOptionalGenManagerDelegate "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.BaseViewManager; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.LayoutShadowNode; + +@SuppressWarnings(\\"deprecation\\") +public class AllPropWithOptionalObjectGenManagerDelegate & AllPropWithOptionalObjectGenManagerInterface> extends BaseViewManagerDelegate { + public AllPropWithOptionalObjectGenManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case \\"stringPropNoDefault\\": + mViewManager.setStringPropNoDefault(view, value == null ? null : (String) value); + break; + case \\"booleanPropNoDefault\\": + mViewManager.setBooleanPropNoDefault(view, value == null ? null : (Boolean) value); + break; + case \\"floatPropNoDefault\\": + mViewManager.setFloatPropNoDefault(view, value == null ? null : ((Double) value).floatValue()); + break; + case \\"stringProp\\": + mViewManager.setStringProp(view, value == null ? \\"\\" : (String) value); + break; + case \\"booleanProp\\": + mViewManager.setBooleanProp(view, value == null ? false : (boolean) value); + break; + case \\"floatProp\\": + mViewManager.setFloatProp(view, value == null ? 0f : ((Double) value).floatValue()); + break; + case \\"intProp\\": + mViewManager.setIntProp(view, value == null ? 0 : ((Double) value).intValue()); + break; + case \\"stringUserDefaultProp\\": + mViewManager.setStringUserDefaultProp(view, value == null ? \\"user_default\\" : (String) value); + break; + case \\"booleanUserDefaultProp\\": + mViewManager.setBooleanUserDefaultProp(view, value == null ? true : (boolean) value); + break; + case \\"floatUserDefaultProp\\": + mViewManager.setFloatUserDefaultProp(view, value == null ? 3.14f : ((Double) value).floatValue()); + break; + case \\"intUserDefaultProp\\": + mViewManager.setIntUserDefaultProp(view, value == null ? 9999 : ((Double) value).intValue()); + break; + case \\"stringEnumProp\\": + mViewManager.setStringEnumProp(view, (String) value); + break; + case \\"intEnumProp\\": + mViewManager.setIntEnumProp(view, value == null ? 0 : ((Double) value).intValue()); + break; + case \\"objectArrayProp\\": + mViewManager.setObjectArrayProp(view, (ReadableMap) value); + break; + case \\"objectPrimitiveRequiredProp\\": + mViewManager.setObjectPrimitiveRequiredProp(view, (ReadableMap) value); + break; + case \\"nestedPropA\\": + mViewManager.setNestedPropA(view, (ReadableMap) value); + break; + case \\"nestedArrayAsProperty\\": + mViewManager.setNestedArrayAsProperty(view, (ReadableMap) value); + break; + default: + super.setProperty(view, propName, value); + } + } +} +", +} +`; + exports[`GeneratePropsJavaDelegate can generate fixture ARRAY_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/ArrayPropsNativeComponentManagerDelegate.java" => "/** @@ -294,7 +382,7 @@ public class ArrayPropsNativeComponentManagerDelegate "/** + "java/com/facebook/react/viewmanagers/ArrayPropsOptionalGenNativeComponentManagerDelegate.java" => "/** * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). * * Do not edit this file as changes may cause incorrect behavior and will be lost @@ -313,8 +401,48 @@ import com.facebook.react.uimanager.BaseViewManagerDelegate; import com.facebook.react.uimanager.LayoutShadowNode; @SuppressWarnings(\\"deprecation\\") -public class ArrayPropsNativeComponentManagerDelegate & ArrayPropsNativeComponentManagerInterface> extends BaseViewManagerDelegate { - public ArrayPropsNativeComponentManagerDelegate(U viewManager) { +public class ArrayPropsOptionalGenNativeComponentManagerDelegate & ArrayPropsOptionalGenNativeComponentManagerInterface> extends BaseViewManagerDelegate { + public ArrayPropsOptionalGenNativeComponentManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case \\"nativePrimitives\\": + mViewManager.setNativePrimitives(view, (ReadableArray) value); + break; + default: + super.setProperty(view, propName, value); + } + } +} +", +} +`; + +exports[`GeneratePropsJavaDelegate can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ArrayPropsOptionalObjectGenNativeComponentManagerDelegate.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.uimanager.BaseViewManager; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.LayoutShadowNode; + +@SuppressWarnings(\\"deprecation\\") +public class ArrayPropsOptionalObjectGenNativeComponentManagerDelegate & ArrayPropsOptionalObjectGenNativeComponentManagerInterface> extends BaseViewManagerDelegate { + public ArrayPropsOptionalObjectGenNativeComponentManagerDelegate(U viewManager) { super(viewManager); } @Override @@ -334,7 +462,7 @@ public class ArrayPropsNativeComponentManagerDelegate "/** + "java/com/facebook/react/viewmanagers/ArrayPropsWithOptionalGenNativeComponentManagerDelegate.java" => "/** * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). * * Do not edit this file as changes may cause incorrect behavior and will be lost @@ -353,8 +481,84 @@ import com.facebook.react.uimanager.BaseViewManagerDelegate; import com.facebook.react.uimanager.LayoutShadowNode; @SuppressWarnings(\\"deprecation\\") -public class ArrayPropsNativeComponentManagerDelegate & ArrayPropsNativeComponentManagerInterface> extends BaseViewManagerDelegate { - public ArrayPropsNativeComponentManagerDelegate(U viewManager) { +public class ArrayPropsWithOptionalGenNativeComponentManagerDelegate & ArrayPropsWithOptionalGenNativeComponentManagerInterface> extends BaseViewManagerDelegate { + public ArrayPropsWithOptionalGenNativeComponentManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case \\"names\\": + mViewManager.setNames(view, (ReadableArray) value); + break; + case \\"disableds\\": + mViewManager.setDisableds(view, (ReadableArray) value); + break; + case \\"progress\\": + mViewManager.setProgress(view, (ReadableArray) value); + break; + case \\"radii\\": + mViewManager.setRadii(view, (ReadableArray) value); + break; + case \\"colors\\": + mViewManager.setColors(view, (ReadableArray) value); + break; + case \\"srcs\\": + mViewManager.setSrcs(view, (ReadableArray) value); + break; + case \\"points\\": + mViewManager.setPoints(view, (ReadableArray) value); + break; + case \\"dimensions\\": + mViewManager.setDimensions(view, (ReadableArray) value); + break; + case \\"sizes\\": + mViewManager.setSizes(view, (ReadableArray) value); + break; + case \\"object\\": + mViewManager.setObject(view, (ReadableArray) value); + break; + case \\"array\\": + mViewManager.setArray(view, (ReadableArray) value); + break; + case \\"arrayOfArrayOfObject\\": + mViewManager.setArrayOfArrayOfObject(view, (ReadableArray) value); + break; + case \\"arrayOfMixed\\": + mViewManager.setArrayOfMixed(view, (ReadableArray) value); + break; + default: + super.setProperty(view, propName, value); + } + } +} +", +} +`; + +exports[`GeneratePropsJavaDelegate can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ArrayPropsWithOptionalObjectGenNativeComponentManagerDelegate.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.uimanager.BaseViewManager; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.LayoutShadowNode; + +@SuppressWarnings(\\"deprecation\\") +public class ArrayPropsWithOptionalObjectGenNativeComponentManagerDelegate & ArrayPropsWithOptionalObjectGenNativeComponentManagerInterface> extends BaseViewManagerDelegate { + public ArrayPropsWithOptionalObjectGenNativeComponentManagerDelegate(U viewManager) { super(viewManager); } @Override @@ -1286,7 +1490,7 @@ public class ObjectPropsManagerDelegate "/** + "java/com/facebook/react/viewmanagers/ObjectPropsWithOptionalGenManagerDelegate.java" => "/** * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). * * Do not edit this file as changes may cause incorrect behavior and will be lost @@ -1305,8 +1509,48 @@ import com.facebook.react.uimanager.BaseViewManagerDelegate; import com.facebook.react.uimanager.LayoutShadowNode; @SuppressWarnings(\\"deprecation\\") -public class ObjectPropsManagerDelegate & ObjectPropsManagerInterface> extends BaseViewManagerDelegate { - public ObjectPropsManagerDelegate(U viewManager) { +public class ObjectPropsWithOptionalGenManagerDelegate & ObjectPropsWithOptionalGenManagerInterface> extends BaseViewManagerDelegate { + public ObjectPropsWithOptionalGenManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case \\"objectProp\\": + mViewManager.setObjectProp(view, (ReadableMap) value); + break; + default: + super.setProperty(view, propName, value); + } + } +} +", +} +`; + +exports[`GeneratePropsJavaDelegate can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ObjectPropsWithOptionalObjectGenManagerDelegate.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaDelegate.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.BaseViewManager; +import com.facebook.react.uimanager.BaseViewManagerDelegate; +import com.facebook.react.uimanager.LayoutShadowNode; + +@SuppressWarnings(\\"deprecation\\") +public class ObjectPropsWithOptionalObjectGenManagerDelegate & ObjectPropsWithOptionalObjectGenManagerInterface> extends BaseViewManagerDelegate { + public ObjectPropsWithOptionalObjectGenManagerDelegate(U viewManager) { super(viewManager); } @Override diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap index 7c73b5e9347..cb0463c7f1f 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaInterface-test.js.snap @@ -82,6 +82,47 @@ public interface AllPropWithOptionalGenManagerInterface extends } `; +exports[`GeneratePropsJavaInterface can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/AllPropWithOptionalObjectGenManagerInterface.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; + +public interface AllPropWithOptionalObjectGenManagerInterface extends ViewManagerWithGeneratedInterface { + void setStringPropNoDefault(T view, @Nullable String value); + void setBooleanPropNoDefault(T view, @Nullable Boolean value); + void setFloatPropNoDefault(T view, @Nullable Float value); + void setStringProp(T view, @Nullable String value); + void setBooleanProp(T view, boolean value); + void setFloatProp(T view, float value); + void setIntProp(T view, int value); + void setStringUserDefaultProp(T view, @Nullable String value); + void setBooleanUserDefaultProp(T view, boolean value); + void setFloatUserDefaultProp(T view, float value); + void setIntUserDefaultProp(T view, int value); + void setStringEnumProp(T view, @Nullable String value); + void setIntEnumProp(T view, @Nullable Integer value); + void setObjectArrayProp(T view, @Nullable ReadableMap value); + void setObjectPrimitiveRequiredProp(T view, @Nullable ReadableMap value); + void setNestedPropA(T view, @Nullable ReadableMap value); + void setNestedArrayAsProperty(T view, @Nullable ReadableMap value); +} +", +} +`; + exports[`GeneratePropsJavaInterface can generate fixture ARRAY_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/ArrayPropsNativeComponentManagerInterface.java" => "/** @@ -146,7 +187,7 @@ public interface ArrayPropsNativeComponentManagerInterface exten exports[`GeneratePropsJavaInterface can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN 1`] = ` Map { - "java/com/facebook/react/viewmanagers/ArrayPropsNativeComponentManagerInterface.java" => "/** + "java/com/facebook/react/viewmanagers/ArrayPropsOptionalGenNativeComponentManagerInterface.java" => "/** * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). * * Do not edit this file as changes may cause incorrect behavior and will be lost @@ -162,7 +203,32 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; -public interface ArrayPropsNativeComponentManagerInterface extends ViewManagerWithGeneratedInterface { +public interface ArrayPropsOptionalGenNativeComponentManagerInterface extends ViewManagerWithGeneratedInterface { + void setNativePrimitives(T view, @Nullable ReadableArray value); +} +", +} +`; + +exports[`GeneratePropsJavaInterface can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ArrayPropsOptionalObjectGenNativeComponentManagerInterface.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; + +public interface ArrayPropsOptionalObjectGenNativeComponentManagerInterface extends ViewManagerWithGeneratedInterface { void setNativePrimitives(T view, @Nullable ReadableArray value); } ", @@ -171,7 +237,7 @@ public interface ArrayPropsNativeComponentManagerInterface exten exports[`GeneratePropsJavaInterface can generate fixture ARRAY_PROPS_WITH_OPTIONAL_GEN 1`] = ` Map { - "java/com/facebook/react/viewmanagers/ArrayPropsNativeComponentManagerInterface.java" => "/** + "java/com/facebook/react/viewmanagers/ArrayPropsWithOptionalGenNativeComponentManagerInterface.java" => "/** * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). * * Do not edit this file as changes may cause incorrect behavior and will be lost @@ -187,7 +253,44 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; -public interface ArrayPropsNativeComponentManagerInterface extends ViewManagerWithGeneratedInterface { +public interface ArrayPropsWithOptionalGenNativeComponentManagerInterface extends ViewManagerWithGeneratedInterface { + void setNames(T view, @Nullable ReadableArray value); + void setDisableds(T view, @Nullable ReadableArray value); + void setProgress(T view, @Nullable ReadableArray value); + void setRadii(T view, @Nullable ReadableArray value); + void setColors(T view, @Nullable ReadableArray value); + void setSrcs(T view, @Nullable ReadableArray value); + void setPoints(T view, @Nullable ReadableArray value); + void setDimensions(T view, @Nullable ReadableArray value); + void setSizes(T view, @Nullable ReadableArray value); + void setObject(T view, @Nullable ReadableArray value); + void setArray(T view, @Nullable ReadableArray value); + void setArrayOfArrayOfObject(T view, @Nullable ReadableArray value); + void setArrayOfMixed(T view, @Nullable ReadableArray value); +} +", +} +`; + +exports[`GeneratePropsJavaInterface can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ArrayPropsWithOptionalObjectGenNativeComponentManagerInterface.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; + +public interface ArrayPropsWithOptionalObjectGenNativeComponentManagerInterface extends ViewManagerWithGeneratedInterface { void setNames(T view, @Nullable ReadableArray value); void setDisableds(T view, @Nullable ReadableArray value); void setProgress(T view, @Nullable ReadableArray value); @@ -727,7 +830,7 @@ public interface ObjectPropsManagerInterface extends ViewManager exports[`GeneratePropsJavaInterface can generate fixture OBJECT_PROPS_WITH_OPTIONAL_GEN 1`] = ` Map { - "java/com/facebook/react/viewmanagers/ObjectPropsManagerInterface.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsWithOptionalGenManagerInterface.java" => "/** * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). * * Do not edit this file as changes may cause incorrect behavior and will be lost @@ -743,7 +846,32 @@ import androidx.annotation.Nullable; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; -public interface ObjectPropsManagerInterface extends ViewManagerWithGeneratedInterface { +public interface ObjectPropsWithOptionalGenManagerInterface extends ViewManagerWithGeneratedInterface { + void setObjectProp(T view, @Nullable ReadableMap value); +} +", +} +`; + +exports[`GeneratePropsJavaInterface can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ObjectPropsWithOptionalObjectGenManagerInterface.java" => "/** +* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). +* +* Do not edit this file as changes may cause incorrect behavior and will be lost +* once the code is regenerated. +* +* @generated by codegen project: GeneratePropsJavaInterface.js +*/ + +package com.facebook.react.viewmanagers; + +import android.view.View; +import androidx.annotation.Nullable; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; + +public interface ObjectPropsWithOptionalObjectGenManagerInterface extends ViewManagerWithGeneratedInterface { void setObjectProp(T view, @Nullable ReadableMap value); } ", diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap index faba4b075d6..e7318bb6dd7 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsJavaPojo-test.js.snap @@ -42,10 +42,40 @@ import com.facebook.react.bridge.ReadableMap; @DoNotStrip public class AllPropPropsObjectPrimitiveRequiredProp { + private @Nullable String mString; + private boolean mBoolean; + private float mFloat; + private @Nullable String mStringNoDefault; + private @Nullable Boolean mBooleanNoDefault; + private @Nullable Float mFloatNoDefault; private @Nullable ReadableMap mImage; private @Nullable Integer mColor; private @Nullable ReadableMap mPoint; @DoNotStrip + public @Nullable String getString() { + return mString; + } + @DoNotStrip + public boolean getBoolean() { + return mBoolean; + } + @DoNotStrip + public float getFloat() { + return mFloat; + } + @DoNotStrip + public @Nullable String getStringNoDefault() { + return mStringNoDefault; + } + @DoNotStrip + public @Nullable Boolean getBooleanNoDefault() { + return mBooleanNoDefault; + } + @DoNotStrip + public @Nullable Float getFloatNoDefault() { + return mFloatNoDefault; + } + @DoNotStrip public @Nullable ReadableMap getImage() { return mImage; } @@ -298,10 +328,40 @@ import com.facebook.react.bridge.ReadableMap; @DoNotStrip public class AllPropWithOptionalGenPropsObjectPrimitiveRequiredProp { + private @Nullable String mString; + private boolean mBoolean; + private float mFloat; + private @Nullable String mStringNoDefault; + private @Nullable Boolean mBooleanNoDefault; + private @Nullable Float mFloatNoDefault; private @Nullable ReadableMap mImage; private @Nullable Integer mColor; private @Nullable ReadableMap mPoint; @DoNotStrip + public @Nullable String getString() { + return mString; + } + @DoNotStrip + public boolean getBoolean() { + return mBoolean; + } + @DoNotStrip + public float getFloat() { + return mFloat; + } + @DoNotStrip + public @Nullable String getStringNoDefault() { + return mStringNoDefault; + } + @DoNotStrip + public @Nullable Boolean getBooleanNoDefault() { + return mBooleanNoDefault; + } + @DoNotStrip + public @Nullable Float getFloatNoDefault() { + return mFloatNoDefault; + } + @DoNotStrip public @Nullable ReadableMap getImage() { return mImage; } @@ -512,6 +572,292 @@ public class AllPropWithOptionalGenProps { } `; +exports[`GeneratePropsJavaPojo can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenPropsObjectArrayProp.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.util.ArrayList; + +@DoNotStrip +public class AllPropWithOptionalObjectGenPropsObjectArrayProp { + private ArrayList mArray; + @DoNotStrip + public ArrayList getArray() { + return mArray; + } +} +", + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenPropsObjectPrimitiveRequiredProp.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReadableMap; + +@DoNotStrip +public class AllPropWithOptionalObjectGenPropsObjectPrimitiveRequiredProp { + private @Nullable String mString; + private boolean mBoolean; + private float mFloat; + private @Nullable String mStringNoDefault; + private @Nullable Boolean mBooleanNoDefault; + private @Nullable Float mFloatNoDefault; + private @Nullable ReadableMap mImage; + private @Nullable Integer mColor; + private @Nullable ReadableMap mPoint; + @DoNotStrip + public @Nullable String getString() { + return mString; + } + @DoNotStrip + public boolean getBoolean() { + return mBoolean; + } + @DoNotStrip + public float getFloat() { + return mFloat; + } + @DoNotStrip + public @Nullable String getStringNoDefault() { + return mStringNoDefault; + } + @DoNotStrip + public @Nullable Boolean getBooleanNoDefault() { + return mBooleanNoDefault; + } + @DoNotStrip + public @Nullable Float getFloatNoDefault() { + return mFloatNoDefault; + } + @DoNotStrip + public @Nullable ReadableMap getImage() { + return mImage; + } + @DoNotStrip + public @Nullable Integer getColor() { + return mColor; + } + @DoNotStrip + public @Nullable ReadableMap getPoint() { + return mPoint; + } +} +", + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenPropsNestedPropANestedPropB.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class AllPropWithOptionalObjectGenPropsNestedPropANestedPropB { + private @Nullable String mNestedPropC; + @DoNotStrip + public @Nullable String getNestedPropC() { + return mNestedPropC; + } +} +", + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenPropsNestedPropA.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class AllPropWithOptionalObjectGenPropsNestedPropA { + private AllPropWithOptionalObjectGenPropsNestedPropANestedPropB mNestedPropB; + @DoNotStrip + public AllPropWithOptionalObjectGenPropsNestedPropANestedPropB getNestedPropB() { + return mNestedPropB; + } +} +", + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenPropsNestedArrayAsPropertyArrayPropElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class AllPropWithOptionalObjectGenPropsNestedArrayAsPropertyArrayPropElement { + private @Nullable String mStringProp; + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } +} +", + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenPropsNestedArrayAsProperty.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.util.ArrayList; + +@DoNotStrip +public class AllPropWithOptionalObjectGenPropsNestedArrayAsProperty { + private ArrayList mArrayProp; + @DoNotStrip + public ArrayList getArrayProp() { + return mArrayProp; + } +} +", + "java/com/facebook/react/viewmanagers/AllPropsNativeComponent/AllPropWithOptionalObjectGenProps.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.AllPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class AllPropWithOptionalObjectGenProps { + private @Nullable String mStringPropNoDefault; + private @Nullable Boolean mBooleanPropNoDefault; + private @Nullable Float mFloatPropNoDefault; + private @Nullable String mStringProp; + private boolean mBooleanProp; + private float mFloatProp; + private int mIntProp; + private @Nullable String mStringUserDefaultProp; + private boolean mBooleanUserDefaultProp; + private float mFloatUserDefaultProp; + private int mIntUserDefaultProp; + private @Nullable String mStringEnumProp; + private @Nullable Integer mIntEnumProp; + private AllPropWithOptionalObjectGenPropsObjectArrayProp mObjectArrayProp; + private AllPropWithOptionalObjectGenPropsObjectPrimitiveRequiredProp mObjectPrimitiveRequiredProp; + private AllPropWithOptionalObjectGenPropsNestedPropA mNestedPropA; + private AllPropWithOptionalObjectGenPropsNestedArrayAsProperty mNestedArrayAsProperty; + @DoNotStrip + public @Nullable String getStringPropNoDefault() { + return mStringPropNoDefault; + } + @DoNotStrip + public @Nullable Boolean getBooleanPropNoDefault() { + return mBooleanPropNoDefault; + } + @DoNotStrip + public @Nullable Float getFloatPropNoDefault() { + return mFloatPropNoDefault; + } + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } + @DoNotStrip + public boolean getBooleanProp() { + return mBooleanProp; + } + @DoNotStrip + public float getFloatProp() { + return mFloatProp; + } + @DoNotStrip + public int getIntProp() { + return mIntProp; + } + @DoNotStrip + public @Nullable String getStringUserDefaultProp() { + return mStringUserDefaultProp; + } + @DoNotStrip + public boolean getBooleanUserDefaultProp() { + return mBooleanUserDefaultProp; + } + @DoNotStrip + public float getFloatUserDefaultProp() { + return mFloatUserDefaultProp; + } + @DoNotStrip + public int getIntUserDefaultProp() { + return mIntUserDefaultProp; + } + @DoNotStrip + public @Nullable String getStringEnumProp() { + return mStringEnumProp; + } + @DoNotStrip + public @Nullable Integer getIntEnumProp() { + return mIntEnumProp; + } + @DoNotStrip + public AllPropWithOptionalObjectGenPropsObjectArrayProp getObjectArrayProp() { + return mObjectArrayProp; + } + @DoNotStrip + public AllPropWithOptionalObjectGenPropsObjectPrimitiveRequiredProp getObjectPrimitiveRequiredProp() { + return mObjectPrimitiveRequiredProp; + } + @DoNotStrip + public AllPropWithOptionalObjectGenPropsNestedPropA getNestedPropA() { + return mNestedPropA; + } + @DoNotStrip + public AllPropWithOptionalObjectGenPropsNestedArrayAsProperty getNestedArrayAsProperty() { + return mNestedArrayAsProperty; + } +} +", +} +`; + exports[`GeneratePropsJavaPojo can generate fixture ARRAY_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentPropsObjectElement.java" => "/** @@ -759,7 +1105,7 @@ public class ArrayPropsNativeComponentProps { exports[`GeneratePropsJavaPojo can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN 1`] = ` Map { - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentPropsNativePrimitivesElement.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsOptionalGenNativeComponentPropsNativePrimitivesElement.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -775,7 +1121,7 @@ import com.facebook.react.bridge.ReadableMap; import java.util.ArrayList; @DoNotStrip -public class ArrayPropsNativeComponentPropsNativePrimitivesElement { +public class ArrayPropsOptionalGenNativeComponentPropsNativePrimitivesElement { private ArrayList mColors; private ArrayList mSrcs; private ArrayList mPoints; @@ -793,7 +1139,7 @@ public class ArrayPropsNativeComponentPropsNativePrimitivesElement { } } ", - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentProps.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsOptionalGenNativeComponentProps.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -808,10 +1154,72 @@ import com.facebook.proguard.annotations.DoNotStrip; import java.util.ArrayList; @DoNotStrip -public class ArrayPropsNativeComponentProps { - private ArrayList mNativePrimitives; +public class ArrayPropsOptionalGenNativeComponentProps { + private ArrayList mNativePrimitives; @DoNotStrip - public ArrayList getNativePrimitives() { + public ArrayList getNativePrimitives() { + return mNativePrimitives; + } +} +", +} +`; + +exports[`GeneratePropsJavaPojo can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsOptionalObjectGenNativeComponentPropsNativePrimitivesElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReadableMap; +import java.util.ArrayList; + +@DoNotStrip +public class ArrayPropsOptionalObjectGenNativeComponentPropsNativePrimitivesElement { + private ArrayList mColors; + private ArrayList mSrcs; + private ArrayList mPoints; + @DoNotStrip + public ArrayList getColors() { + return mColors; + } + @DoNotStrip + public ArrayList getSrcs() { + return mSrcs; + } + @DoNotStrip + public ArrayList getPoints() { + return mPoints; + } +} +", + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsOptionalObjectGenNativeComponentProps.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.util.ArrayList; + +@DoNotStrip +public class ArrayPropsOptionalObjectGenNativeComponentProps { + private ArrayList mNativePrimitives; + @DoNotStrip + public ArrayList getNativePrimitives() { return mNativePrimitives; } } @@ -821,7 +1229,7 @@ public class ArrayPropsNativeComponentProps { exports[`GeneratePropsJavaPojo can generate fixture ARRAY_PROPS_WITH_OPTIONAL_GEN 1`] = ` Map { - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentPropsObjectElement.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalGenNativeComponentPropsObjectElement.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -836,7 +1244,7 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ArrayPropsNativeComponentPropsObjectElement { +public class ArrayPropsWithOptionalGenNativeComponentPropsObjectElement { private @Nullable String mStringProp; @DoNotStrip public @Nullable String getStringProp() { @@ -844,7 +1252,7 @@ public class ArrayPropsNativeComponentPropsObjectElement { } } ", - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentPropsArrayElementObjectElement.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalGenNativeComponentPropsArrayElementObjectElement.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -859,7 +1267,7 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ArrayPropsNativeComponentPropsArrayElementObjectElement { +public class ArrayPropsWithOptionalGenNativeComponentPropsArrayElementObjectElement { private @Nullable String mStringProp; @DoNotStrip public @Nullable String getStringProp() { @@ -867,7 +1275,7 @@ public class ArrayPropsNativeComponentPropsArrayElementObjectElement { } } ", - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentPropsArrayElement.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalGenNativeComponentPropsArrayElement.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -882,15 +1290,15 @@ import com.facebook.proguard.annotations.DoNotStrip; import java.util.ArrayList; @DoNotStrip -public class ArrayPropsNativeComponentPropsArrayElement { - private ArrayList mObject; +public class ArrayPropsWithOptionalGenNativeComponentPropsArrayElement { + private ArrayList mObject; @DoNotStrip - public ArrayList getObject() { + public ArrayList getObject() { return mObject; } } ", - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentPropsArrayOfArrayOfObjectElementElement.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalGenNativeComponentPropsArrayOfArrayOfObjectElementElement.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -905,7 +1313,7 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ArrayPropsNativeComponentPropsArrayOfArrayOfObjectElementElement { +public class ArrayPropsWithOptionalGenNativeComponentPropsArrayOfArrayOfObjectElementElement { private @Nullable String mStringProp; @DoNotStrip public @Nullable String getStringProp() { @@ -913,7 +1321,7 @@ public class ArrayPropsNativeComponentPropsArrayOfArrayOfObjectElementElement { } } ", - "java/com/facebook/react/viewmanagers/Slider/ArrayPropsNativeComponentProps.java" => "/** + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalGenNativeComponentProps.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -931,7 +1339,7 @@ import com.facebook.yoga.YogaValue; import java.util.ArrayList; @DoNotStrip -public class ArrayPropsNativeComponentProps { +public class ArrayPropsWithOptionalGenNativeComponentProps { private ArrayList mNames; private ArrayList mDisableds; private ArrayList mProgress; @@ -941,9 +1349,9 @@ public class ArrayPropsNativeComponentProps { private ArrayList mPoints; private ArrayList mDimensions; private ArrayList mSizes; - private ArrayList mObject; - private ArrayList mArray; - private ArrayList> mArrayOfArrayOfObject; + private ArrayList mObject; + private ArrayList mArray; + private ArrayList> mArrayOfArrayOfObject; private ArrayList mArrayOfMixed; @DoNotStrip public ArrayList getNames() { @@ -982,15 +1390,198 @@ public class ArrayPropsNativeComponentProps { return mSizes; } @DoNotStrip - public ArrayList getObject() { + public ArrayList getObject() { return mObject; } @DoNotStrip - public ArrayList getArray() { + public ArrayList getArray() { return mArray; } @DoNotStrip - public ArrayList> getArrayOfArrayOfObject() { + public ArrayList> getArrayOfArrayOfObject() { + return mArrayOfArrayOfObject; + } + @DoNotStrip + public ArrayList getArrayOfMixed() { + return mArrayOfMixed; + } +} +", +} +`; + +exports[`GeneratePropsJavaPojo can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalObjectGenNativeComponentPropsObjectElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ArrayPropsWithOptionalObjectGenNativeComponentPropsObjectElement { + private @Nullable String mStringProp; + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } +} +", + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalObjectGenNativeComponentPropsArrayElementObjectElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ArrayPropsWithOptionalObjectGenNativeComponentPropsArrayElementObjectElement { + private @Nullable String mStringProp; + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } +} +", + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalObjectGenNativeComponentPropsArrayElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.util.ArrayList; + +@DoNotStrip +public class ArrayPropsWithOptionalObjectGenNativeComponentPropsArrayElement { + private ArrayList mObject; + @DoNotStrip + public ArrayList getObject() { + return mObject; + } +} +", + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalObjectGenNativeComponentPropsArrayOfArrayOfObjectElementElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ArrayPropsWithOptionalObjectGenNativeComponentPropsArrayOfArrayOfObjectElementElement { + private @Nullable String mStringProp; + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } +} +", + "java/com/facebook/react/viewmanagers/Slider/ArrayPropsWithOptionalObjectGenNativeComponentProps.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.Slider; + +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.Dynamic; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.yoga.YogaValue; +import java.util.ArrayList; + +@DoNotStrip +public class ArrayPropsWithOptionalObjectGenNativeComponentProps { + private ArrayList mNames; + private ArrayList mDisableds; + private ArrayList mProgress; + private ArrayList mRadii; + private ArrayList mColors; + private ArrayList mSrcs; + private ArrayList mPoints; + private ArrayList mDimensions; + private ArrayList mSizes; + private ArrayList mObject; + private ArrayList mArray; + private ArrayList> mArrayOfArrayOfObject; + private ArrayList mArrayOfMixed; + @DoNotStrip + public ArrayList getNames() { + return mNames; + } + @DoNotStrip + public ArrayList getDisableds() { + return mDisableds; + } + @DoNotStrip + public ArrayList getProgress() { + return mProgress; + } + @DoNotStrip + public ArrayList getRadii() { + return mRadii; + } + @DoNotStrip + public ArrayList getColors() { + return mColors; + } + @DoNotStrip + public ArrayList getSrcs() { + return mSrcs; + } + @DoNotStrip + public ArrayList getPoints() { + return mPoints; + } + @DoNotStrip + public ArrayList getDimensions() { + return mDimensions; + } + @DoNotStrip + public ArrayList getSizes() { + return mSizes; + } + @DoNotStrip + public ArrayList getObject() { + return mObject; + } + @DoNotStrip + public ArrayList getArray() { + return mArray; + } + @DoNotStrip + public ArrayList> getArrayOfArrayOfObject() { return mArrayOfArrayOfObject; } @DoNotStrip @@ -1882,7 +2473,7 @@ public class ObjectPropsProps { exports[`GeneratePropsJavaPojo can generate fixture OBJECT_PROPS_WITH_OPTIONAL_GEN 1`] = ` Map { - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectPropObjectArrayProp.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectPropObjectArrayProp.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -1897,7 +2488,7 @@ import com.facebook.proguard.annotations.DoNotStrip; import java.util.ArrayList; @DoNotStrip -public class ObjectPropsPropsObjectPropObjectArrayProp { +public class ObjectPropsWithOptionalGenPropsObjectPropObjectArrayProp { private ArrayList mArray; @DoNotStrip public ArrayList getArray() { @@ -1905,7 +2496,7 @@ public class ObjectPropsPropsObjectPropObjectArrayProp { } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectPropObjectPrimitiveRequiredProp.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectPropObjectPrimitiveRequiredProp.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -1921,7 +2512,7 @@ import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.ReadableMap; @DoNotStrip -public class ObjectPropsPropsObjectPropObjectPrimitiveRequiredProp { +public class ObjectPropsWithOptionalGenPropsObjectPropObjectPrimitiveRequiredProp { private @Nullable ReadableMap mImage; private @Nullable Integer mColor; private @Nullable ReadableMap mPoint; @@ -1939,7 +2530,7 @@ public class ObjectPropsPropsObjectPropObjectPrimitiveRequiredProp { } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectPropNestedPropANestedPropB.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectPropNestedPropANestedPropB.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -1954,7 +2545,7 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ObjectPropsPropsObjectPropNestedPropANestedPropB { +public class ObjectPropsWithOptionalGenPropsObjectPropNestedPropANestedPropB { private @Nullable String mNestedPropC; @DoNotStrip public @Nullable String getNestedPropC() { @@ -1962,7 +2553,7 @@ public class ObjectPropsPropsObjectPropNestedPropANestedPropB { } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectPropNestedPropA.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectPropNestedPropA.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -1976,15 +2567,15 @@ package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ObjectPropsPropsObjectPropNestedPropA { - private ObjectPropsPropsObjectPropNestedPropANestedPropB mNestedPropB; +public class ObjectPropsWithOptionalGenPropsObjectPropNestedPropA { + private ObjectPropsWithOptionalGenPropsObjectPropNestedPropANestedPropB mNestedPropB; @DoNotStrip - public ObjectPropsPropsObjectPropNestedPropANestedPropB getNestedPropB() { + public ObjectPropsWithOptionalGenPropsObjectPropNestedPropANestedPropB getNestedPropB() { return mNestedPropB; } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectPropNestedArrayAsPropertyArrayPropElement.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectPropNestedArrayAsPropertyArrayPropElement.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -1999,7 +2590,7 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ObjectPropsPropsObjectPropNestedArrayAsPropertyArrayPropElement { +public class ObjectPropsWithOptionalGenPropsObjectPropNestedArrayAsPropertyArrayPropElement { private @Nullable String mStringProp; @DoNotStrip public @Nullable String getStringProp() { @@ -2007,7 +2598,7 @@ public class ObjectPropsPropsObjectPropNestedArrayAsPropertyArrayPropElement { } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectPropNestedArrayAsProperty.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectPropNestedArrayAsProperty.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -2022,15 +2613,15 @@ import com.facebook.proguard.annotations.DoNotStrip; import java.util.ArrayList; @DoNotStrip -public class ObjectPropsPropsObjectPropNestedArrayAsProperty { - private ArrayList mArrayProp; +public class ObjectPropsWithOptionalGenPropsObjectPropNestedArrayAsProperty { + private ArrayList mArrayProp; @DoNotStrip - public ArrayList getArrayProp() { + public ArrayList getArrayProp() { return mArrayProp; } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsPropsObjectProp.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenPropsObjectProp.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -2045,7 +2636,7 @@ import androidx.annotation.Nullable; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ObjectPropsPropsObjectProp { +public class ObjectPropsWithOptionalGenPropsObjectProp { private @Nullable String mStringProp; private boolean mBooleanProp; private float mFloatProp; @@ -2056,10 +2647,10 @@ public class ObjectPropsPropsObjectProp { private int mIntUserDefaultProp; private @Nullable String mStringEnumProp; private @Nullable Integer mIntEnumProp; - private ObjectPropsPropsObjectPropObjectArrayProp mObjectArrayProp; - private ObjectPropsPropsObjectPropObjectPrimitiveRequiredProp mObjectPrimitiveRequiredProp; - private ObjectPropsPropsObjectPropNestedPropA mNestedPropA; - private ObjectPropsPropsObjectPropNestedArrayAsProperty mNestedArrayAsProperty; + private ObjectPropsWithOptionalGenPropsObjectPropObjectArrayProp mObjectArrayProp; + private ObjectPropsWithOptionalGenPropsObjectPropObjectPrimitiveRequiredProp mObjectPrimitiveRequiredProp; + private ObjectPropsWithOptionalGenPropsObjectPropNestedPropA mNestedPropA; + private ObjectPropsWithOptionalGenPropsObjectPropNestedArrayAsProperty mNestedArrayAsProperty; @DoNotStrip public @Nullable String getStringProp() { return mStringProp; @@ -2101,24 +2692,24 @@ public class ObjectPropsPropsObjectProp { return mIntEnumProp; } @DoNotStrip - public ObjectPropsPropsObjectPropObjectArrayProp getObjectArrayProp() { + public ObjectPropsWithOptionalGenPropsObjectPropObjectArrayProp getObjectArrayProp() { return mObjectArrayProp; } @DoNotStrip - public ObjectPropsPropsObjectPropObjectPrimitiveRequiredProp getObjectPrimitiveRequiredProp() { + public ObjectPropsWithOptionalGenPropsObjectPropObjectPrimitiveRequiredProp getObjectPrimitiveRequiredProp() { return mObjectPrimitiveRequiredProp; } @DoNotStrip - public ObjectPropsPropsObjectPropNestedPropA getNestedPropA() { + public ObjectPropsWithOptionalGenPropsObjectPropNestedPropA getNestedPropA() { return mNestedPropA; } @DoNotStrip - public ObjectPropsPropsObjectPropNestedArrayAsProperty getNestedArrayAsProperty() { + public ObjectPropsWithOptionalGenPropsObjectPropNestedArrayAsProperty getNestedArrayAsProperty() { return mNestedArrayAsProperty; } } ", - "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsProps.java" => "/** + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalGenProps.java" => "/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the @@ -2132,10 +2723,273 @@ package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip -public class ObjectPropsProps { - private ObjectPropsPropsObjectProp mObjectProp; +public class ObjectPropsWithOptionalGenProps { + private ObjectPropsWithOptionalGenPropsObjectProp mObjectProp; @DoNotStrip - public ObjectPropsPropsObjectProp getObjectProp() { + public ObjectPropsWithOptionalGenPropsObjectProp getObjectProp() { + return mObjectProp; + } +} +", +} +`; + +exports[`GeneratePropsJavaPojo can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectPropObjectArrayProp.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.util.ArrayList; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectPropObjectArrayProp { + private ArrayList mArray; + @DoNotStrip + public ArrayList getArray() { + return mArray; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectPropObjectPrimitiveRequiredProp.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReadableMap; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectPropObjectPrimitiveRequiredProp { + private @Nullable ReadableMap mImage; + private @Nullable Integer mColor; + private @Nullable ReadableMap mPoint; + @DoNotStrip + public @Nullable ReadableMap getImage() { + return mImage; + } + @DoNotStrip + public @Nullable Integer getColor() { + return mColor; + } + @DoNotStrip + public @Nullable ReadableMap getPoint() { + return mPoint; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropANestedPropB.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropANestedPropB { + private @Nullable String mNestedPropC; + @DoNotStrip + public @Nullable String getNestedPropC() { + return mNestedPropC; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropA.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropA { + private ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropANestedPropB mNestedPropB; + @DoNotStrip + public ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropANestedPropB getNestedPropB() { + return mNestedPropB; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectPropNestedArrayAsPropertyArrayPropElement.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectPropNestedArrayAsPropertyArrayPropElement { + private @Nullable String mStringProp; + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectPropNestedArrayAsProperty.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.util.ArrayList; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectPropNestedArrayAsProperty { + private ArrayList mArrayProp; + @DoNotStrip + public ArrayList getArrayProp() { + return mArrayProp; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenPropsObjectProp.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenPropsObjectProp { + private @Nullable String mStringProp; + private boolean mBooleanProp; + private float mFloatProp; + private int mIntProp; + private @Nullable String mStringUserDefaultProp; + private boolean mBooleanUserDefaultProp; + private float mFloatUserDefaultProp; + private int mIntUserDefaultProp; + private @Nullable String mStringEnumProp; + private @Nullable Integer mIntEnumProp; + private ObjectPropsWithOptionalObjectGenPropsObjectPropObjectArrayProp mObjectArrayProp; + private ObjectPropsWithOptionalObjectGenPropsObjectPropObjectPrimitiveRequiredProp mObjectPrimitiveRequiredProp; + private ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropA mNestedPropA; + private ObjectPropsWithOptionalObjectGenPropsObjectPropNestedArrayAsProperty mNestedArrayAsProperty; + @DoNotStrip + public @Nullable String getStringProp() { + return mStringProp; + } + @DoNotStrip + public boolean getBooleanProp() { + return mBooleanProp; + } + @DoNotStrip + public float getFloatProp() { + return mFloatProp; + } + @DoNotStrip + public int getIntProp() { + return mIntProp; + } + @DoNotStrip + public @Nullable String getStringUserDefaultProp() { + return mStringUserDefaultProp; + } + @DoNotStrip + public boolean getBooleanUserDefaultProp() { + return mBooleanUserDefaultProp; + } + @DoNotStrip + public float getFloatUserDefaultProp() { + return mFloatUserDefaultProp; + } + @DoNotStrip + public int getIntUserDefaultProp() { + return mIntUserDefaultProp; + } + @DoNotStrip + public @Nullable String getStringEnumProp() { + return mStringEnumProp; + } + @DoNotStrip + public @Nullable Integer getIntEnumProp() { + return mIntEnumProp; + } + @DoNotStrip + public ObjectPropsWithOptionalObjectGenPropsObjectPropObjectArrayProp getObjectArrayProp() { + return mObjectArrayProp; + } + @DoNotStrip + public ObjectPropsWithOptionalObjectGenPropsObjectPropObjectPrimitiveRequiredProp getObjectPrimitiveRequiredProp() { + return mObjectPrimitiveRequiredProp; + } + @DoNotStrip + public ObjectPropsWithOptionalObjectGenPropsObjectPropNestedPropA getNestedPropA() { + return mNestedPropA; + } + @DoNotStrip + public ObjectPropsWithOptionalObjectGenPropsObjectPropNestedArrayAsProperty getNestedArrayAsProperty() { + return mNestedArrayAsProperty; + } +} +", + "java/com/facebook/react/viewmanagers/ObjectPropsNativeComponent/ObjectPropsWithOptionalObjectGenProps.java" => "/** +* Copyright (c) Meta Platforms, Inc. and affiliates. +* +* This source code is licensed under the MIT license found in the +* LICENSE file in the root directory of this source tree. +* +* @generated by codegen project: GeneratePropsJavaPojo.js +*/ + +package com.facebook.react.viewmanagers.ObjectPropsNativeComponent; + +import com.facebook.proguard.annotations.DoNotStrip; + +@DoNotStrip +public class ObjectPropsWithOptionalObjectGenProps { + private ObjectPropsWithOptionalObjectGenPropsObjectProp mObjectProp; + @DoNotStrip + public ObjectPropsWithOptionalObjectGenPropsObjectProp getObjectProp() { return mObjectProp; } } diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap index 9b9718920ca..ed7c273bdf7 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap @@ -46,6 +46,29 @@ extern const char AllPropWithOptionalGenComponentName[] = \\"AllPropWithOptional } `; +exports[`GenerateShadowNodeCpp can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeCpp.js + */ + +#include + +namespace facebook::react { + +extern const char AllPropWithOptionalObjectGenComponentName[] = \\"AllPropWithOptionalObjectGen\\"; + +} // namespace facebook::react +", +} +`; + exports[`GenerateShadowNodeCpp can generate fixture ARRAY_PROPS 1`] = ` Map { "ShadowNodes.cpp" => " @@ -108,7 +131,30 @@ Map { namespace facebook::react { -extern const char ArrayPropsNativeComponentComponentName[] = \\"ArrayPropsNativeComponent\\"; +extern const char ArrayPropsOptionalGenNativeComponentComponentName[] = \\"ArrayPropsOptionalGenNativeComponent\\"; + +} // namespace facebook::react +", +} +`; + +exports[`GenerateShadowNodeCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeCpp.js + */ + +#include + +namespace facebook::react { + +extern const char ArrayPropsOptionalObjectGenNativeComponentComponentName[] = \\"ArrayPropsOptionalObjectGenNativeComponent\\"; } // namespace facebook::react ", @@ -131,7 +177,30 @@ Map { namespace facebook::react { -extern const char ArrayPropsNativeComponentComponentName[] = \\"ArrayPropsNativeComponent\\"; +extern const char ArrayPropsWithOptionalGenNativeComponentComponentName[] = \\"ArrayPropsWithOptionalGenNativeComponent\\"; + +} // namespace facebook::react +", +} +`; + +exports[`GenerateShadowNodeCpp can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeCpp.js + */ + +#include + +namespace facebook::react { + +extern const char ArrayPropsWithOptionalObjectGenNativeComponentComponentName[] = \\"ArrayPropsWithOptionalObjectGenNativeComponent\\"; } // namespace facebook::react ", @@ -661,7 +730,30 @@ Map { namespace facebook::react { -extern const char ObjectPropsComponentName[] = \\"ObjectProps\\"; +extern const char ObjectPropsWithOptionalGenComponentName[] = \\"ObjectPropsWithOptionalGen\\"; + +} // namespace facebook::react +", +} +`; + +exports[`GenerateShadowNodeCpp can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeCpp.js + */ + +#include + +namespace facebook::react { + +extern const char ObjectPropsWithOptionalObjectGenComponentName[] = \\"ObjectPropsWithOptionalObjectGen\\"; } // namespace facebook::react ", diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap index f8639b5b473..c441beb9b39 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -76,6 +76,44 @@ using AllPropWithOptionalGenShadowNode = ConcreteViewShadowNode< } `; +exports[`GenerateShadowNodeH can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeH.js + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace facebook::react { + +JSI_EXPORT extern const char AllPropWithOptionalObjectGenComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using AllPropWithOptionalObjectGenShadowNode = ConcreteViewShadowNode< + AllPropWithOptionalObjectGenComponentName, + AllPropWithOptionalObjectGenProps, + AllPropWithOptionalObjectGenEventEmitter, + AllPropWithOptionalObjectGenState>; + +} // namespace facebook::react +", +} +`; + exports[`GenerateShadowNodeH can generate fixture ARRAY_PROPS 1`] = ` Map { "ShadowNodes.h" => " @@ -174,16 +212,54 @@ Map { namespace facebook::react { -JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char ArrayPropsOptionalGenNativeComponentComponentName[]; /* - * \`ShadowNode\` for component. + * \`ShadowNode\` for component. */ -using ArrayPropsNativeComponentShadowNode = ConcreteViewShadowNode< - ArrayPropsNativeComponentComponentName, - ArrayPropsNativeComponentProps, - ArrayPropsNativeComponentEventEmitter, - ArrayPropsNativeComponentState>; +using ArrayPropsOptionalGenNativeComponentShadowNode = ConcreteViewShadowNode< + ArrayPropsOptionalGenNativeComponentComponentName, + ArrayPropsOptionalGenNativeComponentProps, + ArrayPropsOptionalGenNativeComponentEventEmitter, + ArrayPropsOptionalGenNativeComponentState>; + +} // namespace facebook::react +", +} +`; + +exports[`GenerateShadowNodeH can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeH.js + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace facebook::react { + +JSI_EXPORT extern const char ArrayPropsOptionalObjectGenNativeComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using ArrayPropsOptionalObjectGenNativeComponentShadowNode = ConcreteViewShadowNode< + ArrayPropsOptionalObjectGenNativeComponentComponentName, + ArrayPropsOptionalObjectGenNativeComponentProps, + ArrayPropsOptionalObjectGenNativeComponentEventEmitter, + ArrayPropsOptionalObjectGenNativeComponentState>; } // namespace facebook::react ", @@ -212,16 +288,54 @@ Map { namespace facebook::react { -JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char ArrayPropsWithOptionalGenNativeComponentComponentName[]; /* - * \`ShadowNode\` for component. + * \`ShadowNode\` for component. */ -using ArrayPropsNativeComponentShadowNode = ConcreteViewShadowNode< - ArrayPropsNativeComponentComponentName, - ArrayPropsNativeComponentProps, - ArrayPropsNativeComponentEventEmitter, - ArrayPropsNativeComponentState>; +using ArrayPropsWithOptionalGenNativeComponentShadowNode = ConcreteViewShadowNode< + ArrayPropsWithOptionalGenNativeComponentComponentName, + ArrayPropsWithOptionalGenNativeComponentProps, + ArrayPropsWithOptionalGenNativeComponentEventEmitter, + ArrayPropsWithOptionalGenNativeComponentState>; + +} // namespace facebook::react +", +} +`; + +exports[`GenerateShadowNodeH can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeH.js + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace facebook::react { + +JSI_EXPORT extern const char ArrayPropsWithOptionalObjectGenNativeComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using ArrayPropsWithOptionalObjectGenNativeComponentShadowNode = ConcreteViewShadowNode< + ArrayPropsWithOptionalObjectGenNativeComponentComponentName, + ArrayPropsWithOptionalObjectGenNativeComponentProps, + ArrayPropsWithOptionalObjectGenNativeComponentEventEmitter, + ArrayPropsWithOptionalObjectGenNativeComponentState>; } // namespace facebook::react ", @@ -1079,16 +1193,54 @@ Map { namespace facebook::react { -JSI_EXPORT extern const char ObjectPropsComponentName[]; +JSI_EXPORT extern const char ObjectPropsWithOptionalGenComponentName[]; /* - * \`ShadowNode\` for component. + * \`ShadowNode\` for component. */ -using ObjectPropsShadowNode = ConcreteViewShadowNode< - ObjectPropsComponentName, - ObjectPropsProps, - ObjectPropsEventEmitter, - ObjectPropsState>; +using ObjectPropsWithOptionalGenShadowNode = ConcreteViewShadowNode< + ObjectPropsWithOptionalGenComponentName, + ObjectPropsWithOptionalGenProps, + ObjectPropsWithOptionalGenEventEmitter, + ObjectPropsWithOptionalGenState>; + +} // namespace facebook::react +", +} +`; + +exports[`GenerateShadowNodeH can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateShadowNodeH.js + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace facebook::react { + +JSI_EXPORT extern const char ObjectPropsWithOptionalObjectGenComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using ObjectPropsWithOptionalObjectGenShadowNode = ConcreteViewShadowNode< + ObjectPropsWithOptionalObjectGenComponentName, + ObjectPropsWithOptionalObjectGenProps, + ObjectPropsWithOptionalObjectGenEventEmitter, + ObjectPropsWithOptionalObjectGenState>; } // namespace facebook::react ", diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap index ae3816ce069..2880740bde1 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap @@ -39,6 +39,28 @@ namespace facebook::react { +} // namespace facebook::react +", +} +`; + +exports[`GenerateStateCpp can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook::react { + + + } // namespace facebook::react ", } @@ -105,6 +127,28 @@ namespace facebook::react { +} // namespace facebook::react +", +} +`; + +exports[`GenerateStateCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook::react { + + + } // namespace facebook::react ", } @@ -127,6 +171,28 @@ namespace facebook::react { +} // namespace facebook::react +", +} +`; + +exports[`GenerateStateCpp can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook::react { + + + } // namespace facebook::react ", } @@ -633,6 +699,28 @@ namespace facebook::react { +} // namespace facebook::react +", +} +`; + +exports[`GenerateStateCpp can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook::react { + + + } // namespace facebook::react ", } diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap index dd8f2b623a4..478385b96ca 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap @@ -50,6 +50,31 @@ using AllPropWithOptionalGenState = StateData; } `; +exports[`GenerateStateH can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.h" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#include +#ifdef RN_SERIALIZABLE_STATE +#include +#endif + +namespace facebook::react { + +using AllPropWithOptionalObjectGenState = StateData; + +} // namespace facebook::react", +} +`; + exports[`GenerateStateH can generate fixture ARRAY_PROPS 1`] = ` Map { "States.h" => "/** @@ -119,7 +144,32 @@ Map { namespace facebook::react { -using ArrayPropsNativeComponentState = StateData; +using ArrayPropsOptionalGenNativeComponentState = StateData; + +} // namespace facebook::react", +} +`; + +exports[`GenerateStateH can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.h" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#include +#ifdef RN_SERIALIZABLE_STATE +#include +#endif + +namespace facebook::react { + +using ArrayPropsOptionalObjectGenNativeComponentState = StateData; } // namespace facebook::react", } @@ -144,7 +194,32 @@ Map { namespace facebook::react { -using ArrayPropsNativeComponentState = StateData; +using ArrayPropsWithOptionalGenNativeComponentState = StateData; + +} // namespace facebook::react", +} +`; + +exports[`GenerateStateH can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.h" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#include +#ifdef RN_SERIALIZABLE_STATE +#include +#endif + +namespace facebook::react { + +using ArrayPropsWithOptionalObjectGenNativeComponentState = StateData; } // namespace facebook::react", } @@ -721,7 +796,32 @@ Map { namespace facebook::react { -using ObjectPropsState = StateData; +using ObjectPropsWithOptionalGenState = StateData; + +} // namespace facebook::react", +} +`; + +exports[`GenerateStateH can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "States.h" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#include +#ifdef RN_SERIALIZABLE_STATE +#include +#endif + +namespace facebook::react { + +using ObjectPropsWithOptionalObjectGenState = StateData; } // namespace facebook::react", } diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap index 85b071c1d3e..b06982ce8f3 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateTests-test.js.snap @@ -332,6 +332,172 @@ TEST(AllPropWithOptionalGenProps_stringEnumProp_Option1, etc) { } `; +exports[`GenerateTests can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Tests.cpp" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateTests.js + * */ + +#include +#include +#include +#include +#include +#include +#include + +using namespace facebook::react; + +TEST(AllPropWithOptionalObjectGenProps_DoesNotDie, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_stringPropNoDefault, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"stringPropNoDefault\\", \\"foo\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_booleanPropNoDefault, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"booleanPropNoDefault\\", true)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_floatPropNoDefault, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"floatPropNoDefault\\", 0.1)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_stringProp, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"stringProp\\", \\"foo\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_booleanProp, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"booleanProp\\", false)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_floatProp, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"floatProp\\", 0)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_stringUserDefaultProp, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"stringUserDefaultProp\\", \\"user_default\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_booleanUserDefaultProp, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"booleanUserDefaultProp\\", true)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_floatUserDefaultProp, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"floatUserDefaultProp\\", 3.14)); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +} + +TEST(AllPropWithOptionalObjectGenProps_stringEnumProp_Option1, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + AllPropWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"stringEnumProp\\", \\"option1\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + AllPropWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); +}", +} +`; + exports[`GenerateTests can generate fixture ARRAY_PROPS 1`] = ` Map { "Tests.cpp" => "/** @@ -424,17 +590,52 @@ Map { using namespace facebook::react; -TEST(ArrayPropsNativeComponentProps_DoesNotDie, etc) { +TEST(ArrayPropsOptionalGenNativeComponentProps_DoesNotDie, etc) { RawPropsParser propParser{}; - propParser.prepare(); - ArrayPropsNativeComponentProps sourceProps{}; + propParser.prepare(); + ArrayPropsOptionalGenNativeComponentProps sourceProps{}; RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); ContextContainer contextContainer{}; PropsParserContext parserContext{-1, contextContainer}; rawProps.parse(propParser); - ArrayPropsNativeComponentProps(parserContext, sourceProps, rawProps); + ArrayPropsOptionalGenNativeComponentProps(parserContext, sourceProps, rawProps); +}", +} +`; + +exports[`GenerateTests can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Tests.cpp" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateTests.js + * */ + +#include +#include +#include +#include +#include +#include + +using namespace facebook::react; + +TEST(ArrayPropsOptionalObjectGenNativeComponentProps_DoesNotDie, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + ArrayPropsOptionalObjectGenNativeComponentProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + ArrayPropsOptionalObjectGenNativeComponentProps(parserContext, sourceProps, rawProps); }", } `; @@ -461,17 +662,54 @@ Map { using namespace facebook::react; -TEST(ArrayPropsNativeComponentProps_DoesNotDie, etc) { +TEST(ArrayPropsWithOptionalGenNativeComponentProps_DoesNotDie, etc) { RawPropsParser propParser{}; - propParser.prepare(); - ArrayPropsNativeComponentProps sourceProps{}; + propParser.prepare(); + ArrayPropsWithOptionalGenNativeComponentProps sourceProps{}; RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); ContextContainer contextContainer{}; PropsParserContext parserContext{-1, contextContainer}; rawProps.parse(propParser); - ArrayPropsNativeComponentProps(parserContext, sourceProps, rawProps); + ArrayPropsWithOptionalGenNativeComponentProps(parserContext, sourceProps, rawProps); +}", +} +`; + +exports[`GenerateTests can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Tests.cpp" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateTests.js + * */ + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace facebook::react; + +TEST(ArrayPropsWithOptionalObjectGenNativeComponentProps_DoesNotDie, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + ArrayPropsWithOptionalObjectGenNativeComponentProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + ArrayPropsWithOptionalObjectGenNativeComponentProps(parserContext, sourceProps, rawProps); }", } `; @@ -1519,17 +1757,53 @@ Map { using namespace facebook::react; -TEST(ObjectPropsProps_DoesNotDie, etc) { +TEST(ObjectPropsWithOptionalGenProps_DoesNotDie, etc) { RawPropsParser propParser{}; - propParser.prepare(); - ObjectPropsProps sourceProps{}; + propParser.prepare(); + ObjectPropsWithOptionalGenProps sourceProps{}; RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); ContextContainer contextContainer{}; PropsParserContext parserContext{-1, contextContainer}; rawProps.parse(propParser); - ObjectPropsProps(parserContext, sourceProps, rawProps); + ObjectPropsWithOptionalGenProps(parserContext, sourceProps, rawProps); +}", +} +`; + +exports[`GenerateTests can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "Tests.cpp" => "/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateTests.js + * */ + +#include +#include +#include +#include +#include +#include +#include + +using namespace facebook::react; + +TEST(ObjectPropsWithOptionalObjectGenProps_DoesNotDie, etc) { + RawPropsParser propParser{}; + propParser.prepare(); + ObjectPropsWithOptionalObjectGenProps sourceProps{}; + RawProps rawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser); + ObjectPropsWithOptionalObjectGenProps(parserContext, sourceProps, rawProps); }", } `; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap index 2bdd58140f0..6498bb69fbd 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderH-test.js.snap @@ -56,11 +56,15 @@ Class CommandNativeComponentCls(void) __attribute__((u Class ExcludedAndroidComponentCls(void) __attribute__((used)); // EXCLUDE_ANDROID Class MultiFileIncludedNativeComponentCls(void) __attribute__((used)); // EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES -Class ArrayPropsNativeComponentCls(void) __attribute__((used)); // ARRAY_PROPS_WITH_OPTIONAL_GEN -Class ArrayPropsNativeComponentCls(void) __attribute__((used)); // ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN -Class ObjectPropsCls(void) __attribute__((used)); // OBJECT_PROPS_WITH_OPTIONAL_GEN Class AllPropCls(void) __attribute__((used)); // ALL_PROP Class AllPropWithOptionalGenCls(void) __attribute__((used)); // ALL_PROP_WITH_OPTIONAL_GEN +Class AllPropWithOptionalObjectGenCls(void) __attribute__((used)); // ALL_PROP_WITH_OPTIONAL_OBJECT_GEN +Class ArrayPropsWithOptionalGenNativeComponentCls(void) __attribute__((used)); // ARRAY_PROPS_WITH_OPTIONAL_GEN +Class ArrayPropsWithOptionalObjectGenNativeComponentCls(void) __attribute__((used)); // ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN +Class ArrayPropsOptionalGenNativeComponentCls(void) __attribute__((used)); // ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN +Class ArrayPropsOptionalObjectGenNativeComponentCls(void) __attribute__((used)); // ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN +Class ObjectPropsWithOptionalGenCls(void) __attribute__((used)); // OBJECT_PROPS_WITH_OPTIONAL_GEN +Class ObjectPropsWithOptionalObjectGenCls(void) __attribute__((used)); // OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN #endif #endif diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap index 9c322875e52..d3313843364 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateThirdPartyFabricComponentsProviderObjCpp-test.js.snap @@ -84,15 +84,23 @@ Class RCTThirdPartyFabricComponentsProvider(const char {\\"MultiFileIncludedNativeComponent\\", MultiFileIncludedNativeComponentCls}, // EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES - {\\"ArrayPropsNativeComponent\\", ArrayPropsNativeComponentCls}, // ARRAY_PROPS_WITH_OPTIONAL_GEN - - {\\"ArrayPropsNativeComponent\\", ArrayPropsNativeComponentCls}, // ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN - - {\\"ObjectProps\\", ObjectPropsCls}, // OBJECT_PROPS_WITH_OPTIONAL_GEN - {\\"AllProp\\", AllPropCls}, // ALL_PROP {\\"AllPropWithOptionalGen\\", AllPropWithOptionalGenCls}, // ALL_PROP_WITH_OPTIONAL_GEN + + {\\"AllPropWithOptionalObjectGen\\", AllPropWithOptionalObjectGenCls}, // ALL_PROP_WITH_OPTIONAL_OBJECT_GEN + + {\\"ArrayPropsWithOptionalGenNativeComponent\\", ArrayPropsWithOptionalGenNativeComponentCls}, // ARRAY_PROPS_WITH_OPTIONAL_GEN + + {\\"ArrayPropsWithOptionalObjectGenNativeComponent\\", ArrayPropsWithOptionalObjectGenNativeComponentCls}, // ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN + + {\\"ArrayPropsOptionalGenNativeComponent\\", ArrayPropsOptionalGenNativeComponentCls}, // ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_GEN + + {\\"ArrayPropsOptionalObjectGenNativeComponent\\", ArrayPropsOptionalObjectGenNativeComponentCls}, // ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN + + {\\"ObjectPropsWithOptionalGen\\", ObjectPropsWithOptionalGenCls}, // OBJECT_PROPS_WITH_OPTIONAL_GEN + + {\\"ObjectPropsWithOptionalObjectGen\\", ObjectPropsWithOptionalObjectGenCls}, // OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN #endif #endif }; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap index 9b0746a4fa9..a22f3421309 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -92,6 +92,52 @@ export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL } `; +exports[`GenerateViewConfigJs can generate fixture ALL_PROP_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ALL_PROP_WITH_OPTIONAL_OBJECT_GENNativeViewConfig.js" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @flow + * + * @generated by codegen project: GenerateViewConfigJs.js + */ + +'use strict'; + +const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); + +let nativeComponentName = 'AllPropWithOptionalObjectGen'; +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: \\"AllPropWithOptionalObjectGen\\", + validAttributes: { + stringPropNoDefault: true, + booleanPropNoDefault: true, + floatPropNoDefault: true, + stringProp: true, + booleanProp: true, + floatProp: true, + intProp: true, + stringUserDefaultProp: true, + booleanUserDefaultProp: true, + floatUserDefaultProp: true, + intUserDefaultProp: true, + stringEnumProp: true, + intEnumProp: true, + objectArrayProp: true, + objectPrimitiveRequiredProp: true, + nestedPropA: true, + nestedArrayAsProperty: true + } +}; +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); +", +} +`; + exports[`GenerateViewConfigJs can generate fixture ARRAY_PROPS 1`] = ` Map { "ARRAY_PROPSNativeViewConfig.js" => " @@ -184,9 +230,39 @@ Map { const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -let nativeComponentName = 'ArrayPropsNativeComponent'; +let nativeComponentName = 'ArrayPropsOptionalGenNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { - uiViewClassName: \\"ArrayPropsNativeComponent\\", + uiViewClassName: \\"ArrayPropsOptionalGenNativeComponent\\", + validAttributes: { + nativePrimitives: true + } +}; +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); +", +} +`; + +exports[`GenerateViewConfigJs can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ARRAY_PROPS_WITH_NESTED_OBJECT_WITH_OPTIONAL_OBJECT_GENNativeViewConfig.js" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @flow + * + * @generated by codegen project: GenerateViewConfigJs.js + */ + +'use strict'; + +const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); + +let nativeComponentName = 'ArrayPropsOptionalObjectGenNativeComponent'; +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: \\"ArrayPropsOptionalObjectGenNativeComponent\\", validAttributes: { nativePrimitives: true } @@ -214,9 +290,53 @@ Map { const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -let nativeComponentName = 'ArrayPropsNativeComponent'; +let nativeComponentName = 'ArrayPropsWithOptionalGenNativeComponent'; export const __INTERNAL_VIEW_CONFIG = { - uiViewClassName: \\"ArrayPropsNativeComponent\\", + uiViewClassName: \\"ArrayPropsWithOptionalGenNativeComponent\\", + validAttributes: { + names: true, + disableds: true, + progress: true, + radii: true, + colors: { + process: (req => 'default' in req ? req.default : req)(require('react-native/Libraries/StyleSheet/processColorArray')) + }, + srcs: true, + points: true, + dimensions: true, + sizes: true, + object: true, + array: true, + arrayOfArrayOfObject: true, + arrayOfMixed: true + } +}; +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); +", +} +`; + +exports[`GenerateViewConfigJs can generate fixture ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "ARRAY_PROPS_WITH_OPTIONAL_OBJECT_GENNativeViewConfig.js" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @flow + * + * @generated by codegen project: GenerateViewConfigJs.js + */ + +'use strict'; + +const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); + +let nativeComponentName = 'ArrayPropsWithOptionalObjectGenNativeComponent'; +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: \\"ArrayPropsWithOptionalObjectGenNativeComponent\\", validAttributes: { names: true, disableds: true, @@ -1048,9 +1168,39 @@ Map { const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); -let nativeComponentName = 'ObjectProps'; +let nativeComponentName = 'ObjectPropsWithOptionalGen'; export const __INTERNAL_VIEW_CONFIG = { - uiViewClassName: \\"ObjectProps\\", + uiViewClassName: \\"ObjectPropsWithOptionalGen\\", + validAttributes: { + objectProp: true + } +}; +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); +", +} +`; + +exports[`GenerateViewConfigJs can generate fixture OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GEN 1`] = ` +Map { + "OBJECT_PROPS_WITH_OPTIONAL_OBJECT_GENNativeViewConfig.js" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @flow + * + * @generated by codegen project: GenerateViewConfigJs.js + */ + +'use strict'; + +const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry'); + +let nativeComponentName = 'ObjectPropsWithOptionalObjectGen'; +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: \\"ObjectPropsWithOptionalObjectGen\\", validAttributes: { objectProp: true }