Add PointPrimitive

Summary: Adds support for the native type Point to the rn codegen

Reviewed By: TheSavior

Differential Revision: D14462164

fbshipit-source-id: 942b5697d616c6aa6289d01bb56382fd7adac203
This commit is contained in:
Rick Hanlon
2019-03-19 06:25:06 -07:00
committed by Facebook Github Bot
parent 7723c31329
commit 0827184c60
16 changed files with 308 additions and 20 deletions

View File

@@ -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",

View File

@@ -6,6 +6,7 @@
#import <react/components/FLOAT_PROPS/ComponentDescriptors.h>
#import <react/components/COLOR_PROP/ComponentDescriptors.h>
#import <react/components/IMAGE_PROP/ComponentDescriptors.h>
#import <react/components/POINT_PROP/ComponentDescriptors.h>
#import <react/components/MULTI_NATIVE_PROP/ComponentDescriptors.h>
#import <react/components/ENUM_PROP/ComponentDescriptors.h>
#import <react/components/EVENT_NESTED_OBJECT_PROPS/ComponentDescriptors.h>

View File

@@ -64,7 +64,7 @@ type PropTypeTypeAnnotation =
|}>
| $ReadOnly<{|
type: 'NativePrimitiveTypeAnnotation',
name: 'ColorPrimitive' | 'ImageSourcePrimitive',
name: 'ColorPrimitive' | 'ImageSourcePrimitive' | 'PointPrimitive',
|}>
| $ReadOnly<{|
type: 'ArrayTypeAnnotation',

View File

@@ -86,6 +86,8 @@ function getImports(component): Set<string> {
switch (name) {
case 'ColorPrimitive':
return;
case 'PointPrimitive':
return;
case 'ImageSourcePrimitive':
imports.add('#include <react/components/image/conversions.h>');
return;

View File

@@ -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<string> {
case 'ImageSourcePrimitive':
imports.add('#include <react/imagemanager/primitives.h>');
return;
case 'PointPrimitive':
imports.add('#include <react/graphics/Geometry.h>');
return;
default:
(name: empty);
throw new Error(

View File

@@ -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');

View File

@@ -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,

View File

@@ -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),

View File

@@ -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 <react/components/IMAGE_PROP/ShadowNodes.h>
#include <react/core/ConcreteComponentDescriptor.h>
namespace facebook {
namespace react {
using PointPropNativeComponentComponentDescriptor = ConcreteComponentDescriptor<PointPropNativeComponentShadowNode>;
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateComponentDescriptorH can generate a single boolean prop 1`] = `
Map {
"ComponentDescriptors.h" => "

View File

@@ -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 <react/components/POINT_PROP/EventEmitters.h>
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",

View File

@@ -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 <react/components/view/ViewEventEmitter.h>
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",

View File

@@ -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 <react/components/POINT_PROP/Props.h>
#include <react/core/propsConversions.h>
namespace facebook {
namespace react {
PointPropNativeComponentProps::PointPropNativeComponentProps(
const PointPropNativeComponentProps &sourceProps,
const RawProps &rawProps): ViewProps(sourceProps, rawProps),
startPoint(convertRawProp(rawProps, \\"startPoint\\", sourceProps.startPoint, startPoint))
{}
} // namespace react

View File

@@ -13,6 +13,7 @@ Map {
#include <react/components/view/ViewProps.h>
#include <react/graphics/Color.h>
#include <react/graphics/Geometry.h>
#include <react/imagemanager/primitives.h>
#include <vector>
@@ -32,6 +33,7 @@ const std::vector<int> progress{};
const std::vector<Float> radii{};
const std::vector<SharedColor> colors{};
const std::vector<ImageSource> srcs{};
const std::vector<Point> points{};
};
} // namespace react
@@ -368,6 +370,7 @@ Map {
#include <react/components/view/ViewProps.h>
#include <react/graphics/Color.h>
#include <react/graphics/Geometry.h>
#include <react/imagemanager/primitives.h>
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 <react/components/view/ViewProps.h>
#include <react/graphics/Geometry.h>
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

View File

@@ -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 <react/components/POINT_PROP/ShadowNodes.h>
namespace facebook {
namespace react {
extern const char PointPropNativeComponentComponentName[] = \\"PointPropNativeComponent\\";
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateShadowNodeCpp can generate fixture STRING_PROP 1`] = `
Map {
"ShadowNodes.cpp" => "

View File

@@ -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 <react/components/POINT_PROP/Props.h>
#include <react/components/view/ConcreteViewShadowNode.h>
namespace facebook {
namespace react {
extern const char PointPropNativeComponentComponentName[];
/*
* \`ShadowNode\` for <PointPropNativeComponent> component.
*/
using PointPropNativeComponentShadowNode = ConcreteViewShadowNode<
PointPropNativeComponentComponentName,
PointPropNativeComponentProps>;
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateShadowNodeH can generate fixture STRING_PROP 1`] = `
Map {
"ShadowNodes.h" => "

View File

@@ -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" => "