diff --git a/packages/react-native-codegen/BUCK b/packages/react-native-codegen/BUCK index fedeaefe13..a1d97d26b0 100644 --- a/packages/react-native-codegen/BUCK +++ b/packages/react-native-codegen/BUCK @@ -63,6 +63,14 @@ rn_codegen_test( fixture_name = "COLOR_PROP", ) +rn_codegen_test( + fixture_name = "IMAGE_PROP", +) + +rn_codegen_test( + fixture_name = "MULTI_NATIVE_PROP", +) + rn_codegen_test( fixture_name = "ENUM_PROP", ) @@ -105,7 +113,9 @@ fb_xplat_cxx_binary( ":generated_components-EVENT_NESTED_OBJECT_PROPS", ":generated_components-EVENT_PROPS", ":generated_components-FLOAT_PROPS", + ":generated_components-IMAGE_PROP", ":generated_components-INTEGER_PROPS", + ":generated_components-MULTI_NATIVE_PROP", ":generated_components-STRING_PROP", ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", ":generated_components-TWO_COMPONENTS_SAME_FILE", @@ -137,7 +147,9 @@ rn_xplat_cxx_library( ":generated_components-EVENT_NESTED_OBJECT_PROPS", ":generated_components-EVENT_PROPS", ":generated_components-FLOAT_PROPS", + ":generated_components-IMAGE_PROP", ":generated_components-INTEGER_PROPS", + ":generated_components-MULTI_NATIVE_PROP", ":generated_components-STRING_PROP", ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", ":generated_components-TWO_COMPONENTS_SAME_FILE", diff --git a/packages/react-native-codegen/DEFS.bzl b/packages/react-native-codegen/DEFS.bzl index aa9a6af9bd..8f3ad2e347 100644 --- a/packages/react-native-codegen/DEFS.bzl +++ b/packages/react-native-codegen/DEFS.bzl @@ -129,6 +129,8 @@ def rn_codegen( react_native_xplat_target("fabric/debug:debug"), react_native_xplat_target("fabric/core:core"), react_native_xplat_target("fabric/graphics:graphics"), + react_native_xplat_target("fabric/components/image:image"), + react_native_xplat_target("fabric/imagemanager:imagemanager"), react_native_xplat_target("fabric/components/view:view"), ], ) diff --git a/packages/react-native-codegen/buck_tests/emptyFile.cpp b/packages/react-native-codegen/buck_tests/emptyFile.cpp index 23afb4a431..bf041a6b52 100644 --- a/packages/react-native-codegen/buck_tests/emptyFile.cpp +++ b/packages/react-native-codegen/buck_tests/emptyFile.cpp @@ -3,6 +3,8 @@ #import #import #import +#import +#import #import #import #import diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 0d4c6a014a..4af0aca60b 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -64,7 +64,7 @@ type PropTypeTypeAnnotation = |}> | $ReadOnly<{| type: 'NativePrimitiveTypeAnnotation', - name: 'ColorPrimitive', + name: 'ColorPrimitive' | 'ImageSourcePrimitive', |}>; export type PropTypeShape = $ReadOnly<{| diff --git a/packages/react-native-codegen/src/generators/GeneratePropsCpp.js b/packages/react-native-codegen/src/generators/GeneratePropsCpp.js index 162e9820c5..3a17aa0477 100644 --- a/packages/react-native-codegen/src/generators/GeneratePropsCpp.js +++ b/packages/react-native-codegen/src/generators/GeneratePropsCpp.js @@ -24,7 +24,7 @@ const template = ` */ #include -#include +::_IMPORTS_:: namespace facebook { namespace react { @@ -79,9 +79,36 @@ function getClassExtendString(component): string { return extendString; } +function getImports(component): Set { + const imports: Set = new Set(); + component.props.forEach(prop => { + const typeAnnotation = prop.typeAnnotation; + + if (typeAnnotation.type === 'NativePrimitiveTypeAnnotation') { + switch (typeAnnotation.name) { + case 'ColorPrimitive': + return; + case 'ImageSourcePrimitive': + imports.add('#include '); + return; + default: + (typeAnnotation.name: empty); + throw new Error( + `Invalid NativePrimitiveTypeAnnotation name, got ${prop.name}`, + ); + } + } + }); + + return imports; +} + module.exports = { generate(libraryName: string, schema: SchemaType): FilesOutput { const fileName = 'Props.cpp'; + const allImports: Set = new Set([ + '#include ', + ]); const componentProps = Object.keys(schema.modules) .map(moduleName => { @@ -99,6 +126,9 @@ module.exports = { const propsString = generatePropsString(component); const extendString = getClassExtendString(component); + const imports = getImports(component); + imports.forEach(allImports.add, allImports); + const replacedTemplate = componentTemplate .replace(/::_CLASSNAME_::/g, newName) .replace('::_EXTEND_CLASSES_::', extendString) @@ -113,7 +143,15 @@ module.exports = { const replacedTemplate = template .replace(/::_COMPONENT_CLASSES_::/g, componentProps) - .replace('::_LIBRARY_::', libraryName); + .replace('::_LIBRARY_::', libraryName) + .replace( + '::_IMPORTS_::', + + Array.from(allImports) + .sort() + .join('\n') + .trim(), + ); return new Map([[fileName, replacedTemplate]]); }, diff --git a/packages/react-native-codegen/src/generators/GeneratePropsH.js b/packages/react-native-codegen/src/generators/GeneratePropsH.js index 71aa2fc8c9..49ee11a4c8 100644 --- a/packages/react-native-codegen/src/generators/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/GeneratePropsH.js @@ -106,6 +106,8 @@ function getNativeTypeFromAnnotation(componentName: string, prop): string { switch (typeAnnotation.name) { case 'ColorPrimitive': return 'SharedColor'; + case 'ImageSourcePrimitive': + return 'ImageSource'; default: (typeAnnotation.name: empty); throw new Error('Receieved unknown NativePrimitiveTypeAnnotation'); @@ -136,6 +138,8 @@ function convertDefaultTypeToString(componentName: string, prop): string { switch (typeAnnotation.name) { case 'ColorPrimitive': return ''; + case 'ImageSourcePrimitive': + return ''; default: (typeAnnotation.name: empty); throw new Error('Receieved unknown NativePrimitiveTypeAnnotation'); @@ -239,6 +243,9 @@ function getImports(component): Set { case 'ColorPrimitive': imports.add('#include '); return; + case 'ImageSourcePrimitive': + imports.add('#include '); + return; default: (typeAnnotation.name: empty); throw new Error( diff --git a/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js index 6e111765a9..f19f54c18a 100644 --- a/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js @@ -51,6 +51,9 @@ function getReactDiffProcessValue(prop) { switch (typeAnnotation.name) { case 'ColorPrimitive': return j.template.expression`${nativeTypesString}.ColorPrimitive`; + case 'ImageSourcePrimitive': + return j.template + .expression`${nativeTypesString}.ImageSourcePrimitive`; default: (typeAnnotation.name: empty); throw new Error('Receieved unknown NativePrimitiveTypeAnnotation'); diff --git a/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js index e70995c34e..582eb2be3b 100644 --- a/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js @@ -200,6 +200,78 @@ const COLOR_PROP: SchemaType = { }, }; +const IMAGE_PROP: SchemaType = { + modules: { + Slider: { + components: { + ImagePropNativeComponent: { + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'thumbImage', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + ], + }, + }, + }, + }, +}; + +const MULTI_NATIVE_PROP: SchemaType = { + modules: { + Slider: { + components: { + ImageColorPropNativeComponent: { + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'thumbImage', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ImageSourcePrimitive', + }, + }, + { + name: 'color', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + { + name: 'thumbTintColor', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + ], + }, + }, + }, + }, +}; + const ENUM_PROP: SchemaType = { modules: { Switch: { @@ -513,6 +585,8 @@ module.exports = { INTEGER_PROPS, FLOAT_PROPS, COLOR_PROP, + IMAGE_PROP, + MULTI_NATIVE_PROP, ENUM_PROP, EVENT_PROPS, EVENT_NESTED_OBJECT_PROPS, diff --git a/packages/react-native-codegen/src/generators/__tests__/GenerateComponentDescriptorH-test.js b/packages/react-native-codegen/src/generators/__tests__/GenerateComponentDescriptorH-test.js index 454b6f202e..f9c1d1d264 100644 --- a/packages/react-native-codegen/src/generators/__tests__/GenerateComponentDescriptorH-test.js +++ b/packages/react-native-codegen/src/generators/__tests__/GenerateComponentDescriptorH-test.js @@ -19,6 +19,8 @@ const { INTEGER_PROPS, FLOAT_PROPS, COLOR_PROP, + IMAGE_PROP, + MULTI_NATIVE_PROP, ENUM_PROP, EVENT_PROPS, TWO_COMPONENTS_SAME_FILE, @@ -48,6 +50,16 @@ describe('GenerateComponentDescriptorH', () => { expect(generator.generate('COLOR_PROP', COLOR_PROP)).toMatchSnapshot(); }); + it('can generate a native primitive image prop', () => { + expect(generator.generate('IMAGE_PROP', IMAGE_PROP)).toMatchSnapshot(); + }); + + it('can generate multiple native props', () => { + expect( + generator.generate('MULTI_NATIVE_PROP', MULTI_NATIVE_PROP), + ).toMatchSnapshot(); + }); + it('can generate enum props', () => { expect(generator.generate('ENUM_PROP', ENUM_PROP)).toMatchSnapshot(); }); diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap index c397293a08..75dd517cf1 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateComponentDescriptorH-test.js.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`GenerateComponentDescriptorH can generate a native primitive image prop 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using ImagePropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateComponentDescriptorH can generate a single boolean prop 1`] = ` Map { "ComponentDescriptors.h" => " @@ -182,6 +208,32 @@ using IntegerPropNativeComponentComponentDescriptor = ConcreteComponentDescripto } `; +exports[`GenerateComponentDescriptorH can generate multiple native props 1`] = ` +Map { + "ComponentDescriptors.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +using ImageColorPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateComponentDescriptorH supports two components from different modules 1`] = ` Map { "ComponentDescriptors.h" => " diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap index 7f9d8cc758..bb68b3796d 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterCpp-test.js.snap @@ -166,6 +166,29 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture IMAGE_PROP 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +namespace facebook { +namespace react { + + + } // namespace react } // namespace facebook ", @@ -189,6 +212,29 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "EventEmitters.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +namespace facebook { +namespace react { + + + } // namespace react } // namespace facebook ", diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap index 506d6e8384..f6634f3586 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -175,6 +175,30 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture IMAGE_PROP 1`] = ` +Map { + "EventEmitters.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once + +#include + +namespace facebook { +namespace react { + + + } // namespace react } // namespace facebook ", @@ -199,6 +223,30 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "EventEmitters.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +#pragma once + +#include + +namespace facebook { +namespace react { + + + } // namespace react } // namespace facebook ", diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap index 36346e22ee..69ea1adbeb 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap @@ -178,6 +178,36 @@ blurRadius5(convertRawProp(rawProps, \\"blurRadius5\\", sourceProps.blurRadius5, } `; +exports[`GeneratePropsCpp can generate fixture IMAGE_PROP 1`] = ` +Map { + "Props.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include + +namespace facebook { +namespace react { + +ImagePropNativeComponentProps::ImagePropNativeComponentProps( + const ImagePropNativeComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + thumbImage(convertRawProp(rawProps, \\"thumbImage\\", sourceProps.thumbImage, thumbImage)) + {} + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsCpp can generate fixture INTEGER_PROPS 1`] = ` Map { "Props.cpp" => " @@ -209,6 +239,38 @@ progress3(convertRawProp(rawProps, \\"progress3\\", sourceProps.progress3, progr } `; +exports[`GeneratePropsCpp can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "Props.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include + +namespace facebook { +namespace react { + +ImageColorPropNativeComponentProps::ImageColorPropNativeComponentProps( + const ImageColorPropNativeComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + thumbImage(convertRawProp(rawProps, \\"thumbImage\\", sourceProps.thumbImage, thumbImage)), +color(convertRawProp(rawProps, \\"color\\", sourceProps.color, color)), +thumbTintColor(convertRawProp(rawProps, \\"thumbTintColor\\", sourceProps.thumbTintColor, thumbTintColor)) + {} + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsCpp can generate fixture STRING_PROP 1`] = ` Map { "Props.cpp" => " diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsH-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsH-test.js.snap index 9f08b3b869..d155bcabb5 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsH-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GeneratePropsH-test.js.snap @@ -209,6 +209,38 @@ const Float blurRadius5{1.0}; } `; +exports[`GeneratePropsH can generate fixture IMAGE_PROP 1`] = ` +Map { + "Props.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include + +namespace facebook { +namespace react { + +class ImagePropNativeComponentProps final : public ViewProps { + public: + ImagePropNativeComponentProps() = default; + ImagePropNativeComponentProps(const ImagePropNativeComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + const ImageSource thumbImage{}; +}; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsH can generate fixture INTEGER_PROPS 1`] = ` Map { "Props.h" => " @@ -242,6 +274,41 @@ const int progress3{10}; } `; +exports[`GeneratePropsH can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "Props.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include + +namespace facebook { +namespace react { + +class ImageColorPropNativeComponentProps final : public ViewProps { + public: + ImageColorPropNativeComponentProps() = default; + ImageColorPropNativeComponentProps(const ImageColorPropNativeComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + const ImageSource thumbImage{}; +const SharedColor color{}; +const SharedColor thumbTintColor{}; +}; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GeneratePropsH can generate fixture STRING_PROP 1`] = ` Map { "Props.h" => " diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap index 9b085965b3..6cd3422d2f 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeCpp-test.js.snap @@ -138,6 +138,29 @@ extern const char FloatPropNativeComponentComponentName[] = \\"FloatPropNativeCo } `; +exports[`GenerateShadowNodeCpp can generate fixture IMAGE_PROP 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +namespace facebook { +namespace react { + +extern const char ImagePropNativeComponentComponentName[] = \\"ImagePropNativeComponent\\"; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeCpp can generate fixture INTEGER_PROPS 1`] = ` Map { "ShadowNodes.cpp" => " @@ -161,6 +184,29 @@ extern const char IntegerPropNativeComponentComponentName[] = \\"IntegerPropNati } `; +exports[`GenerateShadowNodeCpp can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "ShadowNodes.cpp" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +namespace facebook { +namespace react { + +extern const char ImageColorPropNativeComponentComponentName[] = \\"ImageColorPropNativeComponent\\"; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeCpp can generate fixture STRING_PROP 1`] = ` Map { "ShadowNodes.cpp" => " diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap index 93561aa130..0fc22b2fe5 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -202,6 +202,39 @@ using FloatPropNativeComponentShadowNode = ConcreteViewShadowNode< } `; +exports[`GenerateShadowNodeH can generate fixture IMAGE_PROP 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +extern const char ImagePropNativeComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using ImagePropNativeComponentShadowNode = ConcreteViewShadowNode< + ImagePropNativeComponentComponentName, + ImagePropNativeComponentProps>; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeH can generate fixture INTEGER_PROPS 1`] = ` Map { "ShadowNodes.h" => " @@ -235,6 +268,39 @@ using IntegerPropNativeComponentShadowNode = ConcreteViewShadowNode< } `; +exports[`GenerateShadowNodeH can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "ShadowNodes.h" => " +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +extern const char ImageColorPropNativeComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using ImageColorPropNativeComponentShadowNode = ConcreteViewShadowNode< + ImageColorPropNativeComponentComponentName, + ImageColorPropNativeComponentProps>; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateShadowNodeH can generate fixture STRING_PROP 1`] = ` Map { "ShadowNodes.h" => " diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap index 28388e124f..e5effa2ce2 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -238,6 +238,41 @@ ReactNativeViewConfigRegistry.register( } `; +exports[`GenerateViewConfigJs can generate fixture IMAGE_PROP 1`] = ` +Map { + "ViewConfigs.js" => " +/** + * Copyright (c) Facebook, Inc. and its 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 + */ + +'use strict'; + +const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes'); +const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry'); + +const ImagePropNativeComponentViewConfig = { + uiViewClassName: 'ImagePropNativeComponent', + + validAttributes: { + thumbImage: require('react-native').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativePrimitives.ImageSourcePrimitive, + style: ReactNativeStyleAttributes + } +}; + +ReactNativeViewConfigRegistry.register( + 'ImagePropNativeComponent', + () => ImagePropNativeComponentViewConfig, +); +", +} +`; + exports[`GenerateViewConfigJs can generate fixture INTEGER_PROPS 1`] = ` Map { "ViewConfigs.js" => " @@ -275,6 +310,43 @@ ReactNativeViewConfigRegistry.register( } `; +exports[`GenerateViewConfigJs can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "ViewConfigs.js" => " +/** + * Copyright (c) Facebook, Inc. and its 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 + */ + +'use strict'; + +const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes'); +const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry'); + +const ImageColorPropNativeComponentViewConfig = { + uiViewClassName: 'ImageColorPropNativeComponent', + + validAttributes: { + thumbImage: require('react-native').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativePrimitives.ImageSourcePrimitive, + color: require('react-native').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativePrimitives.ColorPrimitive, + thumbTintColor: require('react-native').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativePrimitives.ColorPrimitive, + style: ReactNativeStyleAttributes + } +}; + +ReactNativeViewConfigRegistry.register( + 'ImageColorPropNativeComponent', + () => ImageColorPropNativeComponentViewConfig, +); +", +} +`; + exports[`GenerateViewConfigJs can generate fixture STRING_PROP 1`] = ` Map { "ViewConfigs.js" => "