From 6b58dc37358a6c386971e01c389d1e11372895e8 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Sun, 9 Oct 2022 12:10:01 -0700 Subject: [PATCH] Add ImageSource and ImageRequest to generate custom NativeState Summary: This Diff adds supports on the CustomState generation for ImageSource and ImageRequests, to enable NativeComponents to use the ImageSource loading provided by React Native. To achieve this, I also had to fox some errors in the imports and to introduce some functions to decorate parameters. This diff also introduces the tests for thise additional types in both generators and parsers. ## Changelog [General][Added] - add support for ImageSource and ImageRequest in the State. Differential Revision: https://internalfb.com/D39884889 fbshipit-source-id: c2921db68090ca506642f874b24128015811c7d7 --- .../react-native-codegen/src/CodegenSchema.js | 3 +- .../components/ComponentsGeneratorUtils.js | 177 ++ .../src/generators/components/CppHelpers.js | 5 + .../generators/components/GeneratePropsH.js | 85 +- .../components/GeneratePropsJavaDelegate.js | 2 + .../components/GeneratePropsJavaInterface.js | 3 + .../GeneratePropsJavaPojo/serializePojo.js | 11 + .../generators/components/GenerateStateCpp.js | 12 +- .../generators/components/GenerateStateH.js | 76 +- .../components/GenerateViewConfigJs.js | 2 + .../components/__test_fixtures__/fixtures.js | 49 + .../GenerateComponentDescriptorH-test.js.snap | 28 + .../GenerateComponentHObjCpp-test.js.snap | 25 + .../GenerateEventEmitterCpp-test.js.snap | 25 + .../GenerateEventEmitterH-test.js.snap | 34 + .../GeneratePropsCpp-test.js.snap | 34 + .../__snapshots__/GeneratePropsH-test.js.snap | 37 + .../GeneratePropsJavaDelegate-test.js.snap | 38 + .../GeneratePropsJavaInterface-test.js.snap | 24 + .../GeneratePropsJavaPojo-test.js.snap | 29 + .../GenerateShadowNodeCpp-test.js.snap | 25 + .../GenerateShadowNodeH-test.js.snap | 40 + .../GenerateStateCpp-test.js.snap | 92 +- .../__snapshots__/GenerateStateH-test.js.snap | 1579 +++++++++-------- .../__snapshots__/GenerateTests-test.js.snap | 49 + ...artyFabricComponentsProviderH-test.js.snap | 1 + ...abricComponentsProviderObjCpp-test.js.snap | 2 + .../GenerateViewConfigJs-test.js.snap | 36 + .../components/__test_fixtures__/fixtures.js | 32 + .../component-parser-test.js.snap | 50 + .../flow/components/componentsUtils.js | 10 + .../components/__test_fixtures__/fixtures.js | 31 + .../typescript-component-parser-test.js.snap | 50 + .../typescript/components/componentsUtils.js | 10 + 34 files changed, 1832 insertions(+), 874 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 5f98933329e6fc..f5f130002aa5d9 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -183,7 +183,8 @@ export type ReservedPropTypeAnnotation = $ReadOnly<{ | 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive' - | 'EdgeInsetsPrimitive', + | 'EdgeInsetsPrimitive' + | 'ImageRequestPrimitive', }>; export type StateTypeAnnotation = PropTypeAnnotation; diff --git a/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js b/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js index 9b0244127cdb95..994a109ae4140e 100644 --- a/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js +++ b/packages/react-native-codegen/src/generators/components/ComponentsGeneratorUtils.js @@ -32,6 +32,7 @@ const { getEnumMaskName, getEnumName, generateStructName, + getImports, } = require('./CppHelpers.js'); function getNativeTypeFromAnnotation( @@ -77,6 +78,8 @@ function getNativeTypeFromAnnotation( return 'SharedColor'; case 'ImageSourcePrimitive': return 'ImageSource'; + case 'ImageRequestPrimitive': + return 'ImageRequest'; case 'PointPrimitive': return 'Point'; case 'EdgeInsetsPrimitive': @@ -152,7 +155,181 @@ function getStateConstituents( }; } +/// This function process some types if we need to customize them +/// For example, the ImageSource and the reserved types could be trasformed into +/// const address instead of using them as plain types. +function convertTypesToConstAddressIfNeeded( + type: string, + convertibleTypes: Set, +): string { + if (convertibleTypes.has(type)) { + return `${type} const &`; + } + return type; +} + +function convertValueToSharedPointerWithMove( + type: string, + value: string, + convertibleTypes: Set, +): string { + if (convertibleTypes.has(type)) { + return `std::make_shared<${type}>(std::move(${value}))`; + } + return value; +} + +function convertVariableToSharedPointer( + type: string, + convertibleTypes: Set, +): string { + if (convertibleTypes.has(type)) { + return `std::shared_ptr<${type}>`; + } + return type; +} + +function convertVariableToPointer( + type: string, + value: string, + convertibleTypes: Set, +): string { + if (convertibleTypes.has(type)) { + return `*${value}`; + } + return value; +} + +const convertCtorParamToAddressType = (type: string): string => { + const typesToConvert: Set = new Set(); + typesToConvert.add('ImageSource'); + + return convertTypesToConstAddressIfNeeded(type, typesToConvert); +}; + +const convertCtorInitToSharedPointers = ( + type: string, + value: string, +): string => { + const typesToConvert: Set = new Set(); + typesToConvert.add('ImageRequest'); + + return convertValueToSharedPointerWithMove(type, value, typesToConvert); +}; + +const convertGettersReturnTypeToAddressType = (type: string): string => { + const typesToConvert: Set = new Set(); + typesToConvert.add('ImageRequest'); + + return convertTypesToConstAddressIfNeeded(type, typesToConvert); +}; + +const convertVarTypeToSharedPointer = (type: string): string => { + const typesToConvert: Set = new Set(); + typesToConvert.add('ImageRequest'); + + return convertVariableToSharedPointer(type, typesToConvert); +}; + +const convertVarValueToPointer = (type: string, value: string): string => { + const typesToConvert: Set = new Set(); + typesToConvert.add('ImageRequest'); + + return convertVariableToPointer(type, value, typesToConvert); +}; + +function getLocalImports( + properties: + | $ReadOnlyArray> + | $ReadOnlyArray>, +): Set { + const imports: Set = new Set(); + + function addImportsForNativeName( + name: + | 'ColorPrimitive' + | 'EdgeInsetsPrimitive' + | 'ImageSourcePrimitive' + | 'PointPrimitive' + | 'ImageRequestPrimitive', + ) { + switch (name) { + case 'ColorPrimitive': + imports.add('#include '); + return; + case 'ImageSourcePrimitive': + imports.add('#include '); + return; + case 'ImageRequestPrimitive': + imports.add('#include '); + return; + case 'PointPrimitive': + imports.add('#include '); + return; + case 'EdgeInsetsPrimitive': + imports.add('#include '); + return; + default: + (name: empty); + throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`); + } + } + + properties.forEach(prop => { + const typeAnnotation = prop.typeAnnotation; + + if (typeAnnotation.type === 'ReservedPropTypeAnnotation') { + addImportsForNativeName(typeAnnotation.name); + } + + if (typeAnnotation.type === 'ArrayTypeAnnotation') { + imports.add('#include '); + if (typeAnnotation.elementType.type === 'StringEnumTypeAnnotation') { + imports.add('#include '); + } + } + + if ( + typeAnnotation.type === 'ArrayTypeAnnotation' && + typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation' + ) { + addImportsForNativeName(typeAnnotation.elementType.name); + } + + if ( + typeAnnotation.type === 'ArrayTypeAnnotation' && + typeAnnotation.elementType.type === 'ObjectTypeAnnotation' + ) { + const objectProps = typeAnnotation.elementType.properties; + const objectImports = getImports(objectProps); + const localImports = getLocalImports(objectProps); + // $FlowFixMe[method-unbinding] added when improving typing for this parameters + objectImports.forEach(imports.add, imports); + // $FlowFixMe[method-unbinding] added when improving typing for this parameters + localImports.forEach(imports.add, imports); + } + + if (typeAnnotation.type === 'ObjectTypeAnnotation') { + imports.add('#include '); + const objectImports = getImports(typeAnnotation.properties); + const localImports = getLocalImports(typeAnnotation.properties); + // $FlowFixMe[method-unbinding] added when improving typing for this parameters + objectImports.forEach(imports.add, imports); + // $FlowFixMe[method-unbinding] added when improving typing for this parameters + localImports.forEach(imports.add, imports); + } + }); + + return imports; +} + module.exports = { getNativeTypeFromAnnotation, getStateConstituents, + convertCtorParamToAddressType, + convertGettersReturnTypeToAddressType, + convertCtorInitToSharedPointers, + convertVarTypeToSharedPointer, + convertVarValueToPointer, + getLocalImports, }; diff --git a/packages/react-native-codegen/src/generators/components/CppHelpers.js b/packages/react-native-codegen/src/generators/components/CppHelpers.js index 608fd6d98127a5..2f222412878baf 100644 --- a/packages/react-native-codegen/src/generators/components/CppHelpers.js +++ b/packages/react-native-codegen/src/generators/components/CppHelpers.js @@ -61,6 +61,7 @@ function getImports( name: | 'ColorPrimitive' | 'EdgeInsetsPrimitive' + | 'ImageRequestPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive', ) { @@ -71,6 +72,8 @@ function getImports( return; case 'EdgeInsetsPrimitive': return; + case 'ImageRequestPrimitive': + return; case 'ImageSourcePrimitive': imports.add('#include '); return; @@ -163,6 +166,8 @@ function convertDefaultTypeToString( return ''; case 'ImageSourcePrimitive': return ''; + case 'ImageRequestPrimitive': + return ''; case 'PointPrimitive': return ''; case 'EdgeInsetsPrimitive': diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index 168dba84e12a06..008c5d410611e0 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -11,7 +11,10 @@ 'use strict'; import type {ComponentShape} from '../../CodegenSchema'; -const {getNativeTypeFromAnnotation} = require('./ComponentsGeneratorUtils.js'); +const { + getNativeTypeFromAnnotation, + getLocalImports, +} = require('./ComponentsGeneratorUtils.js'); const { convertDefaultTypeToString, @@ -19,7 +22,6 @@ const { getEnumName, toSafeCppString, generateStructName, - getImports, toIntEnumValueName, } = require('./CppHelpers.js'); @@ -500,85 +502,6 @@ function getExtendsImports( return imports; } -function getLocalImports( - properties: $ReadOnlyArray>, -): Set { - const imports: Set = new Set(); - - function addImportsForNativeName( - name: - | 'ColorPrimitive' - | 'EdgeInsetsPrimitive' - | 'ImageSourcePrimitive' - | 'PointPrimitive', - ) { - switch (name) { - case 'ColorPrimitive': - imports.add('#include '); - return; - case 'ImageSourcePrimitive': - imports.add('#include '); - return; - case 'PointPrimitive': - imports.add('#include '); - return; - case 'EdgeInsetsPrimitive': - imports.add('#include '); - return; - default: - (name: empty); - throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`); - } - } - - properties.forEach(prop => { - const typeAnnotation = prop.typeAnnotation; - - if (typeAnnotation.type === 'ReservedPropTypeAnnotation') { - addImportsForNativeName(typeAnnotation.name); - } - - if (typeAnnotation.type === 'ArrayTypeAnnotation') { - imports.add('#include '); - if (typeAnnotation.elementType.type === 'StringEnumTypeAnnotation') { - imports.add('#include '); - } - } - - if ( - typeAnnotation.type === 'ArrayTypeAnnotation' && - typeAnnotation.elementType.type === 'ReservedPropTypeAnnotation' - ) { - addImportsForNativeName(typeAnnotation.elementType.name); - } - - if ( - typeAnnotation.type === 'ArrayTypeAnnotation' && - typeAnnotation.elementType.type === 'ObjectTypeAnnotation' - ) { - const objectProps = typeAnnotation.elementType.properties; - const objectImports = getImports(objectProps); - const localImports = getLocalImports(objectProps); - // $FlowFixMe[method-unbinding] added when improving typing for this parameters - objectImports.forEach(imports.add, imports); - // $FlowFixMe[method-unbinding] added when improving typing for this parameters - localImports.forEach(imports.add, imports); - } - - if (typeAnnotation.type === 'ObjectTypeAnnotation') { - imports.add('#include '); - const objectImports = getImports(typeAnnotation.properties); - const localImports = getLocalImports(typeAnnotation.properties); - // $FlowFixMe[method-unbinding] added when improving typing for this parameters - objectImports.forEach(imports.add, imports); - // $FlowFixMe[method-unbinding] added when improving typing for this parameters - localImports.forEach(imports.add, imports); - } - }); - - return imports; -} - function generateStructsForComponent( componentName: string, component: ComponentShape, diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js index f39fe2a51d9055..bf058c1df18519 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js @@ -122,6 +122,8 @@ function getJavaValueForProp( return 'ColorPropConverter.getColor(value, view.getContext())'; case 'ImageSourcePrimitive': return '(ReadableMap) value'; + case 'ImageRequestPrimitive': + return '(ReadableMap) value'; case 'PointPrimitive': return '(ReadableMap) value'; case 'EdgeInsetsPrimitive': diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js index 5afeeb6e51db10..cdd5051647857c 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaInterface.js @@ -97,6 +97,9 @@ function getJavaValueForProp( case 'ImageSourcePrimitive': addNullable(imports); return '@Nullable ReadableMap value'; + case 'ImageRequestPrimitive': + addNullable(imports); + return '@Nullable ReadableMap value'; case 'PointPrimitive': addNullable(imports); return '@Nullable ReadableMap value'; diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/serializePojo.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/serializePojo.js index 3e3e2ad532dd59..c2c36c1ff61045 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/serializePojo.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaPojo/serializePojo.js @@ -81,6 +81,12 @@ function toJavaType( importReadableMap(); return '@Nullable ReadableMap'; + // TODO: Make ImageRequestPrimitive type-safe + case 'ImageRequestPrimitive': + importNullable(); + importReadableMap(); + return '@Nullable ReadableMap'; + // TODO: Make PointPrimitive type-safe case 'PointPrimitive': importNullable(); @@ -162,6 +168,11 @@ function toJavaType( importReadableMap(); return 'ReadableMap'; + // TODO: Make ImageRequestPrimitive type-safe + case 'ImageRequestPrimitive': + importReadableMap(); + return 'ReadableMap'; + // TODO: Make PointPrimitive type-safe case 'PointPrimitive': importReadableMap(); diff --git a/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js b/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js index 5f8f0c39b0a22f..2e8a1843c0d630 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js +++ b/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js @@ -16,7 +16,11 @@ import type { StateTypeAnnotation, } from '../../CodegenSchema'; const {capitalize} = require('../Utils.js'); -const {getStateConstituents} = require('./ComponentsGeneratorUtils.js'); +const { + getStateConstituents, + convertGettersReturnTypeToAddressType, + convertVarValueToPointer, +} = require('./ComponentsGeneratorUtils.js'); // File path -> contents type FilesOutput = Map; @@ -59,8 +63,10 @@ function generateStrings( ); getters += ` -${type} ${componentName}::get${capitalize(name)}() const { - return ${varName}; +${convertGettersReturnTypeToAddressType( + type, +)} ${componentName}State::get${capitalize(name)}() const { + return ${convertVarValueToPointer(type, varName)}; } `; }); diff --git a/packages/react-native-codegen/src/generators/components/GenerateStateH.js b/packages/react-native-codegen/src/generators/components/GenerateStateH.js index 24520e311c5c2a..355dfdf995e7ee 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateStateH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateStateH.js @@ -16,16 +16,25 @@ import type { StateTypeAnnotation, } from '../../CodegenSchema'; const {capitalize} = require('../Utils.js'); -const {getStateConstituents} = require('./ComponentsGeneratorUtils.js'); +const { + getStateConstituents, + convertCtorParamToAddressType, + convertGettersReturnTypeToAddressType, + convertCtorInitToSharedPointers, + convertVarTypeToSharedPointer, + getLocalImports, +} = require('./ComponentsGeneratorUtils.js'); // File path -> contents type FilesOutput = Map; const FileTemplate = ({ libraryName, + imports, stateClasses, }: { libraryName: string, + imports: string, stateClasses: string, }) => ` @@ -47,6 +56,8 @@ const FileTemplate = ({ #include #endif +${imports} + namespace facebook { namespace react { @@ -71,34 +82,31 @@ const StateTemplate = ({ }) => { let stateWithParams = ''; if (ctorParams.length > 0) { - stateWithParams = ` - ${stateName}State( - ${ctorParams} - ) - : ${ctorInits}{}; - `; + stateWithParams = `${stateName}State( + ${ctorParams}) + : ${ctorInits}{};`; } return ` class ${stateName}State { - public: - ${stateWithParams} - ${stateName}State() = default; +public: + ${stateWithParams} + ${stateName}State() = default; - ${getters} + ${getters} #ifdef ANDROID - ${stateName}State(${stateName}State const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ${stateName}State(${stateName}State const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - ${stateProps} +private: + ${stateProps} }; `.trim(); }; @@ -130,14 +138,21 @@ function generateStrings( stateShape, ); - ctorParams += ` ${type} ${name},\n`; - ctorInits += `${varName}(${name}),\n `; - getters += `${type} get${capitalize(name)}() const;\n `; + ctorParams += `${convertCtorParamToAddressType(type)} ${name},\n `; + ctorInits += `${varName}(${convertCtorInitToSharedPointers( + type, + name, + )}),\n `; + getters += `${convertGettersReturnTypeToAddressType(type)} get${capitalize( + name, + )}() const;\n `; let finalDefaultValue = defaultValue; if (defaultValue.length > 0) { finalDefaultValue = `{${defaultValue}}`; } - stateProps += ` ${type} ${varName}${finalDefaultValue};\n `; + stateProps += ` ${convertVarTypeToSharedPointer( + type, + )} ${varName}${finalDefaultValue};\n `; }); // Sanitize @@ -161,6 +176,8 @@ module.exports = { ): FilesOutput { const fileName = 'States.h'; + const allImports: Set = new Set(); + const stateClasses = Object.keys(schema.modules) .map(moduleName => { const module = schema.modules[moduleName]; @@ -194,6 +211,11 @@ module.exports = { const {ctorParams, ctorInits, getters, stateProps} = generateStrings(componentName, state); + const imports = getLocalImports(state); + + // $FlowFixMe[method-unbinding] added when improving typing for this parameters + imports.forEach(allImports.add, allImports); + return StateTemplate({ stateName: componentName, ctorParams, @@ -208,7 +230,11 @@ module.exports = { .filter(Boolean) .join('\n\n'); - const template = FileTemplate({libraryName, stateClasses}); + const template = FileTemplate({ + libraryName, + imports: Array.from(allImports).sort().join('\n'), + stateClasses, + }); return new Map([[fileName, template]]); }, }; diff --git a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js index d81748a7de6771..efdea0ec5ade6b 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js @@ -70,6 +70,8 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) { case 'ImageSourcePrimitive': return j.template .expression`{ process: require('react-native/Libraries/Image/resolveAssetSource') }`; + case 'ImageRequestPrimitive': + throw new Error('ImageRequest should not be used in props'); case 'PointPrimitive': return j.template .expression`{ diff: require('react-native/Libraries/Utilities/differ/pointsDiffer') }`; 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 abc7cadf8c8afb..77d3060d58297e 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 @@ -2483,6 +2483,54 @@ const COMPONENT_WITH_INT_ENUM_STATE: SchemaType = { }, }; +const COMPONENTS_WITH_IMAGES_IN_STATE: SchemaType = { + modules: { + MyComponent: { + type: 'Component', + components: { + SimpleComponent: { + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'imageSource', + optional: false, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + ], + commands: [], + state: [ + { + name: 'imageSource', + optional: false, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + { + name: 'imageRequest', + optional: false, + typeAnnotation: { + type: 'ReservedPropTypeAnnotation', + name: 'ImageRequestPrimitive', + }, + }, + ], + }, + }, + }, + }, +}; + module.exports = { NO_PROPS_NO_EVENTS, INTERFACE_ONLY, @@ -2525,4 +2573,5 @@ module.exports = { COMPONENT_WITH_ARRAY_OF_OBJECTS_STATE, COMPONENT_WITH_STRING_ENUM_STATE_PROPS, COMPONENT_WITH_INT_ENUM_STATE, + COMPONENTS_WITH_IMAGES_IN_STATE, }; 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 4555d7aa5a4113..cfd91b6c6edaf4 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 @@ -560,6 +560,34 @@ using SimpleComponentComponentDescriptor = ConcreteComponentDescriptor " +/** + * 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 + +namespace facebook { +namespace react { + +using SimpleComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateComponentDescriptorH can generate fixture DOUBLE_PROPS 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 cca8a5d707a190..df6660fa8c3782 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 @@ -636,6 +636,31 @@ NS_ASSUME_NONNULL_END", } `; +exports[`GenerateComponentHObjCpp can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 RCTSimpleComponentViewProtocol + +@end + +NS_ASSUME_NONNULL_END", +} +`; + exports[`GenerateComponentHObjCpp can generate fixture DOUBLE_PROPS 1`] = ` Map { "RCTComponentViewHelpers.h" => "/** 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 27acf965121923..b89cfa6c126c0a 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 @@ -494,6 +494,31 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 { +namespace react { + + + } // namespace react } // namespace facebook ", 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 715f181cd61df8..8255d75631cc2b 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 @@ -672,6 +672,40 @@ class JSI_EXPORT SimpleComponentEventEmitter : public ViewEventEmitter { +}; + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 +#include + +namespace facebook { +namespace react { + +class JSI_EXPORT SimpleComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + }; } // namespace react 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 6056796857e3ab..29c8a79a20d57b 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 @@ -671,6 +671,40 @@ SimpleComponentProps::SimpleComponentProps( } `; +exports[`GeneratePropsCpp can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 { +namespace react { + +SimpleComponentProps::SimpleComponentProps( + const PropsParserContext &context, + const SimpleComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(context, sourceProps, rawProps), + + imageSource(convertRawProp(context, rawProps, \\"imageSource\\", sourceProps.imageSource, {})) + {} + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsCpp can generate fixture DOUBLE_PROPS 1`] = ` Map { "Props.cpp" => " 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 908a1746d771da..88f56072d74278 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 @@ -943,6 +943,43 @@ class JSI_EXPORT SimpleComponentProps final : public ViewProps { } `; +exports[`GeneratePropsH can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 + +namespace facebook { +namespace react { + +class JSI_EXPORT SimpleComponentProps final : public ViewProps { + public: + SimpleComponentProps() = default; + SimpleComponentProps(const PropsParserContext& context, const SimpleComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + ImageSource imageSource{}; +}; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsH can generate fixture DOUBLE_PROPS 1`] = ` Map { "Props.h" => " 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 0c2e907967828d..be52cfb9fc62fd 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 @@ -709,6 +709,44 @@ public class SimpleComponentManagerDelegate "/** +* 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.BaseViewManagerDelegate; +import com.facebook.react.uimanager.BaseViewManagerInterface; + +public class SimpleComponentManagerDelegate & SimpleComponentManagerInterface> extends BaseViewManagerDelegate { + public SimpleComponentManagerDelegate(U viewManager) { + super(viewManager); + } + @Override + public void setProperty(T view, String propName, @Nullable Object value) { + switch (propName) { + case \\"imageSource\\": + mViewManager.setImageSource(view, (ReadableMap) value); + break; + default: + super.setProperty(view, propName, value); + } + } +} +", +} +`; + exports[`GeneratePropsJavaDelegate can generate fixture DOUBLE_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/DoublePropNativeComponentManagerDelegate.java" => "/** 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 a80797694926a2..b3fc55fb785898 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 @@ -460,6 +460,30 @@ public interface SimpleComponentManagerInterface { } `; +exports[`GeneratePropsJavaInterface can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/SimpleComponentManagerInterface.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; + +public interface SimpleComponentManagerInterface { + void setImageSource(T view, @Nullable ReadableMap value); +} +", +} +`; + exports[`GeneratePropsJavaInterface can generate fixture DOUBLE_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/DoublePropNativeComponentManagerInterface.java" => "/** 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 b8315f88c3191f..3fe66b223cce6a 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 @@ -676,6 +676,35 @@ public class SimpleComponentProps { } `; +exports[`GeneratePropsJavaPojo can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 1`] = ` +Map { + "java/com/facebook/react/viewmanagers/MyComponent/SimpleComponentProps.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.MyComponent; + +import androidx.annotation.Nullable; +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReadableMap; + +@DoNotStrip +public class SimpleComponentProps { + private @Nullable ReadableMap mImageSource; + @DoNotStrip + public @Nullable ReadableMap getImageSource() { + return mImageSource; + } +} +", +} +`; + exports[`GeneratePropsJavaPojo can generate fixture DOUBLE_PROPS 1`] = ` Map { "java/com/facebook/react/viewmanagers/Switch/DoublePropNativeComponentProps.java" => "/** 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 25a9aa58bf5401..d71cc8d3952341 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 @@ -500,6 +500,31 @@ extern const char SimpleComponentComponentName[] = \\"SimpleComponent\\"; } `; +exports[`GenerateShadowNodeCpp can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 { +namespace react { + +extern const char SimpleComponentComponentName[] = \\"SimpleComponent\\"; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeCpp can generate fixture DOUBLE_PROPS 1`] = ` Map { "ShadowNodes.cpp" => " 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 ae384f30fee88b..6096930006eed2 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 @@ -800,6 +800,46 @@ using SimpleComponentShadowNode = ConcreteViewShadowNode< } `; +exports[`GenerateShadowNodeH can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 { +namespace react { + +JSI_EXPORT extern const char SimpleComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using SimpleComponentShadowNode = ConcreteViewShadowNode< + SimpleComponentComponentName, + SimpleComponentProps, + SimpleComponentEventEmitter, + SimpleComponentState>; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeH can generate fixture DOUBLE_PROPS 1`] = ` Map { "ShadowNodes.h" => " 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 85fac1d0d71214..b9dd5fe9965663 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 @@ -160,7 +160,7 @@ Map { namespace facebook { namespace react { -std::vector SimpleComponent::getArrayState() const { +std::vector SimpleComponentState::getArrayState() const { return arrayState_; } @@ -186,47 +186,47 @@ Map { namespace facebook { namespace react { -std::vector SimpleComponent::getNames() const { +std::vector SimpleComponentState::getNames() const { return names_; } -std::vector SimpleComponent::getDisableds() const { +std::vector SimpleComponentState::getDisableds() const { return disableds_; } -std::vector SimpleComponent::getProgress() const { +std::vector SimpleComponentState::getProgress() const { return progress_; } -std::vector SimpleComponent::getRadii() const { +std::vector SimpleComponentState::getRadii() const { return radii_; } -std::vector SimpleComponent::getColors() const { +std::vector SimpleComponentState::getColors() const { return colors_; } -std::vector SimpleComponent::getSrcs() const { +std::vector SimpleComponentState::getSrcs() const { return srcs_; } -std::vector SimpleComponent::getPoints() const { +std::vector SimpleComponentState::getPoints() const { return points_; } -SimpleComponentSizesMask SimpleComponent::getSizes() const { +SimpleComponentSizesMask SimpleComponentState::getSizes() const { return sizes_; } -std::vector SimpleComponent::getObject() const { +std::vector SimpleComponentState::getObject() const { return object_; } -std::vector SimpleComponent::getArray() const { +std::vector SimpleComponentState::getArray() const { return array_; } -std::vector> SimpleComponent::getArrayOfArrayOfObject() const { +std::vector> SimpleComponentState::getArrayOfArrayOfObject() const { return arrayOfArrayOfObject_; } @@ -252,7 +252,7 @@ Map { namespace facebook { namespace react { -bool SimpleComponent::getDisabled() const { +bool SimpleComponentState::getDisabled() const { return disabled_; } @@ -278,7 +278,7 @@ Map { namespace facebook { namespace react { -SharedColor SimpleComponent::getTintColor() const { +SharedColor SimpleComponentState::getTintColor() const { return tintColor_; } @@ -304,15 +304,15 @@ Map { namespace facebook { namespace react { -double SimpleComponent::getD_blurRadius() const { +double SimpleComponentState::getD_blurRadius() const { return d_blurRadius_; } -double SimpleComponent::getD_blurRadius2() const { +double SimpleComponentState::getD_blurRadius2() const { return d_blurRadius2_; } -double SimpleComponent::getD_blurRadius3() const { +double SimpleComponentState::getD_blurRadius3() const { return d_blurRadius3_; } @@ -338,7 +338,7 @@ Map { namespace facebook { namespace react { -EdgeInsets SimpleComponent::getContentInset() const { +EdgeInsets SimpleComponentState::getContentInset() const { return contentInset_; } @@ -364,15 +364,15 @@ Map { namespace facebook { namespace react { -Float SimpleComponent::getBlurRadius() const { +Float SimpleComponentState::getBlurRadius() const { return blurRadius_; } -Float SimpleComponent::getBlurRadius2() const { +Float SimpleComponentState::getBlurRadius2() const { return blurRadius2_; } -Float SimpleComponent::getBlurRadius3() const { +Float SimpleComponentState::getBlurRadius3() const { return blurRadius3_; } @@ -398,7 +398,7 @@ Map { namespace facebook { namespace react { -ImageSource SimpleComponent::getThumbImage() const { +ImageSource SimpleComponentState::getThumbImage() const { return thumbImage_; } @@ -424,7 +424,7 @@ Map { namespace facebook { namespace react { -SimpleComponentMaxInterval SimpleComponent::getMaxInterval() const { +SimpleComponentMaxInterval SimpleComponentState::getMaxInterval() const { return maxInterval_; } @@ -450,15 +450,15 @@ Map { namespace facebook { namespace react { -int SimpleComponent::getProgress1() const { +int SimpleComponentState::getProgress1() const { return progress1_; } -int SimpleComponent::getProgress2() const { +int SimpleComponentState::getProgress2() const { return progress2_; } -int SimpleComponent::getProgress3() const { +int SimpleComponentState::getProgress3() const { return progress3_; } @@ -484,7 +484,7 @@ Map { namespace facebook { namespace react { -SimpleComponentObjectPropStruct SimpleComponent::getObjectProp() const { +SimpleComponentObjectPropStruct SimpleComponentState::getObjectProp() const { return objectProp_; } @@ -510,7 +510,7 @@ Map { namespace facebook { namespace react { -Point SimpleComponent::getStartPoint() const { +Point SimpleComponentState::getStartPoint() const { return startPoint_; } @@ -536,7 +536,7 @@ Map { namespace facebook { namespace react { -SimpleComponentAlignment SimpleComponent::getAlignment() const { +SimpleComponentAlignment SimpleComponentState::getAlignment() const { return alignment_; } @@ -562,11 +562,11 @@ Map { namespace facebook { namespace react { -std::string SimpleComponent::getAccessibilityHint() const { +std::string SimpleComponentState::getAccessibilityHint() const { return accessibilityHint_; } -std::string SimpleComponent::getAccessibilityRole() const { +std::string SimpleComponentState::getAccessibilityRole() const { return accessibilityRole_; } @@ -576,6 +576,36 @@ std::string SimpleComponent::getAccessibilityRole() const { } `; +exports[`GenerateStateCpp can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 { +namespace react { + +ImageSource SimpleComponentState::getImageSource() const { + return imageSource_; +} + +ImageRequest const & SimpleComponentState::getImageRequest() const { + return *imageRequest_; +} + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateStateCpp can generate fixture DOUBLE_PROPS 1`] = ` Map { "States.cpp" => " 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 e4737f93112169..3a938546f47813 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 @@ -20,28 +20,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ArrayPropsNativeComponentState { - public: - - ArrayPropsNativeComponentState() = default; +public: + + ArrayPropsNativeComponentState() = default; - + #ifdef ANDROID - ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -69,28 +71,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ArrayPropsNativeComponentState { - public: - - ArrayPropsNativeComponentState() = default; +public: + + ArrayPropsNativeComponentState() = default; - + #ifdef ANDROID - ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -118,28 +122,30 @@ Map { #include #endif + + namespace facebook { namespace react { class BooleanPropNativeComponentState { - public: - - BooleanPropNativeComponentState() = default; +public: + + BooleanPropNativeComponentState() = default; - + #ifdef ANDROID - BooleanPropNativeComponentState(BooleanPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + BooleanPropNativeComponentState(BooleanPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -167,28 +173,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ColorPropNativeComponentState { - public: - - ColorPropNativeComponentState() = default; +public: + + ColorPropNativeComponentState() = default; - + #ifdef ANDROID - ColorPropNativeComponentState(ColorPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ColorPropNativeComponentState(ColorPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -216,28 +224,30 @@ Map { #include #endif + + namespace facebook { namespace react { class CommandNativeComponentState { - public: - - CommandNativeComponentState() = default; +public: + + CommandNativeComponentState() = default; - + #ifdef ANDROID - CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -265,28 +275,30 @@ Map { #include #endif + + namespace facebook { namespace react { class CommandNativeComponentState { - public: - - CommandNativeComponentState() = default; +public: + + CommandNativeComponentState() = default; - + #ifdef ANDROID - CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -314,35 +326,38 @@ Map { #include #endif +#include +#include +#include +#include +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - std::vector arrayState - ) - : arrayState_(arrayState){}; - - SimpleComponentState() = default; - - std::vector getArrayState() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - std::vector arrayState_; - +public: + SimpleComponentState( + std::vector arrayState) + : arrayState_(arrayState){}; + SimpleComponentState() = default; + + std::vector getArrayState() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + std::vector arrayState_; + }; } // namespace react @@ -370,14 +385,19 @@ Map { #include #endif +#include +#include +#include +#include +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - std::vector names, +public: + SimpleComponentState( + std::vector names, std::vector disableds, std::vector progress, std::vector radii, @@ -387,9 +407,8 @@ class SimpleComponentState { SimpleComponentSizesMask sizes, std::vector object, std::vector array, - std::vector> arrayOfArrayOfObject - ) - : names_(names), + std::vector> arrayOfArrayOfObject) + : names_(names), disableds_(disableds), progress_(progress), radii_(radii), @@ -400,45 +419,44 @@ class SimpleComponentState { object_(object), array_(array), arrayOfArrayOfObject_(arrayOfArrayOfObject){}; - - SimpleComponentState() = default; - - std::vector getNames() const; - std::vector getDisableds() const; - std::vector getProgress() const; - std::vector getRadii() const; - std::vector getColors() const; - std::vector getSrcs() const; - std::vector getPoints() const; - SimpleComponentSizesMask getSizes() const; - std::vector getObject() const; - std::vector getArray() const; - std::vector> getArrayOfArrayOfObject() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - std::vector names_; - std::vector disableds_; - std::vector progress_; - std::vector radii_; - std::vector colors_; - std::vector srcs_; - std::vector points_; - SimpleComponentSizesMask sizes_{static_cast(SimpleComponentSizes::Small)}; - std::vector object_; - std::vector array_; - std::vector> arrayOfArrayOfObject_; - + SimpleComponentState() = default; + + std::vector getNames() const; + std::vector getDisableds() const; + std::vector getProgress() const; + std::vector getRadii() const; + std::vector getColors() const; + std::vector getSrcs() const; + std::vector getPoints() const; + SimpleComponentSizesMask getSizes() const; + std::vector getObject() const; + std::vector getArray() const; + std::vector> getArrayOfArrayOfObject() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + std::vector names_; + std::vector disableds_; + std::vector progress_; + std::vector radii_; + std::vector colors_; + std::vector srcs_; + std::vector points_; + SimpleComponentSizesMask sizes_{static_cast(SimpleComponentSizes::Small)}; + std::vector object_; + std::vector array_; + std::vector> arrayOfArrayOfObject_; + }; } // namespace react @@ -466,35 +484,34 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - bool disabled - ) - : disabled_(disabled){}; - - SimpleComponentState() = default; - - bool getDisabled() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - bool disabled_{false}; - +public: + SimpleComponentState( + bool disabled) + : disabled_(disabled){}; + SimpleComponentState() = default; + + bool getDisabled() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + bool disabled_{false}; + }; } // namespace react @@ -522,35 +539,34 @@ Map { #include #endif +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - SharedColor tintColor - ) - : tintColor_(tintColor){}; - - SimpleComponentState() = default; - - SharedColor getTintColor() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - SharedColor tintColor_; - +public: + SimpleComponentState( + SharedColor tintColor) + : tintColor_(tintColor){}; + SimpleComponentState() = default; + + SharedColor getTintColor() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + SharedColor tintColor_; + }; } // namespace react @@ -578,43 +594,42 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - double d_blurRadius, +public: + SimpleComponentState( + double d_blurRadius, double d_blurRadius2, - double d_blurRadius3 - ) - : d_blurRadius_(d_blurRadius), + double d_blurRadius3) + : d_blurRadius_(d_blurRadius), d_blurRadius2_(d_blurRadius2), d_blurRadius3_(d_blurRadius3){}; - - SimpleComponentState() = default; + SimpleComponentState() = default; - double getD_blurRadius() const; - double getD_blurRadius2() const; - double getD_blurRadius3() const; - + double getD_blurRadius() const; + double getD_blurRadius2() const; + double getD_blurRadius3() const; + #ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - double d_blurRadius_{0.0}; - double d_blurRadius2_{8.9}; - double d_blurRadius3_{-0.5}; - +private: + double d_blurRadius_{0.0}; + double d_blurRadius2_{8.9}; + double d_blurRadius3_{-0.5}; + }; } // namespace react @@ -642,35 +657,34 @@ Map { #include #endif +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - EdgeInsets contentInset - ) - : contentInset_(contentInset){}; - - SimpleComponentState() = default; - - EdgeInsets getContentInset() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - EdgeInsets contentInset_; - +public: + SimpleComponentState( + EdgeInsets contentInset) + : contentInset_(contentInset){}; + SimpleComponentState() = default; + + EdgeInsets getContentInset() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + EdgeInsets contentInset_; + }; } // namespace react @@ -698,43 +712,42 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - Float blurRadius, +public: + SimpleComponentState( + Float blurRadius, Float blurRadius2, - Float blurRadius3 - ) - : blurRadius_(blurRadius), + Float blurRadius3) + : blurRadius_(blurRadius), blurRadius2_(blurRadius2), blurRadius3_(blurRadius3){}; - - SimpleComponentState() = default; + SimpleComponentState() = default; - Float getBlurRadius() const; - Float getBlurRadius2() const; - Float getBlurRadius3() const; - + Float getBlurRadius() const; + Float getBlurRadius2() const; + Float getBlurRadius3() const; + #ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - Float blurRadius_{0.0}; - Float blurRadius2_{7.5}; - Float blurRadius3_{-2.1}; - +private: + Float blurRadius_{0.0}; + Float blurRadius2_{7.5}; + Float blurRadius3_{-2.1}; + }; } // namespace react @@ -762,35 +775,34 @@ Map { #include #endif +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - ImageSource thumbImage - ) - : thumbImage_(thumbImage){}; - - SimpleComponentState() = default; - - ImageSource getThumbImage() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - ImageSource thumbImage_; - +public: + SimpleComponentState( + ImageSource const & thumbImage) + : thumbImage_(thumbImage){}; + SimpleComponentState() = default; + + ImageSource getThumbImage() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + ImageSource thumbImage_; + }; } // namespace react @@ -818,35 +830,34 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - SimpleComponentMaxInterval maxInterval - ) - : maxInterval_(maxInterval){}; - - SimpleComponentState() = default; - - SimpleComponentMaxInterval getMaxInterval() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - SimpleComponentMaxInterval maxInterval_{SimpleComponentMaxInterval::MaxInterval0}; - +public: + SimpleComponentState( + SimpleComponentMaxInterval maxInterval) + : maxInterval_(maxInterval){}; + SimpleComponentState() = default; + + SimpleComponentMaxInterval getMaxInterval() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + SimpleComponentMaxInterval maxInterval_{SimpleComponentMaxInterval::MaxInterval0}; + }; } // namespace react @@ -874,43 +885,42 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - int progress1, +public: + SimpleComponentState( + int progress1, int progress2, - int progress3 - ) - : progress1_(progress1), + int progress3) + : progress1_(progress1), progress2_(progress2), progress3_(progress3){}; - - SimpleComponentState() = default; + SimpleComponentState() = default; - int getProgress1() const; - int getProgress2() const; - int getProgress3() const; - + int getProgress1() const; + int getProgress2() const; + int getProgress3() const; + #ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - int progress1_{0}; - int progress2_{-1}; - int progress3_{10}; - +private: + int progress1_{0}; + int progress2_{-1}; + int progress3_{10}; + }; } // namespace react @@ -938,35 +948,39 @@ Map { #include #endif +#include +#include +#include +#include +#include +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - SimpleComponentObjectPropStruct objectProp - ) - : objectProp_(objectProp){}; - - SimpleComponentState() = default; - - SimpleComponentObjectPropStruct getObjectProp() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - SimpleComponentObjectPropStruct objectProp_; - +public: + SimpleComponentState( + SimpleComponentObjectPropStruct objectProp) + : objectProp_(objectProp){}; + SimpleComponentState() = default; + + SimpleComponentObjectPropStruct getObjectProp() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + SimpleComponentObjectPropStruct objectProp_; + }; } // namespace react @@ -994,35 +1008,34 @@ Map { #include #endif +#include + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - Point startPoint - ) - : startPoint_(startPoint){}; - - SimpleComponentState() = default; - - Point getStartPoint() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - Point startPoint_; - +public: + SimpleComponentState( + Point startPoint) + : startPoint_(startPoint){}; + SimpleComponentState() = default; + + Point getStartPoint() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + Point startPoint_; + }; } // namespace react @@ -1050,35 +1063,34 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - SimpleComponentAlignment alignment - ) - : alignment_(alignment){}; - - SimpleComponentState() = default; - - SimpleComponentAlignment getAlignment() const; - - -#ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; -#endif - - private: - SimpleComponentAlignment alignment_{SimpleComponentAlignment::Center}; - +public: + SimpleComponentState( + SimpleComponentAlignment alignment) + : alignment_(alignment){}; + SimpleComponentState() = default; + + SimpleComponentAlignment getAlignment() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + SimpleComponentAlignment alignment_{SimpleComponentAlignment::Center}; + }; } // namespace react @@ -1106,39 +1118,98 @@ Map { #include #endif + + namespace facebook { namespace react { class SimpleComponentState { - public: - - SimpleComponentState( - std::string accessibilityHint, - std::string accessibilityRole - ) - : accessibilityHint_(accessibilityHint), +public: + SimpleComponentState( + std::string accessibilityHint, + std::string accessibilityRole) + : accessibilityHint_(accessibilityHint), accessibilityRole_(accessibilityRole){}; - - SimpleComponentState() = default; + SimpleComponentState() = default; + + std::string getAccessibilityHint() const; + std::string getAccessibilityRole() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + std::string accessibilityHint_{\\"\\"}; + std::string accessibilityRole_; + +}; + +} // namespace react +} // namespace facebook", +} +`; + +exports[`GenerateStateH can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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 - std::string getAccessibilityHint() const; - std::string getAccessibilityRole() const; - +#include #ifdef ANDROID - SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; +#include +#include +#include #endif - private: - std::string accessibilityHint_{\\"\\"}; - std::string accessibilityRole_; - +#include +#include + +namespace facebook { +namespace react { + +class SimpleComponentState { +public: + SimpleComponentState( + ImageSource const & imageSource, + ImageRequest imageRequest) + : imageSource_(imageSource), + imageRequest_(std::make_shared(std::move(imageRequest))){}; + SimpleComponentState() = default; + + ImageSource getImageSource() const; + ImageRequest const & getImageRequest() const; + + +#ifdef ANDROID + SimpleComponentState(SimpleComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif + +private: + ImageSource imageSource_; + std::shared_ptr imageRequest_; + }; } // namespace react @@ -1166,28 +1237,30 @@ Map { #include #endif + + namespace facebook { namespace react { class DoublePropNativeComponentState { - public: - - DoublePropNativeComponentState() = default; +public: + + DoublePropNativeComponentState() = default; - + #ifdef ANDROID - DoublePropNativeComponentState(DoublePropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + DoublePropNativeComponentState(DoublePropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1215,28 +1288,30 @@ Map { #include #endif + + namespace facebook { namespace react { class EventsNestedObjectNativeComponentState { - public: - - EventsNestedObjectNativeComponentState() = default; +public: + + EventsNestedObjectNativeComponentState() = default; - + #ifdef ANDROID - EventsNestedObjectNativeComponentState(EventsNestedObjectNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + EventsNestedObjectNativeComponentState(EventsNestedObjectNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1264,28 +1339,30 @@ Map { #include #endif + + namespace facebook { namespace react { class EventsNativeComponentState { - public: - - EventsNativeComponentState() = default; +public: + + EventsNativeComponentState() = default; - + #ifdef ANDROID - EventsNativeComponentState(EventsNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + EventsNativeComponentState(EventsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1313,6 +1390,8 @@ Map { #include #endif + + namespace facebook { namespace react { @@ -1343,28 +1422,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ExcludedAndroidComponentState { - public: - - ExcludedAndroidComponentState() = default; +public: + + ExcludedAndroidComponentState() = default; - + #ifdef ANDROID - ExcludedAndroidComponentState(ExcludedAndroidComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ExcludedAndroidComponentState(ExcludedAndroidComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1392,28 +1473,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ExcludedAndroidIosComponentState { - public: - - ExcludedAndroidIosComponentState() = default; +public: + + ExcludedAndroidIosComponentState() = default; - + #ifdef ANDROID - ExcludedAndroidIosComponentState(ExcludedAndroidIosComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ExcludedAndroidIosComponentState(ExcludedAndroidIosComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1441,49 +1524,51 @@ Map { #include #endif + + namespace facebook { namespace react { class ExcludedIosComponentState { - public: - - ExcludedIosComponentState() = default; +public: + + ExcludedIosComponentState() = default; - + #ifdef ANDROID - ExcludedIosComponentState(ExcludedIosComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ExcludedIosComponentState(ExcludedIosComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; class MultiFileIncludedNativeComponentState { - public: - - MultiFileIncludedNativeComponentState() = default; +public: + + MultiFileIncludedNativeComponentState() = default; - + #ifdef ANDROID - MultiFileIncludedNativeComponentState(MultiFileIncludedNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + MultiFileIncludedNativeComponentState(MultiFileIncludedNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1511,28 +1596,30 @@ Map { #include #endif + + namespace facebook { namespace react { class FloatPropNativeComponentState { - public: - - FloatPropNativeComponentState() = default; +public: + + FloatPropNativeComponentState() = default; - + #ifdef ANDROID - FloatPropNativeComponentState(FloatPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + FloatPropNativeComponentState(FloatPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1560,28 +1647,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ImagePropNativeComponentState { - public: - - ImagePropNativeComponentState() = default; +public: + + ImagePropNativeComponentState() = default; - + #ifdef ANDROID - ImagePropNativeComponentState(ImagePropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ImagePropNativeComponentState(ImagePropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1609,28 +1698,30 @@ Map { #include #endif + + namespace facebook { namespace react { class InsetsPropNativeComponentState { - public: - - InsetsPropNativeComponentState() = default; +public: + + InsetsPropNativeComponentState() = default; - + #ifdef ANDROID - InsetsPropNativeComponentState(InsetsPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + InsetsPropNativeComponentState(InsetsPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1658,28 +1749,30 @@ Map { #include #endif + + namespace facebook { namespace react { class Int32EnumPropsNativeComponentState { - public: - - Int32EnumPropsNativeComponentState() = default; +public: + + Int32EnumPropsNativeComponentState() = default; - + #ifdef ANDROID - Int32EnumPropsNativeComponentState(Int32EnumPropsNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + Int32EnumPropsNativeComponentState(Int32EnumPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1707,28 +1800,30 @@ Map { #include #endif + + namespace facebook { namespace react { class IntegerPropNativeComponentState { - public: - - IntegerPropNativeComponentState() = default; +public: + + IntegerPropNativeComponentState() = default; - + #ifdef ANDROID - IntegerPropNativeComponentState(IntegerPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + IntegerPropNativeComponentState(IntegerPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1756,6 +1851,8 @@ Map { #include #endif + + namespace facebook { namespace react { @@ -1786,28 +1883,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ImageColorPropNativeComponentState { - public: - - ImageColorPropNativeComponentState() = default; +public: + + ImageColorPropNativeComponentState() = default; - + #ifdef ANDROID - ImageColorPropNativeComponentState(ImageColorPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ImageColorPropNativeComponentState(ImageColorPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1835,28 +1934,30 @@ Map { #include #endif + + namespace facebook { namespace react { class NoPropsNoEventsComponentState { - public: - - NoPropsNoEventsComponentState() = default; +public: + + NoPropsNoEventsComponentState() = default; - + #ifdef ANDROID - NoPropsNoEventsComponentState(NoPropsNoEventsComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + NoPropsNoEventsComponentState(NoPropsNoEventsComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1884,28 +1985,30 @@ Map { #include #endif + + namespace facebook { namespace react { class ObjectPropsState { - public: - - ObjectPropsState() = default; +public: + + ObjectPropsState() = default; - + #ifdef ANDROID - ObjectPropsState(ObjectPropsState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + ObjectPropsState(ObjectPropsState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1933,28 +2036,30 @@ Map { #include #endif + + namespace facebook { namespace react { class PointPropNativeComponentState { - public: - - PointPropNativeComponentState() = default; +public: + + PointPropNativeComponentState() = default; - + #ifdef ANDROID - PointPropNativeComponentState(PointPropNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + PointPropNativeComponentState(PointPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -1982,28 +2087,30 @@ Map { #include #endif + + namespace facebook { namespace react { class StringEnumPropsNativeComponentState { - public: - - StringEnumPropsNativeComponentState() = default; +public: + + StringEnumPropsNativeComponentState() = default; - + #ifdef ANDROID - StringEnumPropsNativeComponentState(StringEnumPropsNativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + StringEnumPropsNativeComponentState(StringEnumPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -2031,28 +2138,30 @@ Map { #include #endif + + namespace facebook { namespace react { class StringPropComponentState { - public: - - StringPropComponentState() = default; +public: + + StringPropComponentState() = default; - + #ifdef ANDROID - StringPropComponentState(StringPropComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + StringPropComponentState(StringPropComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -2080,49 +2189,51 @@ Map { #include #endif + + namespace facebook { namespace react { class MultiFile1NativeComponentState { - public: - - MultiFile1NativeComponentState() = default; +public: + + MultiFile1NativeComponentState() = default; - + #ifdef ANDROID - MultiFile1NativeComponentState(MultiFile1NativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + MultiFile1NativeComponentState(MultiFile1NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; class MultiFile2NativeComponentState { - public: - - MultiFile2NativeComponentState() = default; +public: + + MultiFile2NativeComponentState() = default; - + #ifdef ANDROID - MultiFile2NativeComponentState(MultiFile2NativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + MultiFile2NativeComponentState(MultiFile2NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace react @@ -2150,49 +2261,51 @@ Map { #include #endif + + namespace facebook { namespace react { class MultiComponent1NativeComponentState { - public: - - MultiComponent1NativeComponentState() = default; +public: + + MultiComponent1NativeComponentState() = default; - + #ifdef ANDROID - MultiComponent1NativeComponentState(MultiComponent1NativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + MultiComponent1NativeComponentState(MultiComponent1NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; class MultiComponent2NativeComponentState { - public: - - MultiComponent2NativeComponentState() = default; +public: + + MultiComponent2NativeComponentState() = default; - + #ifdef ANDROID - MultiComponent2NativeComponentState(MultiComponent2NativeComponentState const &previousState, folly::dynamic data){}; - folly::dynamic getDynamic() const { - return {}; - }; - MapBuffer getMapBuffer() const { - return MapBufferBuilder::EMPTY(); - }; + MultiComponent2NativeComponentState(MultiComponent2NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; #endif - private: - +private: + }; } // namespace 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 e5b038cd646694..1c6de7812a63e1 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 @@ -740,6 +740,55 @@ TEST(SimpleComponentProps_DoesNotDie, etc) { } `; +exports[`GenerateTests can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 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(SimpleComponentProps_DoesNotDie, etc) { + auto propParser = RawPropsParser(); + propParser.prepare(); + auto const &sourceProps = SimpleComponentProps(); + auto const &rawProps = RawProps(folly::dynamic::object(\\"xx_invalid_xx\\", \\"xx_invalid_xx\\")); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser, parserContext); + SimpleComponentProps(parserContext, sourceProps, rawProps); +} + +TEST(SimpleComponentProps_imageSource, etc) { + auto propParser = RawPropsParser(); + propParser.prepare(); + auto const &sourceProps = SimpleComponentProps(); + auto const &rawProps = RawProps(folly::dynamic::object(\\"imageSource\\", folly::dynamic::object(\\"url\\", \\"testurl\\"))); + + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + rawProps.parse(propParser, parserContext); + SimpleComponentProps(parserContext, sourceProps, rawProps); +}", +} +`; + exports[`GenerateTests can generate fixture DOUBLE_PROPS 1`] = ` Map { "Tests.cpp" => "/** 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 d6ac27d7b877b2..902b991cc046d4 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 @@ -66,6 +66,7 @@ Class SimpleComponentCls(void) __attribute__((used)); Class SimpleComponentCls(void) __attribute__((used)); // COMPONENT_WITH_ARRAY_OF_OBJECTS_STATE Class SimpleComponentCls(void) __attribute__((used)); // COMPONENT_WITH_STRING_ENUM_STATE_PROPS Class SimpleComponentCls(void) __attribute__((used)); // COMPONENT_WITH_INT_ENUM_STATE +Class SimpleComponentCls(void) __attribute__((used)); // COMPONENTS_WITH_IMAGES_IN_STATE #ifdef __cplusplus } 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 f140a9cb238384..06af76d00eb588 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 @@ -104,6 +104,8 @@ Class RCTThirdPartyFabricComponentsProvider(const char {\\"SimpleComponent\\", SimpleComponentCls}, // COMPONENT_WITH_STRING_ENUM_STATE_PROPS {\\"SimpleComponent\\", SimpleComponentCls}, // COMPONENT_WITH_INT_ENUM_STATE + + {\\"SimpleComponent\\", SimpleComponentCls}, // COMPONENTS_WITH_IMAGES_IN_STATE }; auto p = sFabricComponentsClassMap.find(name); 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 0b209211cb47d4..cef9e05a8d3082 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 @@ -673,6 +673,42 @@ export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL } `; +exports[`GenerateViewConfigJs can generate fixture COMPONENTS_WITH_IMAGES_IN_STATE 1`] = ` +Map { + "COMPONENTS_WITH_IMAGES_IN_STATENativeViewConfig.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 = 'SimpleComponent'; + + +export const __INTERNAL_VIEW_CONFIG = { + uiViewClassName: 'SimpleComponent', + + validAttributes: { + imageSource: { + process: require('react-native/Libraries/Image/resolveAssetSource'), + }, + }, +}; + +export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG); +", +} +`; + exports[`GenerateViewConfigJs can generate fixture DOUBLE_PROPS 1`] = ` Map { "DOUBLE_PROPSNativeViewConfig.js" => " diff --git a/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js index 9517a4c96bdeb5..548399cd1cfb2b 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js @@ -1421,6 +1421,37 @@ export default (codegenNativeComponent( ): HostComponent); `; +const STATE_WITH_IMAGES = ` +/** + * 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. + * + * @format + * @flow strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); +import type {ImageSource} from 'ImageSource'; + +type ModuleProps = $ReadOnly<{| + ...ViewProps, + imageSource: ImageSource, +|}>; + +type ModuleNativeState = $ReadOnly<{| + imageSource: ImageSource, + imageRequest: ImageRequest, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + //TODO: fix this. The code is the same as per the props, but it fails with the State. // const STATE_ALIASED_LOCALLY = ` // /** @@ -1488,5 +1519,6 @@ module.exports = { ARRAY_STATE_TYPES, OBJECT_STATE_TYPES, STATE_NEGATIVE_DEFAULTS, + STATE_WITH_IMAGES, // STATE_ALIASED_LOCALLY, }; diff --git a/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap b/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap index 2d3b92f835c4a7..0df5be6f35b5cd 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap +++ b/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap @@ -11422,3 +11422,53 @@ exports[`RN Codegen Flow Parser can generate fixture STATE_NEGATIVE_DEFAULTS 1`] } }" `; + +exports[`RN Codegen Flow Parser can generate fixture STATE_WITH_IMAGES 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [], + 'props': [ + { + 'name': 'imageSource', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + ], + 'commands': [], + 'state': [ + { + 'name': 'imageSource', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + }, + { + 'name': 'imageRequest', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageRequestPrimitive' + } + } + ] + } + } + } + } +}" +`; diff --git a/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js b/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js index 4bfd1097ad37d7..49de49da57ff7c 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js +++ b/packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js @@ -102,6 +102,11 @@ function getTypeAnnotationForArray<+T>( type: 'ReservedPropTypeAnnotation', name: 'ImageSourcePrimitive', }; + case 'ImageRequest': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ImageRequestPrimitive', + }; case 'ColorValue': case 'ProcessedColorValue': return { @@ -269,6 +274,11 @@ function getTypeAnnotation<+T>( type: 'ReservedPropTypeAnnotation', name: 'ImageSourcePrimitive', }; + case 'ImageRequest': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ImageRequestPrimitive', + }; case 'ColorValue': case 'ProcessedColorValue': return { diff --git a/packages/react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js index 728afa8ec6b310..05770b047cf3cb 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/__test_fixtures__/fixtures.js @@ -1701,6 +1701,36 @@ export default codegenNativeComponent( ) as HostComponent; `; +const STATE_WITH_IMAGES = ` +/** + * 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. + * + * @format + * @flow strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); +import type {ImageSource} from 'ImageSource'; + +export interface ModuleProps extends ViewProps { + imageSource: ImageSource; +} + +interface ModuleNativeState { + imageSource: ImageSource, + imageRequest: ImageRequest, +} + +export default codegenNativeComponent( + 'Module', +) as HostComponent; +`; + module.exports = { ALL_PROP_TYPES_NO_EVENTS, ARRAY_PROP_TYPES_NO_EVENTS, @@ -1723,4 +1753,5 @@ module.exports = { ARRAY2_STATE_TYPES, OBJECT_STATE_TYPES, STATE_NEGATIVE_DEFAULTS, + STATE_WITH_IMAGES, }; diff --git a/packages/react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap b/packages/react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap index 09ecbc5643aab8..9ae3ac9a7d561e 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap +++ b/packages/react-native-codegen/src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap @@ -13052,3 +13052,53 @@ exports[`RN Codegen TypeScript Parser can generate fixture STATE_NEGATIVE_DEFAUL } }" `; + +exports[`RN Codegen TypeScript Parser can generate fixture STATE_WITH_IMAGES 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [], + 'props': [ + { + 'name': 'imageSource', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + ], + 'commands': [], + 'state': [ + { + 'name': 'imageSource', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + }, + { + 'name': 'imageRequest', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageRequestPrimitive' + } + } + ] + } + } + } + } +}" +`; diff --git a/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js b/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js index d608a491eeca06..a0b21bd8186a20 100644 --- a/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js +++ b/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js @@ -233,6 +233,11 @@ function getTypeAnnotationForArray( type: 'ReservedPropTypeAnnotation', name: 'ImageSourcePrimitive', }; + case 'ImageRequest': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ImageRequestPrimitive', + }; case 'ColorValue': case 'ProcessedColorValue': return { @@ -336,6 +341,11 @@ function getTypeAnnotation( type: 'ReservedPropTypeAnnotation', name: 'ImageSourcePrimitive', }; + case 'ImageRequest': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ImageRequestPrimitive', + }; case 'ColorValue': case 'ProcessedColorValue': return {