From 5d33e656947505545ca4284dfc7cb5e1b073fc4e Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 28 Jul 2021 20:16:53 -0700 Subject: [PATCH] Pass context through to all prop parser (props structs changes) Summary: See previous diffs for context. This updates all of the relevant props structs. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D29855426 fbshipit-source-id: 30177c3380ef82ecf8f2a4321f128cfbe8a576e0 --- .../renderer/components/image/ImageProps.cpp | 37 +++-- .../renderer/components/image/ImageProps.h | 6 +- .../LegacyViewManagerInteropViewProps.cpp | 10 +- .../LegacyViewManagerInteropViewProps.h | 2 + .../renderer/components/root/RootProps.cpp | 16 +- .../renderer/components/root/RootProps.h | 7 +- .../components/root/RootShadowNode.cpp | 3 +- .../renderer/components/root/RootShadowNode.h | 2 + .../components/scrollview/ScrollViewProps.cpp | 49 +++++- .../components/scrollview/ScrollViewProps.h | 6 +- .../components/text/BaseTextProps.cpp | 27 ++++ .../renderer/components/text/BaseTextProps.h | 6 +- .../text/ParagraphComponentDescriptor.h | 3 +- .../components/text/ParagraphProps.cpp | 14 +- .../renderer/components/text/ParagraphProps.h | 6 +- .../renderer/components/text/RawTextProps.cpp | 5 +- .../renderer/components/text/RawTextProps.h | 6 +- .../renderer/components/text/TextProps.cpp | 9 +- .../renderer/components/text/TextProps.h | 6 +- .../AndroidTextInputProps.cpp | 139 +++++++----------- .../androidtextinput/AndroidTextInputProps.h | 12 +- .../textinput/iostextinput/TextInputProps.cpp | 54 +++++-- .../textinput/iostextinput/TextInputProps.h | 6 +- .../textinput/iostextinput/conversions.h | 18 ++- .../textinput/iostextinput/propsConversions.h | 32 +++- .../UnimplementedViewProps.h | 1 + .../components/view/AccessibilityProps.cpp | 19 ++- .../components/view/AccessibilityProps.h | 2 + .../components/view/ViewComponentDescriptor.h | 7 +- .../renderer/components/view/ViewProps.cpp | 71 +++++++-- .../renderer/components/view/ViewProps.h | 6 +- .../components/view/YogaStylableProps.cpp | 5 +- .../components/view/YogaStylableProps.h | 2 + .../view/accessibilityPropsConversions.h | 27 +++- .../react/renderer/core/ComponentDescriptor.h | 3 + .../core/ConcreteComponentDescriptor.h | 11 +- .../react/renderer/core/ConcreteShadowNode.h | 3 + ReactCommon/react/renderer/core/Props.cpp | 12 +- ReactCommon/react/renderer/core/Props.h | 6 +- .../react/renderer/core/PropsParserContext.h | 28 ++++ ReactCommon/react/renderer/core/RawProps.cpp | 3 +- ReactCommon/react/renderer/core/RawProps.h | 4 +- .../react/renderer/core/RawPropsParser.h | 13 +- .../renderer/core/tests/RawPropsTest.cpp | 64 +++++--- .../react/renderer/graphics/conversions.h | 26 +++- .../generators/components/GeneratePropsCpp.js | 6 +- .../generators/components/GeneratePropsH.js | 22 +-- 47 files changed, 599 insertions(+), 223 deletions(-) create mode 100644 ReactCommon/react/renderer/core/PropsParserContext.h diff --git a/ReactCommon/react/renderer/components/image/ImageProps.cpp b/ReactCommon/react/renderer/components/image/ImageProps.cpp index 4a496bba12d..b007b4869d4 100644 --- a/ReactCommon/react/renderer/components/image/ImageProps.cpp +++ b/ReactCommon/react/renderer/components/image/ImageProps.cpp @@ -12,26 +12,45 @@ namespace facebook { namespace react { -ImageProps::ImageProps(const ImageProps &sourceProps, const RawProps &rawProps) - : ViewProps(sourceProps, rawProps), - sources(convertRawProp(rawProps, "source", sourceProps.sources, {})), +ImageProps::ImageProps( + const PropsParserContext &context, + const ImageProps &sourceProps, + const RawProps &rawProps) + : ViewProps(context, sourceProps, rawProps), + sources( + convertRawProp(context, rawProps, "source", sourceProps.sources, {})), defaultSources(convertRawProp( + context, rawProps, "defaultSource", sourceProps.defaultSources, {})), resizeMode(convertRawProp( + context, rawProps, "resizeMode", sourceProps.resizeMode, ImageResizeMode::Stretch)), - blurRadius( - convertRawProp(rawProps, "blurRadius", sourceProps.blurRadius, {})), - capInsets( - convertRawProp(rawProps, "capInsets", sourceProps.capInsets, {})), - tintColor( - convertRawProp(rawProps, "tintColor", sourceProps.tintColor, {})), + blurRadius(convertRawProp( + context, + rawProps, + "blurRadius", + sourceProps.blurRadius, + {})), + capInsets(convertRawProp( + context, + rawProps, + "capInsets", + sourceProps.capInsets, + {})), + tintColor(convertRawProp( + context, + rawProps, + "tintColor", + sourceProps.tintColor, + {})), internal_analyticTag(convertRawProp( + context, rawProps, "internal_analyticTag", sourceProps.internal_analyticTag, diff --git a/ReactCommon/react/renderer/components/image/ImageProps.h b/ReactCommon/react/renderer/components/image/ImageProps.h index 7ecfc27b8f7..b3d9ef36cf5 100644 --- a/ReactCommon/react/renderer/components/image/ImageProps.h +++ b/ReactCommon/react/renderer/components/image/ImageProps.h @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -16,7 +17,10 @@ namespace react { class ImageProps final : public ViewProps { public: ImageProps() = default; - ImageProps(const ImageProps &sourceProps, const RawProps &rawProps); + ImageProps( + const PropsParserContext &context, + const ImageProps &sourceProps, + const RawProps &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.cpp b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.cpp index db6236e0743..059384e82c0 100644 --- a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.cpp +++ b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.cpp @@ -12,12 +12,14 @@ namespace facebook { namespace react { LegacyViewManagerInteropViewProps::LegacyViewManagerInteropViewProps( + const PropsParserContext &context, const LegacyViewManagerInteropViewProps &sourceProps, const RawProps &rawProps) - : ViewProps(sourceProps, rawProps), - otherProps( - mergeDynamicProps(sourceProps.otherProps, (folly::dynamic)rawProps)) { -} + : ViewProps(context, sourceProps, rawProps), + otherProps(mergeDynamicProps( + context, + sourceProps.otherProps, + (folly::dynamic)rawProps)) {} } // namespace react } // namespace facebook diff --git a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h index 9b56571e579..b2645cd7de2 100644 --- a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h +++ b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h @@ -7,6 +7,7 @@ #include #include +#include #include namespace facebook { @@ -16,6 +17,7 @@ class LegacyViewManagerInteropViewProps final : public ViewProps { public: LegacyViewManagerInteropViewProps() = default; LegacyViewManagerInteropViewProps( + const PropsParserContext &context, const LegacyViewManagerInteropViewProps &sourceProps, const RawProps &rawProps); diff --git a/ReactCommon/react/renderer/components/root/RootProps.cpp b/ReactCommon/react/renderer/components/root/RootProps.cpp index beb6af92cbf..3e14c8a73ad 100644 --- a/ReactCommon/react/renderer/components/root/RootProps.cpp +++ b/ReactCommon/react/renderer/components/root/RootProps.cpp @@ -13,10 +13,20 @@ namespace facebook { namespace react { -RootProps::RootProps(RootProps const &sourceProps, RawProps const &rawProps) - : ViewProps(sourceProps, rawProps) {} - +// Note that a default/empty context may be passed here from RootShadowNode. +// If that's a problem and the context is necesary here, refactor RootShadowNode +// first. RootProps::RootProps( + const PropsParserContext &context, + RootProps const &sourceProps, + RawProps const &rawProps) + : ViewProps(context, sourceProps, rawProps) {} + +// Note that a default/empty context may be passed here from RootShadowNode. +// If that's a problem and the context is necesary here, refactor RootShadowNode +// first. +RootProps::RootProps( + const PropsParserContext &context, RootProps const &sourceProps, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext) diff --git a/ReactCommon/react/renderer/components/root/RootProps.h b/ReactCommon/react/renderer/components/root/RootProps.h index d3e2ea2dc05..d28f02837b9 100644 --- a/ReactCommon/react/renderer/components/root/RootProps.h +++ b/ReactCommon/react/renderer/components/root/RootProps.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -19,8 +20,12 @@ namespace react { class RootProps final : public ViewProps { public: RootProps() = default; - RootProps(RootProps const &sourceProps, RawProps const &rawProps); RootProps( + const PropsParserContext &context, + RootProps const &sourceProps, + RawProps const &rawProps); + RootProps( + const PropsParserContext &context, RootProps const &sourceProps, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext); diff --git a/ReactCommon/react/renderer/components/root/RootShadowNode.cpp b/ReactCommon/react/renderer/components/root/RootShadowNode.cpp index eeeb0c5ac68..5e611de8d61 100644 --- a/ReactCommon/react/renderer/components/root/RootShadowNode.cpp +++ b/ReactCommon/react/renderer/components/root/RootShadowNode.cpp @@ -39,10 +39,11 @@ Transform RootShadowNode::getTransform() const { } RootShadowNode::Unshared RootShadowNode::clone( + PropsParserContext const &propsParserContext, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext) const { auto props = std::make_shared( - getConcreteProps(), layoutConstraints, layoutContext); + propsParserContext, getConcreteProps(), layoutConstraints, layoutContext); auto newRootShadowNode = std::make_shared( *this, ShadowNodeFragment{ diff --git a/ReactCommon/react/renderer/components/root/RootShadowNode.h b/ReactCommon/react/renderer/components/root/RootShadowNode.h index 3625e679718..8d88ec91338 100644 --- a/ReactCommon/react/renderer/components/root/RootShadowNode.h +++ b/ReactCommon/react/renderer/components/root/RootShadowNode.h @@ -12,6 +12,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -51,6 +52,7 @@ class RootShadowNode final * Clones the node with given `layoutConstraints` and `layoutContext`. */ RootShadowNode::Unshared clone( + PropsParserContext const &propsParserContext, LayoutConstraints const &layoutConstraints, LayoutContext const &layoutContext) const; diff --git a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp index 8addef6feff..5ac1187937b 100644 --- a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp +++ b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp @@ -17,163 +17,204 @@ namespace facebook { namespace react { ScrollViewProps::ScrollViewProps( + const PropsParserContext &context, ScrollViewProps const &sourceProps, RawProps const &rawProps) - : ViewProps(sourceProps, rawProps), + : ViewProps(context, sourceProps, rawProps), alwaysBounceHorizontal(convertRawProp( + context, rawProps, "alwaysBounceHorizontal", sourceProps.alwaysBounceHorizontal, {})), alwaysBounceVertical(convertRawProp( + context, rawProps, "alwaysBounceVertical", sourceProps.alwaysBounceVertical, {})), - bounces(convertRawProp(rawProps, "bounces", sourceProps.bounces, true)), + bounces(convertRawProp( + context, + rawProps, + "bounces", + sourceProps.bounces, + true)), bouncesZoom(convertRawProp( + context, rawProps, "bouncesZoom", sourceProps.bouncesZoom, true)), canCancelContentTouches(convertRawProp( + context, rawProps, "canCancelContentTouches", sourceProps.canCancelContentTouches, true)), centerContent(convertRawProp( + context, rawProps, "centerContent", sourceProps.centerContent, {})), automaticallyAdjustContentInsets(convertRawProp( + context, rawProps, "automaticallyAdjustContentInsets", sourceProps.automaticallyAdjustContentInsets, {})), automaticallyAdjustsScrollIndicatorInsets(convertRawProp( + context, rawProps, "automaticallyAdjustsScrollIndicatorInsets", sourceProps.automaticallyAdjustsScrollIndicatorInsets, true)), decelerationRate(convertRawProp( + context, rawProps, "decelerationRate", sourceProps.decelerationRate, (Float)0.998)), directionalLockEnabled(convertRawProp( + context, rawProps, "directionalLockEnabled", sourceProps.directionalLockEnabled, {})), indicatorStyle(convertRawProp( + context, rawProps, "indicatorStyle", sourceProps.indicatorStyle, {})), keyboardDismissMode(convertRawProp( + context, rawProps, "keyboardDismissMode", sourceProps.keyboardDismissMode, {})), maximumZoomScale(convertRawProp( + context, rawProps, "maximumZoomScale", sourceProps.maximumZoomScale, (Float)1.0)), minimumZoomScale(convertRawProp( + context, rawProps, "minimumZoomScale", sourceProps.minimumZoomScale, (Float)1.0)), scrollEnabled(convertRawProp( + context, rawProps, "scrollEnabled", sourceProps.scrollEnabled, true)), pagingEnabled(convertRawProp( + context, rawProps, "pagingEnabled", sourceProps.pagingEnabled, {})), pinchGestureEnabled(convertRawProp( + context, rawProps, "pinchGestureEnabled", sourceProps.pinchGestureEnabled, true)), scrollsToTop(convertRawProp( + context, rawProps, "scrollsToTop", sourceProps.scrollsToTop, true)), showsHorizontalScrollIndicator(convertRawProp( + context, rawProps, "showsHorizontalScrollIndicator", sourceProps.showsHorizontalScrollIndicator, true)), showsVerticalScrollIndicator(convertRawProp( + context, rawProps, "showsVerticalScrollIndicator", sourceProps.showsVerticalScrollIndicator, true)), scrollEventThrottle(convertRawProp( + context, rawProps, "scrollEventThrottle", sourceProps.scrollEventThrottle, {})), zoomScale(convertRawProp( + context, rawProps, "zoomScale", sourceProps.zoomScale, (Float)1.0)), contentInset(convertRawProp( + context, rawProps, "contentInset", sourceProps.contentInset, {})), contentOffset(convertRawProp( + context, rawProps, "contentOffset", sourceProps.contentOffset, {})), scrollIndicatorInsets(convertRawProp( + context, rawProps, "scrollIndicatorInsets", sourceProps.scrollIndicatorInsets, {})), snapToInterval(convertRawProp( + context, rawProps, "snapToInterval", sourceProps.snapToInterval, {})), snapToAlignment(convertRawProp( + context, rawProps, "snapToAlignment", sourceProps.snapToAlignment, {})), disableIntervalMomentum(convertRawProp( + context, rawProps, "disableIntervalMomentum", sourceProps.disableIntervalMomentum, {})), snapToOffsets(convertRawProp( + context, rawProps, "snapToOffsets", sourceProps.snapToOffsets, {})), snapToStart(convertRawProp( + context, rawProps, "snapToStart", sourceProps.snapToStart, true)), - snapToEnd( - convertRawProp(rawProps, "snapToEnd", sourceProps.snapToEnd, true)), + snapToEnd(convertRawProp( + context, + rawProps, + "snapToEnd", + sourceProps.snapToEnd, + true)), contentInsetAdjustmentBehavior(convertRawProp( + context, rawProps, "contentInsetAdjustmentBehavior", sourceProps.contentInsetAdjustmentBehavior, {ContentInsetAdjustmentBehavior::Never})), scrollToOverflowEnabled(convertRawProp( + context, rawProps, "scrollToOverflowEnabled", sourceProps.scrollToOverflowEnabled, diff --git a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h index 31c3a2e919b..2e83cb16a19 100644 --- a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h +++ b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.h @@ -9,6 +9,7 @@ #include #include +#include namespace facebook { namespace react { @@ -17,7 +18,10 @@ namespace react { class ScrollViewProps final : public ViewProps { public: ScrollViewProps() = default; - ScrollViewProps(ScrollViewProps const &sourceProps, RawProps const &rawProps); + ScrollViewProps( + const PropsParserContext &context, + ScrollViewProps const &sourceProps, + RawProps const &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/text/BaseTextProps.cpp b/ReactCommon/react/renderer/components/text/BaseTextProps.cpp index fb4fe1d57d3..d8079cf4b81 100644 --- a/ReactCommon/react/renderer/components/text/BaseTextProps.cpp +++ b/ReactCommon/react/renderer/components/text/BaseTextProps.cpp @@ -16,6 +16,7 @@ namespace facebook { namespace react { static TextAttributes convertRawProp( + const PropsParserContext &context, const RawProps &rawProps, const TextAttributes sourceTextAttributes, const TextAttributes defaultTextAttributes) { @@ -23,16 +24,19 @@ static TextAttributes convertRawProp( // Color textAttributes.foregroundColor = convertRawProp( + context, rawProps, "color", sourceTextAttributes.foregroundColor, defaultTextAttributes.foregroundColor); textAttributes.backgroundColor = convertRawProp( + context, rawProps, "backgroundColor", sourceTextAttributes.backgroundColor, defaultTextAttributes.backgroundColor); textAttributes.opacity = convertRawProp( + context, rawProps, "opacity", sourceTextAttributes.opacity, @@ -40,46 +44,55 @@ static TextAttributes convertRawProp( // Font textAttributes.fontFamily = convertRawProp( + context, rawProps, "fontFamily", sourceTextAttributes.fontFamily, defaultTextAttributes.fontFamily); textAttributes.fontSize = convertRawProp( + context, rawProps, "fontSize", sourceTextAttributes.fontSize, defaultTextAttributes.fontSize); textAttributes.fontSizeMultiplier = convertRawProp( + context, rawProps, "fontSizeMultiplier", sourceTextAttributes.fontSizeMultiplier, defaultTextAttributes.fontSizeMultiplier); textAttributes.fontWeight = convertRawProp( + context, rawProps, "fontWeight", sourceTextAttributes.fontWeight, defaultTextAttributes.fontWeight); textAttributes.fontStyle = convertRawProp( + context, rawProps, "fontStyle", sourceTextAttributes.fontStyle, defaultTextAttributes.fontStyle); textAttributes.fontVariant = convertRawProp( + context, rawProps, "fontVariant", sourceTextAttributes.fontVariant, defaultTextAttributes.fontVariant); textAttributes.allowFontScaling = convertRawProp( + context, rawProps, "allowFontScaling", sourceTextAttributes.allowFontScaling, defaultTextAttributes.allowFontScaling); textAttributes.letterSpacing = convertRawProp( + context, rawProps, "letterSpacing", sourceTextAttributes.letterSpacing, defaultTextAttributes.letterSpacing); textAttributes.textTransform = convertRawProp( + context, rawProps, "textTransform", sourceTextAttributes.textTransform, @@ -87,16 +100,19 @@ static TextAttributes convertRawProp( // Paragraph textAttributes.lineHeight = convertRawProp( + context, rawProps, "lineHeight", sourceTextAttributes.lineHeight, defaultTextAttributes.lineHeight); textAttributes.alignment = convertRawProp( + context, rawProps, "textAlign", sourceTextAttributes.alignment, defaultTextAttributes.alignment); textAttributes.baseWritingDirection = convertRawProp( + context, rawProps, "baseWritingDirection", sourceTextAttributes.baseWritingDirection, @@ -104,21 +120,25 @@ static TextAttributes convertRawProp( // Decoration textAttributes.textDecorationColor = convertRawProp( + context, rawProps, "textDecorationColor", sourceTextAttributes.textDecorationColor, defaultTextAttributes.textDecorationColor); textAttributes.textDecorationLineType = convertRawProp( + context, rawProps, "textDecorationLine", sourceTextAttributes.textDecorationLineType, defaultTextAttributes.textDecorationLineType); textAttributes.textDecorationLineStyle = convertRawProp( + context, rawProps, "textDecorationLineStyle", sourceTextAttributes.textDecorationLineStyle, defaultTextAttributes.textDecorationLineStyle); textAttributes.textDecorationLinePattern = convertRawProp( + context, rawProps, "textDecorationLinePattern", sourceTextAttributes.textDecorationLinePattern, @@ -126,16 +146,19 @@ static TextAttributes convertRawProp( // Shadow textAttributes.textShadowOffset = convertRawProp( + context, rawProps, "textShadowOffset", sourceTextAttributes.textShadowOffset, defaultTextAttributes.textShadowOffset); textAttributes.textShadowRadius = convertRawProp( + context, rawProps, "textShadowRadius", sourceTextAttributes.textShadowRadius, defaultTextAttributes.textShadowRadius); textAttributes.textShadowColor = convertRawProp( + context, rawProps, "textShadowColor", sourceTextAttributes.textShadowColor, @@ -143,12 +166,14 @@ static TextAttributes convertRawProp( // Special textAttributes.isHighlighted = convertRawProp( + context, rawProps, "isHighlighted", sourceTextAttributes.isHighlighted, defaultTextAttributes.isHighlighted); textAttributes.accessibilityRole = convertRawProp( + context, rawProps, "accessibilityRole", sourceTextAttributes.accessibilityRole, @@ -158,9 +183,11 @@ static TextAttributes convertRawProp( } BaseTextProps::BaseTextProps( + const PropsParserContext &context, const BaseTextProps &sourceProps, const RawProps &rawProps) : textAttributes(convertRawProp( + context, rawProps, sourceProps.textAttributes, TextAttributes{})){}; diff --git a/ReactCommon/react/renderer/components/text/BaseTextProps.h b/ReactCommon/react/renderer/components/text/BaseTextProps.h index 4e4fefbafe5..c20d07b6c3e 100644 --- a/ReactCommon/react/renderer/components/text/BaseTextProps.h +++ b/ReactCommon/react/renderer/components/text/BaseTextProps.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -22,7 +23,10 @@ namespace react { class BaseTextProps { public: BaseTextProps() = default; - BaseTextProps(const BaseTextProps &sourceProps, const RawProps &rawProps); + BaseTextProps( + const PropsParserContext &context, + const BaseTextProps &sourceProps, + const RawProps &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/text/ParagraphComponentDescriptor.h b/ReactCommon/react/renderer/components/text/ParagraphComponentDescriptor.h index bc388600568..cd9baf46e57 100644 --- a/ReactCommon/react/renderer/components/text/ParagraphComponentDescriptor.h +++ b/ReactCommon/react/renderer/components/text/ParagraphComponentDescriptor.h @@ -33,10 +33,11 @@ class ParagraphComponentDescriptor final } virtual SharedProps interpolateProps( + const PropsParserContext &context, float animationProgress, const SharedProps &props, const SharedProps &newProps) const override { - SharedProps interpolatedPropsShared = cloneProps(newProps, {}); + SharedProps interpolatedPropsShared = cloneProps(context, newProps, {}); interpolateViewProps( animationProgress, props, newProps, interpolatedPropsShared); diff --git a/ReactCommon/react/renderer/components/text/ParagraphProps.cpp b/ReactCommon/react/renderer/components/text/ParagraphProps.cpp index 7508c571a83..632da3bdcd1 100644 --- a/ReactCommon/react/renderer/components/text/ParagraphProps.cpp +++ b/ReactCommon/react/renderer/components/text/ParagraphProps.cpp @@ -18,18 +18,24 @@ namespace facebook { namespace react { ParagraphProps::ParagraphProps( + const PropsParserContext &context, ParagraphProps const &sourceProps, RawProps const &rawProps) - : ViewProps(sourceProps, rawProps), - BaseTextProps(sourceProps, rawProps), - paragraphAttributes( - convertRawProp(rawProps, sourceProps.paragraphAttributes, {})), + : ViewProps(context, sourceProps, rawProps), + BaseTextProps(context, sourceProps, rawProps), + paragraphAttributes(convertRawProp( + context, + rawProps, + sourceProps.paragraphAttributes, + {})), isSelectable(convertRawProp( + context, rawProps, "selectable", sourceProps.isSelectable, false)), onTextLayout(convertRawProp( + context, rawProps, "onTextLayout", sourceProps.onTextLayout, diff --git a/ReactCommon/react/renderer/components/text/ParagraphProps.h b/ReactCommon/react/renderer/components/text/ParagraphProps.h index b456586c716..a82bbb8eb4b 100644 --- a/ReactCommon/react/renderer/components/text/ParagraphProps.h +++ b/ReactCommon/react/renderer/components/text/ParagraphProps.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -26,7 +27,10 @@ namespace react { class ParagraphProps : public ViewProps, public BaseTextProps { public: ParagraphProps() = default; - ParagraphProps(ParagraphProps const &sourceProps, RawProps const &rawProps); + ParagraphProps( + const PropsParserContext &context, + ParagraphProps const &sourceProps, + RawProps const &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/text/RawTextProps.cpp b/ReactCommon/react/renderer/components/text/RawTextProps.cpp index d54292bc527..3660824907f 100644 --- a/ReactCommon/react/renderer/components/text/RawTextProps.cpp +++ b/ReactCommon/react/renderer/components/text/RawTextProps.cpp @@ -14,10 +14,11 @@ namespace facebook { namespace react { RawTextProps::RawTextProps( + const PropsParserContext &context, const RawTextProps &sourceProps, const RawProps &rawProps) - : Props(sourceProps, rawProps), - text(convertRawProp(rawProps, "text", sourceProps.text, {})){}; + : Props(context, sourceProps, rawProps), + text(convertRawProp(context, rawProps, "text", sourceProps.text, {})){}; #pragma mark - DebugStringConvertible diff --git a/ReactCommon/react/renderer/components/text/RawTextProps.h b/ReactCommon/react/renderer/components/text/RawTextProps.h index 4b98953a0a2..2516e99b1c4 100644 --- a/ReactCommon/react/renderer/components/text/RawTextProps.h +++ b/ReactCommon/react/renderer/components/text/RawTextProps.h @@ -10,6 +10,7 @@ #include #include +#include #include namespace facebook { @@ -22,7 +23,10 @@ using SharedRawTextProps = std::shared_ptr; class RawTextProps : public Props { public: RawTextProps() = default; - RawTextProps(const RawTextProps &sourceProps, const RawProps &rawProps); + RawTextProps( + const PropsParserContext &context, + const RawTextProps &sourceProps, + const RawProps &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/text/TextProps.cpp b/ReactCommon/react/renderer/components/text/TextProps.cpp index ac07380c1cd..8e4bc4b0a6e 100644 --- a/ReactCommon/react/renderer/components/text/TextProps.cpp +++ b/ReactCommon/react/renderer/components/text/TextProps.cpp @@ -10,9 +10,12 @@ namespace facebook { namespace react { -TextProps::TextProps(const TextProps &sourceProps, const RawProps &rawProps) - : Props(sourceProps, rawProps), - BaseTextProps::BaseTextProps(sourceProps, rawProps){}; +TextProps::TextProps( + const PropsParserContext &context, + const TextProps &sourceProps, + const RawProps &rawProps) + : Props(context, sourceProps, rawProps), + BaseTextProps::BaseTextProps(context, sourceProps, rawProps){}; #pragma mark - DebugStringConvertible diff --git a/ReactCommon/react/renderer/components/text/TextProps.h b/ReactCommon/react/renderer/components/text/TextProps.h index 31e7be2a84f..9903b05e0d7 100644 --- a/ReactCommon/react/renderer/components/text/TextProps.h +++ b/ReactCommon/react/renderer/components/text/TextProps.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -19,7 +20,10 @@ namespace react { class TextProps : public Props, public BaseTextProps { public: TextProps() = default; - TextProps(const TextProps &sourceProps, const RawProps &rawProps); + TextProps( + const PropsParserContext &context, + const TextProps &sourceProps, + const RawProps &rawProps); #pragma mark - DebugStringConvertible diff --git a/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp b/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp index 54329d635e7..81dbfb6a767 100644 --- a/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp +++ b/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp @@ -37,215 +37,182 @@ static bool hasValue( } AndroidTextInputProps::AndroidTextInputProps( + const PropsParserContext &context, const AndroidTextInputProps &sourceProps, const RawProps &rawProps) - : ViewProps(sourceProps, rawProps), - BaseTextProps(sourceProps, rawProps), + : ViewProps(context, sourceProps, rawProps), + BaseTextProps(context, sourceProps, rawProps), autoCompleteType(convertRawProp( + context, rawProps, "autoCompleteType", sourceProps.autoCompleteType, {})), - returnKeyLabel(convertRawProp( - rawProps, + returnKeyLabel(convertRawProp(context, rawProps, "returnKeyLabel", sourceProps.returnKeyLabel, {})), - numberOfLines(convertRawProp( - rawProps, + numberOfLines(convertRawProp(context, rawProps, "numberOfLines", sourceProps.numberOfLines, {0})), - disableFullscreenUI(convertRawProp( - rawProps, + disableFullscreenUI(convertRawProp(context, rawProps, "disableFullscreenUI", sourceProps.disableFullscreenUI, {false})), - textBreakStrategy(convertRawProp( - rawProps, + textBreakStrategy(convertRawProp(context, rawProps, "textBreakStrategy", sourceProps.textBreakStrategy, {})), - underlineColorAndroid(convertRawProp( - rawProps, + underlineColorAndroid(convertRawProp(context, rawProps, "underlineColorAndroid", sourceProps.underlineColorAndroid, {})), - inlineImageLeft(convertRawProp( - rawProps, + inlineImageLeft(convertRawProp(context, rawProps, "inlineImageLeft", sourceProps.inlineImageLeft, {})), - inlineImagePadding(convertRawProp( - rawProps, + inlineImagePadding(convertRawProp(context, rawProps, "inlineImagePadding", sourceProps.inlineImagePadding, {0})), - importantForAutofill(convertRawProp( - rawProps, + importantForAutofill(convertRawProp(context, rawProps, "importantForAutofill", sourceProps.importantForAutofill, {})), - showSoftInputOnFocus(convertRawProp( - rawProps, + showSoftInputOnFocus(convertRawProp(context, rawProps, "showSoftInputOnFocus", sourceProps.showSoftInputOnFocus, {false})), - autoCapitalize(convertRawProp( - rawProps, + autoCapitalize(convertRawProp(context, rawProps, "autoCapitalize", sourceProps.autoCapitalize, {})), - autoCorrect(convertRawProp( - rawProps, + autoCorrect(convertRawProp(context, rawProps, "autoCorrect", sourceProps.autoCorrect, {false})), - autoFocus(convertRawProp( - rawProps, + autoFocus(convertRawProp(context, rawProps, "autoFocus", sourceProps.autoFocus, {false})), - allowFontScaling(convertRawProp( - rawProps, + allowFontScaling(convertRawProp(context, rawProps, "allowFontScaling", sourceProps.allowFontScaling, {false})), - maxFontSizeMultiplier(convertRawProp( - rawProps, + maxFontSizeMultiplier(convertRawProp(context, rawProps, "maxFontSizeMultiplier", sourceProps.maxFontSizeMultiplier, {0.0})), editable( - convertRawProp(rawProps, "editable", sourceProps.editable, {false})), - keyboardType(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "editable", sourceProps.editable, {false})), + keyboardType(convertRawProp(context, rawProps, "keyboardType", sourceProps.keyboardType, {})), - returnKeyType(convertRawProp( - rawProps, + returnKeyType(convertRawProp(context, rawProps, "returnKeyType", sourceProps.returnKeyType, {})), maxLength( - convertRawProp(rawProps, "maxLength", sourceProps.maxLength, {0})), - multiline(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "maxLength", sourceProps.maxLength, {0})), + multiline(convertRawProp(context, rawProps, "multiline", sourceProps.multiline, {false})), placeholder( - convertRawProp(rawProps, "placeholder", sourceProps.placeholder, {})), - placeholderTextColor(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "placeholder", sourceProps.placeholder, {})), + placeholderTextColor(convertRawProp(context, rawProps, "placeholderTextColor", sourceProps.placeholderTextColor, {})), - secureTextEntry(convertRawProp( - rawProps, + secureTextEntry(convertRawProp(context, rawProps, "secureTextEntry", sourceProps.secureTextEntry, {false})), - selectionColor(convertRawProp( - rawProps, + selectionColor(convertRawProp(context, rawProps, "selectionColor", sourceProps.selectionColor, {})), selection( - convertRawProp(rawProps, "selection", sourceProps.selection, {})), - value(convertRawProp(rawProps, "value", sourceProps.value, {})), - defaultValue(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "selection", sourceProps.selection, {})), + value(convertRawProp(context, rawProps, "value", sourceProps.value, {})), + defaultValue(convertRawProp(context, rawProps, "defaultValue", sourceProps.defaultValue, {})), - selectTextOnFocus(convertRawProp( - rawProps, + selectTextOnFocus(convertRawProp(context, rawProps, "selectTextOnFocus", sourceProps.selectTextOnFocus, {false})), - blurOnSubmit(convertRawProp( - rawProps, + blurOnSubmit(convertRawProp(context, rawProps, "blurOnSubmit", sourceProps.blurOnSubmit, {false})), - caretHidden(convertRawProp( - rawProps, + caretHidden(convertRawProp(context, rawProps, "caretHidden", sourceProps.caretHidden, {false})), - contextMenuHidden(convertRawProp( - rawProps, + contextMenuHidden(convertRawProp(context, rawProps, "contextMenuHidden", sourceProps.contextMenuHidden, {false})), - textShadowColor(convertRawProp( - rawProps, + textShadowColor(convertRawProp(context, rawProps, "textShadowColor", sourceProps.textShadowColor, {})), - textShadowRadius(convertRawProp( - rawProps, + textShadowRadius(convertRawProp(context, rawProps, "textShadowRadius", sourceProps.textShadowRadius, {0.0})), - textDecorationLine(convertRawProp( - rawProps, + textDecorationLine(convertRawProp(context, rawProps, "textDecorationLine", sourceProps.textDecorationLine, {})), fontStyle( - convertRawProp(rawProps, "fontStyle", sourceProps.fontStyle, {})), - textShadowOffset(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "fontStyle", sourceProps.fontStyle, {})), + textShadowOffset(convertRawProp(context, rawProps, "textShadowOffset", sourceProps.textShadowOffset, {})), - lineHeight(convertRawProp( - rawProps, + lineHeight(convertRawProp(context, rawProps, "lineHeight", sourceProps.lineHeight, {0.0})), - textTransform(convertRawProp( - rawProps, + textTransform(convertRawProp(context, rawProps, "textTransform", sourceProps.textTransform, {})), - color(convertRawProp(rawProps, "color", sourceProps.color, {0})), - letterSpacing(convertRawProp( - rawProps, + color(0 /*convertRawProp(context, rawProps, "color", sourceProps.color, {0})*/), + letterSpacing(convertRawProp(context, rawProps, "letterSpacing", sourceProps.letterSpacing, {0.0})), fontSize( - convertRawProp(rawProps, "fontSize", sourceProps.fontSize, {0.0})), + convertRawProp(context, rawProps, "fontSize", sourceProps.fontSize, {0.0})), textAlign( - convertRawProp(rawProps, "textAlign", sourceProps.textAlign, {})), - includeFontPadding(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "textAlign", sourceProps.textAlign, {})), + includeFontPadding(convertRawProp(context, rawProps, "includeFontPadding", sourceProps.includeFontPadding, {false})), fontWeight( - convertRawProp(rawProps, "fontWeight", sourceProps.fontWeight, {})), + convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})), fontFamily( - convertRawProp(rawProps, "fontFamily", sourceProps.fontFamily, {})), - textAlignVertical(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})), + textAlignVertical(convertRawProp(context, rawProps, "textAlignVertical", sourceProps.textAlignVertical, {})), cursorColor( - convertRawProp(rawProps, "cursorColor", sourceProps.cursorColor, {})), - mostRecentEventCount(convertRawProp( - rawProps, + convertRawProp(context, rawProps, "cursorColor", sourceProps.cursorColor, {})), + mostRecentEventCount(convertRawProp(context, rawProps, "mostRecentEventCount", sourceProps.mostRecentEventCount, {0})), - text(convertRawProp(rawProps, "text", sourceProps.text, {})), + text(convertRawProp(context, rawProps, "text", sourceProps.text, {})), paragraphAttributes( - convertRawProp(rawProps, sourceProps.paragraphAttributes, {})), + convertRawProp(context, rawProps, sourceProps.paragraphAttributes, {})), // See AndroidTextInputComponentDescriptor for usage // TODO T63008435: can these, and this feature, be removed entirely? hasPadding(hasValue(rawProps, sourceProps.hasPadding, "", "padding", "")), diff --git a/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.h b/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.h index d102df19431..66a670b78f9 100644 --- a/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.h +++ b/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -31,17 +32,18 @@ struct AndroidTextInputSelectionStruct { }; static inline void fromRawValue( + const PropsParserContext &context, const RawValue &value, AndroidTextInputSelectionStruct &result) { auto map = (better::map)value; auto start = map.find("start"); if (start != map.end()) { - fromRawValue(start->second, result.start); + fromRawValue(context, start->second, result.start); } auto end = map.find("end"); if (end != map.end()) { - fromRawValue(end->second, result.end); + fromRawValue(context, end->second, result.end); } } @@ -56,17 +58,18 @@ struct AndroidTextInputTextShadowOffsetStruct { }; static inline void fromRawValue( + const PropsParserContext &context, const RawValue &value, AndroidTextInputTextShadowOffsetStruct &result) { auto map = (better::map)value; auto width = map.find("width"); if (width != map.end()) { - fromRawValue(width->second, result.width); + fromRawValue(context, width->second, result.width); } auto height = map.find("height"); if (height != map.end()) { - fromRawValue(height->second, result.height); + fromRawValue(context, height->second, result.height); } } @@ -96,6 +99,7 @@ class AndroidTextInputProps final : public ViewProps, public BaseTextProps { public: AndroidTextInputProps() = default; AndroidTextInputProps( + const PropsParserContext &context, const AndroidTextInputProps &sourceProps, const RawProps &rawProps); diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.cpp b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.cpp index e102f463bf4..d7e4c3f93f1 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.cpp +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.cpp @@ -16,48 +16,74 @@ namespace facebook { namespace react { TextInputProps::TextInputProps( + const PropsParserContext &context, TextInputProps const &sourceProps, RawProps const &rawProps) - : ViewProps(sourceProps, rawProps), - BaseTextProps(sourceProps, rawProps), - traits(convertRawProp(rawProps, sourceProps.traits, {})), - paragraphAttributes( - convertRawProp(rawProps, sourceProps.paragraphAttributes, {})), + : ViewProps(context, sourceProps, rawProps), + BaseTextProps(context, sourceProps, rawProps), + traits(convertRawProp(context, rawProps, sourceProps.traits, {})), + paragraphAttributes(convertRawProp( + context, + rawProps, + sourceProps.paragraphAttributes, + {})), defaultValue(convertRawProp( + context, rawProps, "defaultValue", sourceProps.defaultValue, {})), - placeholder( - convertRawProp(rawProps, "placeholder", sourceProps.placeholder, {})), + placeholder(convertRawProp( + context, + rawProps, + "placeholder", + sourceProps.placeholder, + {})), placeholderTextColor(convertRawProp( + context, rawProps, "placeholderTextColor", sourceProps.placeholderTextColor, {})), - maxLength( - convertRawProp(rawProps, "maxLength", sourceProps.maxLength, {})), - cursorColor( - convertRawProp(rawProps, "cursorColor", sourceProps.cursorColor, {})), + maxLength(convertRawProp( + context, + rawProps, + "maxLength", + sourceProps.maxLength, + {})), + cursorColor(convertRawProp( + context, + rawProps, + "cursorColor", + sourceProps.cursorColor, + {})), selectionColor(convertRawProp( + context, rawProps, "selectionColor", sourceProps.selectionColor, {})), underlineColorAndroid(convertRawProp( + context, rawProps, "underlineColorAndroid", sourceProps.underlineColorAndroid, {})), - text(convertRawProp(rawProps, "text", sourceProps.text, {})), + text(convertRawProp(context, rawProps, "text", sourceProps.text, {})), mostRecentEventCount(convertRawProp( + context, rawProps, "mostRecentEventCount", sourceProps.mostRecentEventCount, {})), - autoFocus( - convertRawProp(rawProps, "autoFocus", sourceProps.autoFocus, {})), + autoFocus(convertRawProp( + context, + rawProps, + "autoFocus", + sourceProps.autoFocus, + {})), inputAccessoryViewID(convertRawProp( + context, rawProps, "inputAccessoryViewID", sourceProps.inputAccessoryViewID, diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.h b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.h index a12503ff669..50b054e0b3e 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.h +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,10 @@ namespace react { class TextInputProps final : public ViewProps, public BaseTextProps { public: TextInputProps() = default; - TextInputProps(TextInputProps const &sourceProps, RawProps const &rawProps); + TextInputProps( + const PropsParserContext &context, + TextInputProps const &sourceProps, + RawProps const &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/conversions.h b/ReactCommon/react/renderer/components/textinput/iostextinput/conversions.h index cc935fadecf..56be93b9da1 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/conversions.h +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/conversions.h @@ -8,12 +8,14 @@ #pragma once #include +#include #include namespace facebook { namespace react { inline void fromRawValue( + const PropsParserContext &context, const RawValue &value, AutocapitalizationType &result) { auto string = (std::string)value; @@ -36,7 +38,10 @@ inline void fromRawValue( abort(); } -inline void fromRawValue(const RawValue &value, KeyboardAppearance &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + KeyboardAppearance &result) { auto string = (std::string)value; if (string == "default") { result = KeyboardAppearance::Default; @@ -53,7 +58,10 @@ inline void fromRawValue(const RawValue &value, KeyboardAppearance &result) { abort(); } -inline void fromRawValue(const RawValue &value, ReturnKeyType &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + ReturnKeyType &result) { auto string = (std::string)value; if (string == "default") { result = ReturnKeyType::Default; @@ -119,6 +127,7 @@ inline void fromRawValue(const RawValue &value, ReturnKeyType &result) { } inline void fromRawValue( + const PropsParserContext &context, const RawValue &value, TextInputAccessoryVisibilityMode &result) { auto string = (std::string)value; @@ -141,7 +150,10 @@ inline void fromRawValue( abort(); } -inline void fromRawValue(const RawValue &value, KeyboardType &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + KeyboardType &result) { auto string = (std::string)value; if (string == "default") { result = KeyboardType::Default; diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/propsConversions.h b/ReactCommon/react/renderer/components/textinput/iostextinput/propsConversions.h index 4de4dc98d98..cfd0675c407 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/propsConversions.h +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/propsConversions.h @@ -8,107 +8,135 @@ #pragma once #include +#include #include namespace facebook { namespace react { static TextInputTraits convertRawProp( + const PropsParserContext &context, RawProps const &rawProps, TextInputTraits const &sourceTraits, TextInputTraits const &defaultTraits) { auto traits = TextInputTraits{}; traits.multiline = convertRawProp( - rawProps, "multiline", sourceTraits.multiline, defaultTraits.multiline); + context, + rawProps, + "multiline", + sourceTraits.multiline, + defaultTraits.multiline); traits.autocapitalizationType = convertRawProp( + context, rawProps, "autoCapitalize", sourceTraits.autocapitalizationType, defaultTraits.autocapitalizationType); traits.autoCorrect = convertRawProp( + context, rawProps, "autoCorrect", sourceTraits.autoCorrect, defaultTraits.autoCorrect); traits.contextMenuHidden = convertRawProp( + context, rawProps, "contextMenuHidden", sourceTraits.contextMenuHidden, defaultTraits.contextMenuHidden); traits.editable = convertRawProp( - rawProps, "editable", sourceTraits.editable, defaultTraits.editable); + context, + rawProps, + "editable", + sourceTraits.editable, + defaultTraits.editable); traits.enablesReturnKeyAutomatically = convertRawProp( + context, rawProps, "enablesReturnKeyAutomatically", sourceTraits.enablesReturnKeyAutomatically, defaultTraits.enablesReturnKeyAutomatically); traits.keyboardAppearance = convertRawProp( + context, rawProps, "keyboardAppearance", sourceTraits.keyboardAppearance, defaultTraits.keyboardAppearance); traits.spellCheck = convertRawProp( + context, rawProps, "spellCheck", sourceTraits.spellCheck, defaultTraits.spellCheck); traits.caretHidden = convertRawProp( + context, rawProps, "caretHidden", sourceTraits.caretHidden, defaultTraits.caretHidden); traits.clearButtonMode = convertRawProp( + context, rawProps, "clearButtonMode", sourceTraits.clearButtonMode, defaultTraits.clearButtonMode); traits.scrollEnabled = convertRawProp( + context, rawProps, "scrollEnabled", sourceTraits.scrollEnabled, defaultTraits.scrollEnabled); traits.secureTextEntry = convertRawProp( + context, rawProps, "secureTextEntry", sourceTraits.secureTextEntry, defaultTraits.secureTextEntry); traits.blurOnSubmit = convertRawProp( + context, rawProps, "blurOnSubmit", sourceTraits.blurOnSubmit, defaultTraits.blurOnSubmit); traits.clearTextOnFocus = convertRawProp( + context, rawProps, "clearTextOnFocus", sourceTraits.clearTextOnFocus, defaultTraits.clearTextOnFocus); traits.keyboardType = convertRawProp( + context, rawProps, "keyboardType", sourceTraits.keyboardType, defaultTraits.keyboardType); traits.showSoftInputOnFocus = convertRawProp( + context, rawProps, "showSoftInputOnFocus", sourceTraits.showSoftInputOnFocus, defaultTraits.showSoftInputOnFocus); traits.returnKeyType = convertRawProp( + context, rawProps, "returnKeyType", sourceTraits.returnKeyType, defaultTraits.returnKeyType); traits.selectTextOnFocus = convertRawProp( + context, rawProps, "selectTextOnFocus", sourceTraits.selectTextOnFocus, defaultTraits.selectTextOnFocus); traits.textContentType = convertRawProp( + context, rawProps, "textContentType", sourceTraits.textContentType, defaultTraits.textContentType); traits.passwordRules = convertRawProp( + context, rawProps, "passwordRules", sourceTraits.passwordRules, diff --git a/ReactCommon/react/renderer/components/unimplementedview/UnimplementedViewProps.h b/ReactCommon/react/renderer/components/unimplementedview/UnimplementedViewProps.h index 637769f62f1..c2907a50abc 100644 --- a/ReactCommon/react/renderer/components/unimplementedview/UnimplementedViewProps.h +++ b/ReactCommon/react/renderer/components/unimplementedview/UnimplementedViewProps.h @@ -8,6 +8,7 @@ #pragma once #include +#include namespace facebook { namespace react { diff --git a/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp b/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp index d47d3782a6b..d681a387ad4 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp +++ b/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp @@ -16,79 +16,96 @@ namespace facebook { namespace react { AccessibilityProps::AccessibilityProps( + const PropsParserContext &context, AccessibilityProps const &sourceProps, RawProps const &rawProps) : accessible(convertRawProp( + context, rawProps, "accessible", sourceProps.accessible, false)), accessibilityTraits(convertRawProp( + context, rawProps, "accessibilityRole", sourceProps.accessibilityTraits, AccessibilityTraits::None)), accessibilityState(convertRawProp( + context, rawProps, "accessibilityState", sourceProps.accessibilityState, {})), accessibilityLabel(convertRawProp( + context, rawProps, "accessibilityLabel", sourceProps.accessibilityLabel, "")), accessibilityHint(convertRawProp( + context, rawProps, "accessibilityHint", sourceProps.accessibilityHint, "")), accessibilityActions(convertRawProp( + context, rawProps, "accessibilityActions", sourceProps.accessibilityActions, {})), accessibilityViewIsModal(convertRawProp( + context, rawProps, "accessibilityViewIsModal", sourceProps.accessibilityViewIsModal, false)), accessibilityElementsHidden(convertRawProp( + context, rawProps, "accessibilityElementsHidden", sourceProps.accessibilityElementsHidden, false)), accessibilityIgnoresInvertColors(convertRawProp( + context, rawProps, "accessibilityIgnoresInvertColors", sourceProps.accessibilityIgnoresInvertColors, false)), onAccessibilityTap(convertRawProp( + context, rawProps, "onAccessibilityTap", sourceProps.onAccessibilityTap, {})), onAccessibilityMagicTap(convertRawProp( + context, rawProps, "onAccessibilityMagicTap", sourceProps.onAccessibilityMagicTap, {})), onAccessibilityEscape(convertRawProp( + context, rawProps, "onAccessibilityEscape", sourceProps.onAccessibilityEscape, {})), onAccessibilityAction(convertRawProp( + context, rawProps, "onAccessibilityAction", sourceProps.onAccessibilityAction, {})), importantForAccessibility(convertRawProp( + context, rawProps, "importantForAccessibility", sourceProps.importantForAccessibility, ImportantForAccessibility::Auto)), - testId(convertRawProp(rawProps, "testID", sourceProps.testId, "")) {} + testId( + convertRawProp(context, rawProps, "testID", sourceProps.testId, "")) { +} #pragma mark - DebugStringConvertible diff --git a/ReactCommon/react/renderer/components/view/AccessibilityProps.h b/ReactCommon/react/renderer/components/view/AccessibilityProps.h index 362ee83f085..39330c082b5 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityProps.h +++ b/ReactCommon/react/renderer/components/view/AccessibilityProps.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -19,6 +20,7 @@ class AccessibilityProps { public: AccessibilityProps() = default; AccessibilityProps( + const PropsParserContext &context, AccessibilityProps const &sourceProps, RawProps const &rawProps); diff --git a/ReactCommon/react/renderer/components/view/ViewComponentDescriptor.h b/ReactCommon/react/renderer/components/view/ViewComponentDescriptor.h index 4ec013c7fb5..e9609b75f5f 100644 --- a/ReactCommon/react/renderer/components/view/ViewComponentDescriptor.h +++ b/ReactCommon/react/renderer/components/view/ViewComponentDescriptor.h @@ -22,6 +22,7 @@ class ViewComponentDescriptor : ConcreteComponentDescriptor(parameters) {} virtual SharedProps interpolateProps( + const PropsParserContext &context, float animationProgress, const SharedProps &props, const SharedProps &newProps) const override { @@ -29,10 +30,10 @@ class ViewComponentDescriptor // On Android only, the merged props should have the same RawProps as the // final props struct SharedProps interpolatedPropsShared = - (newProps != nullptr ? cloneProps(newProps, newProps->rawProps) - : cloneProps(newProps, {})); + (newProps != nullptr ? cloneProps(context, newProps, newProps->rawProps) + : cloneProps(context, newProps, {})); #else - SharedProps interpolatedPropsShared = cloneProps(newProps, {}); + SharedProps interpolatedPropsShared = cloneProps(context, newProps, {}); #endif interpolateViewProps( diff --git a/ReactCommon/react/renderer/components/view/ViewProps.cpp b/ReactCommon/react/renderer/components/view/ViewProps.cpp index 504ddbcd16f..0e1a9976793 100644 --- a/ReactCommon/react/renderer/components/view/ViewProps.cpp +++ b/ReactCommon/react/renderer/components/view/ViewProps.cpp @@ -18,88 +18,131 @@ namespace facebook { namespace react { -ViewProps::ViewProps(ViewProps const &sourceProps, RawProps const &rawProps) - : YogaStylableProps(sourceProps, rawProps), - AccessibilityProps(sourceProps, rawProps), - opacity( - convertRawProp(rawProps, "opacity", sourceProps.opacity, (Float)1.0)), +ViewProps::ViewProps( + const PropsParserContext &context, + ViewProps const &sourceProps, + RawProps const &rawProps) + : YogaStylableProps(context, sourceProps, rawProps), + AccessibilityProps(context, sourceProps, rawProps), + opacity(convertRawProp( + context, + rawProps, + "opacity", + sourceProps.opacity, + (Float)1.0)), foregroundColor(convertRawProp( + context, rawProps, "foregroundColor", sourceProps.foregroundColor, {})), backgroundColor(convertRawProp( + context, rawProps, "backgroundColor", sourceProps.backgroundColor, {})), borderRadii(convertRawProp( + context, rawProps, "border", "Radius", sourceProps.borderRadii, {})), borderColors(convertRawProp( + context, rawProps, "border", "Color", sourceProps.borderColors, {})), borderStyles(convertRawProp( + context, rawProps, "border", "Style", sourceProps.borderStyles, {})), - shadowColor( - convertRawProp(rawProps, "shadowColor", sourceProps.shadowColor, {})), + shadowColor(convertRawProp( + context, + rawProps, + "shadowColor", + sourceProps.shadowColor, + {})), shadowOffset(convertRawProp( + context, rawProps, "shadowOffset", sourceProps.shadowOffset, {})), shadowOpacity(convertRawProp( + context, rawProps, "shadowOpacity", sourceProps.shadowOpacity, {})), shadowRadius(convertRawProp( + context, rawProps, "shadowRadius", sourceProps.shadowRadius, {})), - transform( - convertRawProp(rawProps, "transform", sourceProps.transform, {})), + transform(convertRawProp( + context, + rawProps, + "transform", + sourceProps.transform, + {})), backfaceVisibility(convertRawProp( + context, rawProps, "backfaceVisibility", sourceProps.backfaceVisibility, {})), shouldRasterize(convertRawProp( + context, rawProps, "shouldRasterize", sourceProps.shouldRasterize, {})), - zIndex(convertRawProp(rawProps, "zIndex", sourceProps.zIndex, {})), + zIndex( + convertRawProp(context, rawProps, "zIndex", sourceProps.zIndex, {})), pointerEvents(convertRawProp( + context, rawProps, "pointerEvents", sourceProps.pointerEvents, {})), - hitSlop(convertRawProp(rawProps, "hitSlop", sourceProps.hitSlop, {})), - onLayout(convertRawProp(rawProps, "onLayout", sourceProps.onLayout, {})), + hitSlop(convertRawProp( + context, + rawProps, + "hitSlop", + sourceProps.hitSlop, + {})), + onLayout(convertRawProp( + context, + rawProps, + "onLayout", + sourceProps.onLayout, + {})), collapsable(convertRawProp( + context, rawProps, "collapsable", sourceProps.collapsable, true)), removeClippedSubviews(convertRawProp( + context, rawProps, "removeClippedSubviews", sourceProps.removeClippedSubviews, false)), - elevation( - convertRawProp(rawProps, "elevation", sourceProps.elevation, {})){}; + elevation(convertRawProp( + context, + rawProps, + "elevation", + sourceProps.elevation, + {})){}; #pragma mark - Convenience Methods diff --git a/ReactCommon/react/renderer/components/view/ViewProps.h b/ReactCommon/react/renderer/components/view/ViewProps.h index daa0d1890b9..b66249a6915 100644 --- a/ReactCommon/react/renderer/components/view/ViewProps.h +++ b/ReactCommon/react/renderer/components/view/ViewProps.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,10 @@ using SharedViewProps = std::shared_ptr; class ViewProps : public YogaStylableProps, public AccessibilityProps { public: ViewProps() = default; - ViewProps(ViewProps const &sourceProps, RawProps const &rawProps); + ViewProps( + const PropsParserContext &context, + ViewProps const &sourceProps, + RawProps const &rawProps); #pragma mark - Props diff --git a/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp b/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp index 8fe909a188a..d8c44f49f5c 100644 --- a/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp +++ b/ReactCommon/react/renderer/components/view/YogaStylableProps.cpp @@ -20,10 +20,11 @@ namespace facebook { namespace react { YogaStylableProps::YogaStylableProps( + const PropsParserContext &context, YogaStylableProps const &sourceProps, RawProps const &rawProps) - : Props(sourceProps, rawProps), - yogaStyle(convertRawProp(rawProps, sourceProps.yogaStyle)){}; + : Props(context, sourceProps, rawProps), + yogaStyle(convertRawProp(context, rawProps, sourceProps.yogaStyle)){}; #pragma mark - DebugStringConvertible diff --git a/ReactCommon/react/renderer/components/view/YogaStylableProps.h b/ReactCommon/react/renderer/components/view/YogaStylableProps.h index d272f069346..3d6e314d6c0 100644 --- a/ReactCommon/react/renderer/components/view/YogaStylableProps.h +++ b/ReactCommon/react/renderer/components/view/YogaStylableProps.h @@ -10,6 +10,7 @@ #include #include +#include #include namespace facebook { @@ -19,6 +20,7 @@ class YogaStylableProps : public Props { public: YogaStylableProps() = default; YogaStylableProps( + const PropsParserContext &context, YogaStylableProps const &sourceProps, RawProps const &rawProps); diff --git a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h index 5eb0b6e4a4d..37b8961a0ca 100644 --- a/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h +++ b/ReactCommon/react/renderer/components/view/accessibilityPropsConversions.h @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace facebook { @@ -96,7 +97,10 @@ inline void fromString(const std::string &string, AccessibilityTraits &result) { result = AccessibilityTraits::None; } -inline void fromRawValue(const RawValue &value, AccessibilityTraits &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + AccessibilityTraits &result) { if (value.hasType()) { fromString((std::string)value, result); return; @@ -117,15 +121,18 @@ inline void fromRawValue(const RawValue &value, AccessibilityTraits &result) { } } -inline void fromRawValue(const RawValue &value, AccessibilityState &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + AccessibilityState &result) { auto map = (better::map)value; auto selected = map.find("selected"); if (selected != map.end()) { - fromRawValue(selected->second, result.selected); + fromRawValue(context, selected->second, result.selected); } auto disabled = map.find("disabled"); if (disabled != map.end()) { - fromRawValue(disabled->second, result.disabled); + fromRawValue(context, disabled->second, result.disabled); } auto checked = map.find("checked"); if (checked != map.end()) { @@ -147,11 +154,11 @@ inline void fromRawValue(const RawValue &value, AccessibilityState &result) { } auto busy = map.find("busy"); if (busy != map.end()) { - fromRawValue(busy->second, result.busy); + fromRawValue(context, busy->second, result.busy); } auto expanded = map.find("expanded"); if (expanded != map.end()) { - fromRawValue(expanded->second, result.expanded); + fromRawValue(context, expanded->second, result.expanded); } } @@ -170,6 +177,7 @@ inline std::string toString( } inline void fromRawValue( + const PropsParserContext &context, const RawValue &value, ImportantForAccessibility &result) { react_native_assert(value.hasType()); @@ -192,13 +200,16 @@ inline void fromRawValue( } } -inline void fromRawValue(const RawValue &value, AccessibilityAction &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + AccessibilityAction &result) { auto map = (better::map)value; auto name = map.find("name"); react_native_assert(name != map.end() && name->second.hasType()); if (name != map.end()) { - fromRawValue(name->second, result.name); + fromRawValue(context, name->second, result.name); } auto label = map.find("label"); diff --git a/ReactCommon/react/renderer/core/ComponentDescriptor.h b/ReactCommon/react/renderer/core/ComponentDescriptor.h index 1ec633552b3..cc50c109d7d 100644 --- a/ReactCommon/react/renderer/core/ComponentDescriptor.h +++ b/ReactCommon/react/renderer/core/ComponentDescriptor.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -101,6 +102,7 @@ class ComponentDescriptor { * Must return an object which is NOT pointer equal to `props`. */ virtual SharedProps cloneProps( + const PropsParserContext &context, const SharedProps &props, const RawProps &rawProps) const = 0; @@ -109,6 +111,7 @@ class ComponentDescriptor { * between `props` and `newProps`. */ virtual SharedProps interpolateProps( + const PropsParserContext &context, float animationProgress, const SharedProps &props, const SharedProps &newProps) const = 0; diff --git a/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 1e6b6eb035b..45625c8f5eb 100644 --- a/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -103,6 +104,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { } virtual SharedProps cloneProps( + const PropsParserContext &context, const SharedProps &props, const RawProps &rawProps) const override { react_native_assert( @@ -119,12 +121,13 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { return ShadowNodeT::defaultSharedProps(); } - rawProps.parse(rawPropsParser_); + rawProps.parse(rawPropsParser_, context); - return ShadowNodeT::Props(rawProps, props); + return ShadowNodeT::Props(context, rawProps, props); }; virtual SharedProps interpolateProps( + const PropsParserContext &context, float animationProgress, const SharedProps &props, const SharedProps &newProps) const override { @@ -133,11 +136,11 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { // On Android only, the merged props should have the same RawProps as the // final props struct if (newProps != nullptr) { - return cloneProps(newProps, newProps->rawProps); + return cloneProps(context, newProps, newProps->rawProps); } #endif - return cloneProps(newProps, {}); + return cloneProps(context, newProps, {}); }; virtual State::Shared createInitialState( diff --git a/ReactCommon/react/renderer/core/ConcreteShadowNode.h b/ReactCommon/react/renderer/core/ConcreteShadowNode.h index 6a3ffb80f5b..d441f326a0b 100644 --- a/ReactCommon/react/renderer/core/ConcreteShadowNode.h +++ b/ReactCommon/react/renderer/core/ConcreteShadowNode.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -68,9 +69,11 @@ class ConcreteShadowNode : public BaseShadowNodeT { } static SharedConcreteProps Props( + const PropsParserContext &context, RawProps const &rawProps, SharedProps const &baseProps = nullptr) { return std::make_shared( + context, baseProps ? static_cast(*baseProps) : PropsT(), rawProps); } diff --git a/ReactCommon/react/renderer/core/Props.cpp b/ReactCommon/react/renderer/core/Props.cpp index 79d6777691f..f502fccfdf2 100644 --- a/ReactCommon/react/renderer/core/Props.cpp +++ b/ReactCommon/react/renderer/core/Props.cpp @@ -13,8 +13,16 @@ namespace facebook { namespace react { -Props::Props(const Props &sourceProps, const RawProps &rawProps) - : nativeId(convertRawProp(rawProps, "nativeID", sourceProps.nativeId, {})), +Props::Props( + const PropsParserContext &context, + const Props &sourceProps, + const RawProps &rawProps) + : nativeId(convertRawProp( + context, + rawProps, + "nativeID", + sourceProps.nativeId, + {})), revision(sourceProps.revision + 1) #ifdef ANDROID , diff --git a/ReactCommon/react/renderer/core/Props.h b/ReactCommon/react/renderer/core/Props.h index 5653509fd7a..3321310b433 100644 --- a/ReactCommon/react/renderer/core/Props.h +++ b/ReactCommon/react/renderer/core/Props.h @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -28,7 +29,10 @@ class Props : public virtual Sealable, public virtual DebugStringConvertible { using Shared = std::shared_ptr; Props() = default; - Props(Props const &sourceProps, RawProps const &rawProps); + Props( + const PropsParserContext &context, + const Props &sourceProps, + RawProps const &rawProps); virtual ~Props() = default; std::string nativeId; diff --git a/ReactCommon/react/renderer/core/PropsParserContext.h b/ReactCommon/react/renderer/core/PropsParserContext.h new file mode 100644 index 00000000000..9b9d10d2dcb --- /dev/null +++ b/ReactCommon/react/renderer/core/PropsParserContext.h @@ -0,0 +1,28 @@ +/* + * 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 { + +// For props requiring some context to parse, this toolbox can be used. +// It should be used as infrequently as possible - most props can and should +// be parsed without any context. +struct PropsParserContext { + // Non-copyable + PropsParserContext(const PropsParserContext &) = delete; + PropsParserContext &operator=(const PropsParserContext &) = delete; + + int surfaceId; // TODO: use SurfaceId type + const ContextContainer &contextContainer; +}; + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/react/renderer/core/RawProps.cpp b/ReactCommon/react/renderer/core/RawProps.cpp index f48dffa2cd7..4776ce5ac81 100644 --- a/ReactCommon/react/renderer/core/RawProps.cpp +++ b/ReactCommon/react/renderer/core/RawProps.cpp @@ -47,7 +47,8 @@ RawProps::RawProps(folly::dynamic const &dynamic) noexcept { dynamic_ = dynamic; } -void RawProps::parse(RawPropsParser const &parser) const noexcept { +void RawProps::parse(RawPropsParser const &parser, const PropsParserContext &) + const noexcept { react_native_assert(parser_ == nullptr && "A parser was already assigned."); parser_ = &parser; parser.preparse(*this); diff --git a/ReactCommon/react/renderer/core/RawProps.h b/ReactCommon/react/renderer/core/RawProps.h index 152f7528f9d..3cb96eca5fe 100644 --- a/ReactCommon/react/renderer/core/RawProps.h +++ b/ReactCommon/react/renderer/core/RawProps.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -74,7 +75,8 @@ class RawProps final { RawProps(RawProps const &other) noexcept = delete; RawProps &operator=(RawProps const &other) noexcept = delete; - void parse(RawPropsParser const &parser) const noexcept; + void parse(RawPropsParser const &parser, const PropsParserContext &) + const noexcept; /* * Deprecated. Do not use. diff --git a/ReactCommon/react/renderer/core/RawPropsParser.h b/ReactCommon/react/renderer/core/RawPropsParser.h index ff1a73b4c16..5d37cefd8c3 100644 --- a/ReactCommon/react/renderer/core/RawPropsParser.h +++ b/ReactCommon/react/renderer/core/RawPropsParser.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -40,8 +41,16 @@ class RawPropsParser final { std::is_base_of::value, "PropsT must be a descendant of Props"); RawProps emptyRawProps{}; - emptyRawProps.parse(*this); - PropsT({}, emptyRawProps); + + // Create a stub parser context. + // Since this prepares the parser by passing in + // empty props, no prop parsers should actually reference the + // ContextContainer or SurfaceId here. + ContextContainer contextContainer{}; + PropsParserContext parserContext{-1, contextContainer}; + + emptyRawProps.parse(*this, parserContext); + PropsT(parserContext, {}, emptyRawProps); postPrepare(); } diff --git a/ReactCommon/react/renderer/core/tests/RawPropsTest.cpp b/ReactCommon/react/renderer/core/tests/RawPropsTest.cpp index 2e54fc8bf02..de5b1b2bcf7 100644 --- a/ReactCommon/react/renderer/core/tests/RawPropsTest.cpp +++ b/ReactCommon/react/renderer/core/tests/RawPropsTest.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -21,9 +22,11 @@ class PropsSingleFloat : public Props { public: PropsSingleFloat() = default; PropsSingleFloat( + const PropsParserContext &context, const PropsSingleFloat &sourceProps, const RawProps &rawProps) : floatValue(convertRawProp( + context, rawProps, "floatValue", sourceProps.floatValue, @@ -37,9 +40,11 @@ class PropsSingleDouble : public Props { public: PropsSingleDouble() = default; PropsSingleDouble( + const PropsParserContext &context, const PropsSingleDouble &sourceProps, const RawProps &rawProps) : doubleValue(convertRawProp( + context, rawProps, "doubleValue", sourceProps.doubleValue, @@ -52,9 +57,16 @@ class PropsSingleDouble : public Props { class PropsSingleInt : public Props { public: PropsSingleInt() = default; - PropsSingleInt(const PropsSingleInt &sourceProps, const RawProps &rawProps) - : intValue( - convertRawProp(rawProps, "intValue", sourceProps.intValue, 17)) {} + PropsSingleInt( + const PropsParserContext &context, + const PropsSingleInt &sourceProps, + const RawProps &rawProps) + : intValue(convertRawProp( + context, + rawProps, + "intValue", + sourceProps.intValue, + 17)) {} private: const int intValue{17}; @@ -64,26 +76,35 @@ class PropsPrimitiveTypes : public Props { public: PropsPrimitiveTypes() = default; PropsPrimitiveTypes( + const PropsParserContext &context, const PropsPrimitiveTypes &sourceProps, const RawProps &rawProps) - : intValue( - convertRawProp(rawProps, "intValue", sourceProps.intValue, 17)), + : intValue(convertRawProp( + context, + rawProps, + "intValue", + sourceProps.intValue, + 17)), doubleValue(convertRawProp( + context, rawProps, "doubleValue", sourceProps.doubleValue, 17.56)), floatValue(convertRawProp( + context, rawProps, "floatValue", sourceProps.floatValue, 56.75)), stringValue(convertRawProp( + context, rawProps, "stringValue", sourceProps.stringValue, "")), boolValue(convertRawProp( + context, rawProps, "boolValue", sourceProps.boolValue, @@ -101,9 +122,11 @@ class PropsMultiLookup : public Props { public: PropsMultiLookup() = default; PropsMultiLookup( + const PropsParserContext &context, const PropsMultiLookup &sourceProps, const RawProps &rawProps) : floatValue(convertRawProp( + context, rawProps, "floatValue", sourceProps.floatValue, @@ -112,7 +135,12 @@ class PropsMultiLookup : public Props { // pattern that does occur a lot: nested structs that access props we // have already accessed populating Props derivedFloatValue( - convertRawProp(rawProps, "floatValue", sourceProps.floatValue, 40) * + convertRawProp( + context, + rawProps, + "floatValue", + sourceProps.floatValue, + 40) * 2) {} const float floatValue{17.5}; @@ -123,7 +151,7 @@ TEST(RawPropsTest, handleProps) { const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc")); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); auto props = std::make_shared(Props(), raw); @@ -137,7 +165,7 @@ TEST(RawPropsTest, handleRawPropsSingleString) { const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc")); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); std::string value = (std::string)*raw.at("nativeID", nullptr, nullptr); @@ -149,7 +177,7 @@ TEST(RawPropsTest, handleRawPropsSingleFloat) { RawProps(folly::dynamic::object("floatValue", (float)42.42)); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); float value = (float)*raw.at("floatValue", nullptr, nullptr); @@ -161,7 +189,7 @@ TEST(RawPropsTest, handleRawPropsSingleDouble) { RawProps(folly::dynamic::object("doubleValue", (double)42.42)); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); double value = (double)*raw.at("doubleValue", nullptr, nullptr); @@ -172,7 +200,7 @@ TEST(RawPropsTest, handleRawPropsSingleInt) { const auto &raw = RawProps(folly::dynamic::object("intValue", (int)42.42)); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); int value = (int)*raw.at("intValue", nullptr, nullptr); @@ -183,7 +211,7 @@ TEST(RawPropsTest, handleRawPropsSingleIntGetManyTimes) { const auto &raw = RawProps(folly::dynamic::object("intValue", (int)42.42)); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42); EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42); @@ -198,7 +226,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypes) { auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42); EXPECT_NEAR((double)*raw.at("doubleValue", nullptr, nullptr), 17.42, 0.0001); @@ -217,7 +245,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetTwice) { auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42); EXPECT_NEAR((double)*raw.at("doubleValue", nullptr, nullptr), 17.42, 0.0001); @@ -244,7 +272,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesGetOutOfOrder) { auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42); EXPECT_NEAR((double)*raw.at("doubleValue", nullptr, nullptr), 17.42, 0.0001); @@ -268,7 +296,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncomplete) { auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); EXPECT_EQ((int)*raw.at("intValue", nullptr, nullptr), 42); EXPECT_EQ(raw.at("doubleValue", nullptr, nullptr), nullptr); @@ -285,7 +313,7 @@ TEST(RawPropsTest, handleRawPropsPrimitiveTypesIncorrectLookup) { auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); // Before D18662135, looking up an invalid key would trigger // an infinite loop. This is out of contract, so we should only @@ -299,7 +327,7 @@ TEST(RawPropsTest, handlePropsMultiLookup) { const auto &raw = RawProps(folly::dynamic::object("floatValue", (float)10.0)); auto parser = RawPropsParser(); parser.prepare(); - raw.parse(parser); + raw.parse(parser, {}); auto props = std::make_shared(PropsMultiLookup(), raw); diff --git a/ReactCommon/react/renderer/graphics/conversions.h b/ReactCommon/react/renderer/graphics/conversions.h index 8818e3fff05..dfa06ac0479 100644 --- a/ReactCommon/react/renderer/graphics/conversions.h +++ b/ReactCommon/react/renderer/graphics/conversions.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,7 +21,10 @@ namespace react { #pragma mark - Color -inline void fromRawValue(const RawValue &value, SharedColor &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + SharedColor &result) { float red = 0; float green = 0; float blue = 0; @@ -81,7 +85,10 @@ inline std::string toString(const SharedColor &value) { #pragma mark - Geometry -inline void fromRawValue(const RawValue &value, Point &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + Point &result) { if (value.hasType>()) { auto map = (better::map)value; for (const auto &pair : map) { @@ -109,7 +116,10 @@ inline void fromRawValue(const RawValue &value, Point &result) { } } -inline void fromRawValue(const RawValue &value, Size &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + Size &result) { if (value.hasType>()) { auto map = (better::map)value; for (const auto &pair : map) { @@ -140,7 +150,10 @@ inline void fromRawValue(const RawValue &value, Size &result) { } } -inline void fromRawValue(const RawValue &value, EdgeInsets &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + EdgeInsets &result) { if (value.hasType()) { auto number = (Float)value; result = {number, number, number, number}; @@ -180,7 +193,10 @@ inline void fromRawValue(const RawValue &value, EdgeInsets &result) { } } -inline void fromRawValue(const RawValue &value, CornerInsets &result) { +inline void fromRawValue( + const PropsParserContext &context, + const RawValue &value, + CornerInsets &result) { if (value.hasType()) { auto number = (Float)value; result = {number, number, number, number}; diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js index 50452248199..b29fdf7adf9 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js @@ -40,6 +40,7 @@ namespace react { const componentTemplate = ` ::_CLASSNAME_::::::_CLASSNAME_::( + const PropsParserContext &context, const ::_CLASSNAME_:: &sourceProps, const RawProps &rawProps):::_EXTEND_CLASSES_:: @@ -51,7 +52,7 @@ function generatePropsString(componentName: string, component: ComponentShape) { return component.props .map(prop => { const defaultValue = convertDefaultTypeToString(componentName, prop); - return `${prop.name}(convertRawProp(rawProps, "${prop.name}", sourceProps.${prop.name}, {${defaultValue}}))`; + return `${prop.name}(convertRawProp(context, rawProps, "${prop.name}", sourceProps.${prop.name}, {${defaultValue}}))`; }) .join(',\n' + ' '); } @@ -65,7 +66,7 @@ function getClassExtendString(component): string { case 'ReactNativeBuiltInType': switch (extendProps.knownTypeName) { case 'ReactNativeCoreViewProps': - return 'ViewProps(sourceProps, rawProps)'; + return 'ViewProps(context, sourceProps, rawProps)'; default: (extendProps.knownTypeName: empty); throw new Error('Invalid knownTypeName'); @@ -91,6 +92,7 @@ module.exports = { const fileName = 'Props.cpp'; const allImports: Set = new Set([ '#include ', + '#include ', ]); const componentProps = Object.keys(schema.modules) diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index 868d21bbf10..bdbd5886294 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -60,7 +60,7 @@ const classTemplate = ` class ::_CLASSNAME_:: final::_EXTEND_CLASSES_:: { public: ::_CLASSNAME_::() = default; - ::_CLASSNAME_::(const ::_CLASSNAME_:: &sourceProps, const RawProps &rawProps); + ::_CLASSNAME_::(const PropsParserContext& context, const ::_CLASSNAME_:: &sourceProps, const RawProps &rawProps); #pragma mark - Props @@ -71,7 +71,7 @@ class ::_CLASSNAME_:: final::_EXTEND_CLASSES_:: { const enumTemplate = ` enum class ::_ENUM_NAME_:: { ::_VALUES_:: }; -static inline void fromRawValue(const RawValue &value, ::_ENUM_NAME_:: &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_ENUM_NAME_:: &result) { auto string = (std::string)value; ::_FROM_CASES_:: abort(); @@ -87,7 +87,7 @@ static inline std::string toString(const ::_ENUM_NAME_:: &value) { const intEnumTemplate = ` enum class ::_ENUM_NAME_:: { ::_VALUES_:: }; -static inline void fromRawValue(const RawValue &value, ::_ENUM_NAME_:: &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_ENUM_NAME_:: &result) { assert(value.hasType()); auto integerValue = (int)value; switch (integerValue) {::_FROM_CASES_:: @@ -106,7 +106,7 @@ const structTemplate = `struct ::_STRUCT_NAME_:: { ::_FIELDS_:: }; -static inline void fromRawValue(const RawValue &value, ::_STRUCT_NAME_:: &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_STRUCT_NAME_:: &result) { auto map = (better::map)value; ::_FROM_CASES_:: @@ -117,23 +117,23 @@ static inline std::string toString(const ::_STRUCT_NAME_:: &value) { } `.trim(); -const arrayConversionFunction = `static inline void fromRawValue(const RawValue &value, std::vector<::_STRUCT_NAME_::> &result) { +const arrayConversionFunction = `static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector<::_STRUCT_NAME_::> &result) { auto items = (std::vector)value; for (const auto &item : items) { ::_STRUCT_NAME_:: newItem; - fromRawValue(item, newItem); + fromRawValue(context, item, newItem); result.emplace_back(newItem); } } `; -const doubleArrayConversionFunction = `static inline void fromRawValue(const RawValue &value, std::vector> &result) { +const doubleArrayConversionFunction = `static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, std::vector> &result) { auto items = (std::vector>)value; for (const std::vector &item : items) { auto nestedArray = std::vector<::_STRUCT_NAME_::>{}; for (const RawValue &nestedItem : item) { ::_STRUCT_NAME_:: newItem; - fromRawValue(nestedItem, newItem); + fromRawValue(context, nestedItem, newItem); nestedArray.emplace_back(newItem); } result.emplace_back(nestedArray); @@ -166,7 +166,7 @@ constexpr void operator|=( lhs = lhs | static_cast<::_ENUM_MASK_::>(rhs); } -static inline void fromRawValue(const RawValue &value, ::_ENUM_MASK_:: &result) { +static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ::_ENUM_MASK_:: &result) { auto items = std::vector{value}; for (const auto &item : items) { ::_FROM_CASES_:: @@ -460,6 +460,8 @@ function getExtendsImports( ): Set { const imports: Set = new Set(); + imports.add('#include '); + extendsProps.forEach(extendProps => { switch (extendProps.type) { case 'ReactNativeBuiltInType': @@ -737,7 +739,7 @@ function generateStruct( const variable = property.name; return `auto ${variable} = map.find("${property.name}"); if (${variable} != map.end()) { - fromRawValue(${variable}->second, result.${variable}); + fromRawValue(context, ${variable}->second, result.${variable}); }`; }) .join('\n ');