From 2319f75c8e63d2868ea2bb9bb75e4a0338c12e8c Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Sun, 2 Oct 2022 03:38:07 -0700 Subject: [PATCH] Support iterator-style prop parsing in ImageProps Summary: Support iterator-style prop parsing in ImageProps Changelog: [Internal] Reviewed By: javache Differential Revision: D38834100 fbshipit-source-id: 69274595cca8e6f40cd5e0ad9aac1582f57acc61 --- .../renderer/components/image/ImageProps.cpp | 114 ++++++++++++------ .../renderer/components/image/ImageProps.h | 20 +-- .../components/scrollview/ScrollViewProps.cpp | 4 + 3 files changed, 94 insertions(+), 44 deletions(-) diff --git a/ReactCommon/react/renderer/components/image/ImageProps.cpp b/ReactCommon/react/renderer/components/image/ImageProps.cpp index 37ca6e4208cf58..9dca74cded2574 100644 --- a/ReactCommon/react/renderer/components/image/ImageProps.cpp +++ b/ReactCommon/react/renderer/components/image/ImageProps.cpp @@ -18,43 +18,83 @@ ImageProps::ImageProps( 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( - 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, - {})) {} + Props::enablePropIteratorSetter ? sourceProps.sources + : convertRawProp( + context, + rawProps, + "source", + sourceProps.sources, + {})), + defaultSources( + Props::enablePropIteratorSetter ? sourceProps.defaultSources + : convertRawProp( + context, + rawProps, + "defaultSource", + sourceProps.defaultSources, + {})), + resizeMode( + Props::enablePropIteratorSetter ? sourceProps.resizeMode + : convertRawProp( + context, + rawProps, + "resizeMode", + sourceProps.resizeMode, + ImageResizeMode::Stretch)), + blurRadius( + Props::enablePropIteratorSetter ? sourceProps.blurRadius + : convertRawProp( + context, + rawProps, + "blurRadius", + sourceProps.blurRadius, + {})), + capInsets( + Props::enablePropIteratorSetter ? sourceProps.capInsets + : convertRawProp( + context, + rawProps, + "capInsets", + sourceProps.capInsets, + {})), + tintColor( + Props::enablePropIteratorSetter ? sourceProps.tintColor + : convertRawProp( + context, + rawProps, + "tintColor", + sourceProps.tintColor, + {})), + internal_analyticTag( + Props::enablePropIteratorSetter + ? sourceProps.internal_analyticTag + : convertRawProp( + context, + rawProps, + "internal_analyticTag", + sourceProps.internal_analyticTag, + {})) {} + +void ImageProps::setProp( + const PropsParserContext &context, + RawPropsPropNameHash hash, + const char *propName, + RawValue const &value) { + // All Props structs setProp methods must always, unconditionally, + // call all super::setProp methods, since multiple structs may + // reuse the same values. + ViewProps::setProp(context, hash, propName, value); + + switch (hash) { + RAW_SET_PROP_SWITCH_CASE(sources, "source", {}); + RAW_SET_PROP_SWITCH_CASE(defaultSources, "defaultSource", {}); + RAW_SET_PROP_SWITCH_CASE_BASIC(resizeMode, ImageResizeMode::Stretch); + RAW_SET_PROP_SWITCH_CASE_BASIC(blurRadius, {}); + RAW_SET_PROP_SWITCH_CASE_BASIC(capInsets, {}); + RAW_SET_PROP_SWITCH_CASE_BASIC(tintColor, {}); + RAW_SET_PROP_SWITCH_CASE_BASIC(internal_analyticTag, {}); + } +} } // namespace react } // namespace facebook diff --git a/ReactCommon/react/renderer/components/image/ImageProps.h b/ReactCommon/react/renderer/components/image/ImageProps.h index dd55bce0961426..6c1e4c3536176f 100644 --- a/ReactCommon/react/renderer/components/image/ImageProps.h +++ b/ReactCommon/react/renderer/components/image/ImageProps.h @@ -22,15 +22,21 @@ class ImageProps final : public ViewProps { const ImageProps &sourceProps, const RawProps &rawProps); + void setProp( + const PropsParserContext &context, + RawPropsPropNameHash hash, + const char *propName, + RawValue const &value); + #pragma mark - Props - const ImageSources sources{}; - const ImageSources defaultSources{}; - const ImageResizeMode resizeMode{ImageResizeMode::Stretch}; - const Float blurRadius{}; - const EdgeInsets capInsets{}; - const SharedColor tintColor{}; - const std::string internal_analyticTag{}; + ImageSources sources{}; + ImageSources defaultSources{}; + ImageResizeMode resizeMode{ImageResizeMode::Stretch}; + Float blurRadius{}; + EdgeInsets capInsets{}; + SharedColor tintColor{}; + std::string internal_analyticTag{}; }; } // namespace react diff --git a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp index ff1611d71fcbe0..ee6791cd97857e 100644 --- a/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp +++ b/ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp @@ -303,7 +303,11 @@ void ScrollViewProps::setProp( RawPropsPropNameHash hash, const char *propName, RawValue const &value) { + // All Props structs setProp methods must always, unconditionally, + // call all super::setProp methods, since multiple structs may + // reuse the same values. ViewProps::setProp(context, hash, propName, value); + switch (hash) { RAW_SET_PROP_SWITCH_CASE_BASIC(alwaysBounceHorizontal, {}); RAW_SET_PROP_SWITCH_CASE_BASIC(alwaysBounceVertical, {});