diff --git a/packages/react-native-codegen/BUCK b/packages/react-native-codegen/BUCK index 857750a4926..f305b43e744 100644 --- a/packages/react-native-codegen/BUCK +++ b/packages/react-native-codegen/BUCK @@ -71,6 +71,10 @@ rn_codegen_test( fixture_name = "IMAGE_PROP", ) +rn_codegen_test( + fixture_name = "POINT_PROP", +) + rn_codegen_test( fixture_name = "ARRAY_PROPS", ) @@ -126,6 +130,7 @@ fb_xplat_cxx_binary( ":generated_components-INTEGER_PROPS", ":generated_components-INTERFACE_ONLY", ":generated_components-MULTI_NATIVE_PROP", + ":generated_components-POINT_PROP", ":generated_components-STRING_PROP", ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", ":generated_components-TWO_COMPONENTS_SAME_FILE", @@ -162,6 +167,7 @@ rn_xplat_cxx_library( ":generated_components-INTEGER_PROPS", ":generated_components-INTERFACE_ONLY", ":generated_components-MULTI_NATIVE_PROP", + ":generated_components-POINT_PROP", ":generated_components-STRING_PROP", ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", ":generated_components-TWO_COMPONENTS_SAME_FILE", diff --git a/packages/react-native-codegen/buck_tests/emptyFile.cpp b/packages/react-native-codegen/buck_tests/emptyFile.cpp index 527f9d6910d..89c5b84d274 100644 --- a/packages/react-native-codegen/buck_tests/emptyFile.cpp +++ b/packages/react-native-codegen/buck_tests/emptyFile.cpp @@ -6,6 +6,7 @@ #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 d1b2b685b73..dff76dae367 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' | 'ImageSourcePrimitive', + name: 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive', |}> | $ReadOnly<{| type: 'ArrayTypeAnnotation', diff --git a/packages/react-native-codegen/src/generators/GeneratePropsCpp.js b/packages/react-native-codegen/src/generators/GeneratePropsCpp.js index b9ead297148..9f25a41a273 100644 --- a/packages/react-native-codegen/src/generators/GeneratePropsCpp.js +++ b/packages/react-native-codegen/src/generators/GeneratePropsCpp.js @@ -86,6 +86,8 @@ function getImports(component): Set { switch (name) { case 'ColorPrimitive': return; + case 'PointPrimitive': + return; case 'ImageSourcePrimitive': imports.add('#include '); return; diff --git a/packages/react-native-codegen/src/generators/GeneratePropsH.js b/packages/react-native-codegen/src/generators/GeneratePropsH.js index bd47d4acf1e..c4f1d98084f 100644 --- a/packages/react-native-codegen/src/generators/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/GeneratePropsH.js @@ -109,6 +109,8 @@ function getNativeTypeFromAnnotation(componentName: string, prop): string { return 'SharedColor'; case 'ImageSourcePrimitive': return 'ImageSource'; + case 'PointPrimitive': + return 'Point'; default: (typeAnnotation.name: empty); throw new Error('Receieved unknown NativePrimitiveTypeAnnotation'); @@ -153,6 +155,8 @@ function convertDefaultTypeToString(componentName: string, prop): string { return ''; case 'ImageSourcePrimitive': return ''; + case 'PointPrimitive': + return ''; default: (typeAnnotation.name: empty); throw new Error('Receieved unknown NativePrimitiveTypeAnnotation'); @@ -259,6 +263,9 @@ function getImports(component): Set { case 'ImageSourcePrimitive': imports.add('#include '); return; + case 'PointPrimitive': + imports.add('#include '); + return; default: (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 f0d562e5098..071c21cee47 100644 --- a/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js @@ -55,6 +55,8 @@ function getReactDiffProcessValue(prop) { case 'ImageSourcePrimitive': return j.template .expression`${nativeTypesString}.ImageSourcePrimitive`; + case 'PointPrimitive': + return j.template.expression`${nativeTypesString}.PointPrimitive`; 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 2099bcc3dfe..b9fa3f01238 100644 --- a/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js @@ -284,6 +284,34 @@ const IMAGE_PROP: SchemaType = { }, }; +const POINT_PROP: SchemaType = { + modules: { + Switch: { + components: { + PointPropNativeComponent: { + extendsProps: [ + { + type: 'ReactNativeBuiltInType', + knownTypeName: 'ReactNativeCoreViewProps', + }, + ], + events: [], + props: [ + { + name: 'startPoint', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'PointPrimitive', + }, + }, + ], + }, + }, + }, + }, +}; + const ARRAY_PROPS: SchemaType = { modules: { Slider: { @@ -359,6 +387,17 @@ const ARRAY_PROPS: SchemaType = { }, }, }, + { + name: 'points', + optional: true, + typeAnnotation: { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'NativePrimitiveTypeAnnotation', + name: 'PointPrimitive', + }, + }, + }, ], }, }, @@ -403,6 +442,14 @@ const MULTI_NATIVE_PROP: SchemaType = { name: 'ColorPrimitive', }, }, + { + name: 'point', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'PointPrimitive', + }, + }, ], }, }, @@ -490,23 +537,6 @@ const EVENT_PROPS: SchemaType = { name: 'scale', optional: true, }, - // { - // type: 'ObjectTypeAnnotation', - // name: 'location', - // optional: false, - // properties: [ - // { - // type: 'IntegerTypeAnnotation', - // name: 'x', - // optional: false, - // }, - // { - // type: 'IntegerTypeAnnotation', - // name: 'y', - // optional: false, - // }, - // ], - // }, ], }, }, @@ -725,6 +755,7 @@ module.exports = { FLOAT_PROPS, COLOR_PROP, IMAGE_PROP, + POINT_PROP, ARRAY_PROPS, MULTI_NATIVE_PROP, ENUM_PROP, 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 780250782f5..64b911abf1f 100644 --- a/packages/react-native-codegen/src/generators/__tests__/GenerateComponentDescriptorH-test.js +++ b/packages/react-native-codegen/src/generators/__tests__/GenerateComponentDescriptorH-test.js @@ -21,6 +21,7 @@ const { FLOAT_PROPS, COLOR_PROP, IMAGE_PROP, + POINT_PROP, MULTI_NATIVE_PROP, ENUM_PROP, EVENT_PROPS, @@ -59,6 +60,10 @@ describe('GenerateComponentDescriptorH', () => { expect(generator.generate('IMAGE_PROP', IMAGE_PROP)).toMatchSnapshot(); }); + it('can generate a native primitive point prop', () => { + expect(generator.generate('IMAGE_PROP', POINT_PROP)).toMatchSnapshot(); + }); + it('can generate multiple native props', () => { expect( generator.generate('MULTI_NATIVE_PROP', MULTI_NATIVE_PROP), 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 9a2e4a1bdde..6a46dea5fb2 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 @@ -52,6 +52,32 @@ using ImagePropNativeComponentComponentDescriptor = ConcreteComponentDescriptor< } `; +exports[`GenerateComponentDescriptorH can generate a native primitive point 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 PointPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook +", +} +`; + exports[`GenerateComponentDescriptorH can generate a single boolean prop 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 79bfc6fd052..41ed47758c4 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 @@ -287,6 +287,29 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterCpp can generate fixture POINT_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 99a6e0efca2..f7d7ca0508c 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 @@ -304,6 +304,30 @@ namespace react { +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateEventEmitterH can generate fixture POINT_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 88433dd182b..c02ab463d37 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 @@ -26,7 +26,8 @@ disableds(convertRawProp(rawProps, \\"disableds\\", sourceProps.disableds, disab progress(convertRawProp(rawProps, \\"progress\\", sourceProps.progress, progress)), radii(convertRawProp(rawProps, \\"radii\\", sourceProps.radii, radii)), colors(convertRawProp(rawProps, \\"colors\\", sourceProps.colors, colors)), -srcs(convertRawProp(rawProps, \\"srcs\\", sourceProps.srcs, srcs)) +srcs(convertRawProp(rawProps, \\"srcs\\", sourceProps.srcs, srcs)), +points(convertRawProp(rawProps, \\"points\\", sourceProps.points, points)) {} } // namespace react @@ -327,7 +328,37 @@ ImageColorPropNativeComponentProps::ImageColorPropNativeComponentProps( thumbImage(convertRawProp(rawProps, \\"thumbImage\\", sourceProps.thumbImage, thumbImage)), color(convertRawProp(rawProps, \\"color\\", sourceProps.color, color)), -thumbTintColor(convertRawProp(rawProps, \\"thumbTintColor\\", sourceProps.thumbTintColor, thumbTintColor)) +thumbTintColor(convertRawProp(rawProps, \\"thumbTintColor\\", sourceProps.thumbTintColor, thumbTintColor)), +point(convertRawProp(rawProps, \\"point\\", sourceProps.point, point)) + {} + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GeneratePropsCpp can generate fixture POINT_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 + +namespace facebook { +namespace react { + +PointPropNativeComponentProps::PointPropNativeComponentProps( + const PointPropNativeComponentProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + startPoint(convertRawProp(rawProps, \\"startPoint\\", sourceProps.startPoint, startPoint)) {} } // namespace react 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 46fb666b8a4..798e5c647ce 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 @@ -13,6 +13,7 @@ Map { #include #include +#include #include #include @@ -32,6 +33,7 @@ const std::vector progress{}; const std::vector radii{}; const std::vector colors{}; const std::vector srcs{}; +const std::vector points{}; }; } // namespace react @@ -368,6 +370,7 @@ Map { #include #include +#include #include namespace facebook { @@ -383,6 +386,40 @@ class ImageColorPropNativeComponentProps final : public ViewProps { const ImageSource thumbImage{}; const SharedColor color{}; const SharedColor thumbTintColor{}; +const Point point{}; +}; + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GeneratePropsH can generate fixture POINT_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. + */ +#pragma once + +#include +#include + +namespace facebook { +namespace react { + +class PointPropNativeComponentProps final : public ViewProps { + public: + PointPropNativeComponentProps() = default; + PointPropNativeComponentProps(const PointPropNativeComponentProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + const Point startPoint{}; }; } // namespace react 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 59f830b15b5..da5ea73e124 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 @@ -253,6 +253,29 @@ extern const char ImageColorPropNativeComponentComponentName[] = \\"ImageColorPr } `; +exports[`GenerateShadowNodeCpp can generate fixture POINT_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 PointPropNativeComponentComponentName[] = \\"PointPropNativeComponent\\"; + +} // 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 364c007a330..d9f2428280f 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 @@ -360,6 +360,39 @@ using ImageColorPropNativeComponentShadowNode = ConcreteViewShadowNode< } `; +exports[`GenerateShadowNodeH can generate fixture POINT_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 PointPropNativeComponentComponentName[]; + +/* + * \`ShadowNode\` for component. + */ +using PointPropNativeComponentShadowNode = ConcreteViewShadowNode< + PointPropNativeComponentComponentName, + PointPropNativeComponentProps>; + +} // 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 6775c1bc7ba..da4bebc2e70 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 @@ -28,6 +28,7 @@ const ArrayPropsNativeComponentViewConfig = { radii: true, colors: true, srcs: true, + points: true, style: ReactNativeStyleAttributes } }; @@ -420,6 +421,7 @@ const ImageColorPropNativeComponentViewConfig = { 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, + point: require('react-native').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativePrimitives.PointPrimitive, style: ReactNativeStyleAttributes } }; @@ -432,6 +434,41 @@ ReactNativeViewConfigRegistry.register( } `; +exports[`GenerateViewConfigJs can generate fixture POINT_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 PointPropNativeComponentViewConfig = { + uiViewClassName: 'PointPropNativeComponent', + + validAttributes: { + startPoint: require('react-native').__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativePrimitives.PointPrimitive, + style: ReactNativeStyleAttributes + } +}; + +ReactNativeViewConfigRegistry.register( + 'PointPropNativeComponent', + () => PointPropNativeComponentViewConfig, +); +", +} +`; + exports[`GenerateViewConfigJs can generate fixture STRING_PROP 1`] = ` Map { "ViewConfigs.js" => "