Fix codegen for Array<EdgeInsetsValue>

Summary:
Changelog:
[Internal][Added] - Add support for props of type Array<EdgeInsetsValue>

Reviewed By: christophpurrer

Differential Revision: D42651078

fbshipit-source-id: 3b8683ab199c3d590136cec0e6a67e9e85aaa2c0
This commit is contained in:
Genki Kondo
2023-01-23 11:06:09 -08:00
committed by Facebook GitHub Bot
parent 114e03ebe5
commit 04cf92fa9e
7 changed files with 15 additions and 3 deletions
@@ -8,7 +8,10 @@
* @flow strict-local
*/
import type {PointValue} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
import type {
EdgeInsetsValue,
PointValue,
} from '../../../../../Libraries/StyleSheet/StyleSheetTypes';
import type {ColorValue} from '../../../../../Libraries/StyleSheet/StyleSheet';
import type {ImageSource} from '../../../../../Libraries/Image/ImageSource';
import type {
@@ -31,8 +34,7 @@ type NativeProps = $ReadOnly<{|
colors?: $ReadOnlyArray<ColorValue>,
srcs?: $ReadOnlyArray<ImageSource>,
points?: $ReadOnlyArray<PointValue>,
// TODO(T104760003) Fix EdgeInsetsValue in codegen
// edgeInsets?: $ReadOnlyArray<EdgeInsetsValue>,
edgeInsets?: $ReadOnlyArray<EdgeInsetsValue>,
sizes?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>,
object?: $ReadOnlyArray<$ReadOnly<{|prop: string|}>>,
|}>;
@@ -32,6 +32,7 @@ ArrayPropsNativeComponentViewProps::ArrayPropsNativeComponentViewProps(
colors(convertRawProp(context, rawProps, \\"colors\\", sourceProps.colors, {})),
srcs(convertRawProp(context, rawProps, \\"srcs\\", sourceProps.srcs, {})),
points(convertRawProp(context, rawProps, \\"points\\", sourceProps.points, {})),
edgeInsets(convertRawProp(context, rawProps, \\"edgeInsets\\", sourceProps.edgeInsets, {})),
sizes(convertRawProp(context, rawProps, \\"sizes\\", sourceProps.sizes, {static_cast<ArrayPropsNativeComponentViewSizesMask>(ArrayPropsNativeComponentViewSizes::Small)})),
object(convertRawProp(context, rawProps, \\"object\\", sourceProps.object, {}))
{}
@@ -19,6 +19,7 @@ Object {
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/graphics/Point.h>
#include <react/renderer/graphics/RectangleEdges.h>
#include <react/renderer/imagemanager/primitives.h>
#include <vector>
@@ -120,6 +121,7 @@ class JSI_EXPORT ArrayPropsNativeComponentViewProps final : public ViewProps {
std::vector<SharedColor> colors{};
std::vector<ImageSource> srcs{};
std::vector<Point> points{};
std::vector<EdgeInsets> edgeInsets{};
ArrayPropsNativeComponentViewSizesMask sizes{static_cast<ArrayPropsNativeComponentViewSizesMask>(ArrayPropsNativeComponentViewSizes::Small)};
std::vector<ArrayPropsNativeComponentViewObjectStruct> object{};
};
@@ -47,6 +47,9 @@ public class ArrayPropsNativeComponentViewManagerDelegate<T extends View, U exte
case \\"points\\":
mViewManager.setPoints(view, (ReadableArray) value);
break;
case \\"edgeInsets\\":
mViewManager.setEdgeInsets(view, (ReadableArray) value);
break;
case \\"sizes\\":
mViewManager.setSizes(view, (ReadableArray) value);
break;
@@ -25,6 +25,7 @@ public interface ArrayPropsNativeComponentViewManagerInterface<T extends View> {
void setColors(T view, @Nullable ReadableArray value);
void setSrcs(T view, @Nullable ReadableArray value);
void setPoints(T view, @Nullable ReadableArray value);
void setEdgeInsets(T view, @Nullable ReadableArray value);
void setSizes(T view, @Nullable ReadableArray value);
void setObject(T view, @Nullable ReadableArray value);
}
@@ -36,6 +36,7 @@ export const __INTERNAL_VIEW_CONFIG = {
srcs: true,
points: true,
edgeInsets: true,
sizes: true,
object: true,
},
@@ -93,6 +93,8 @@ function getReactDiffProcessValue(typeAnnotation: PropTypeAnnotation) {
return j.literal(true);
case 'PointPrimitive':
return j.literal(true);
case 'EdgeInsetsPrimitive':
return j.literal(true);
default:
throw new Error(
`Received unknown array native typeAnnotation: "${typeAnnotation.elementType.name}"`,