Skip to content

Commit 2319f75

Browse files
rshestfacebook-github-bot
authored andcommitted
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
1 parent 4766755 commit 2319f75

File tree

3 files changed

+94
-44
lines changed

3 files changed

+94
-44
lines changed

ReactCommon/react/renderer/components/image/ImageProps.cpp

Lines changed: 77 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,83 @@ ImageProps::ImageProps(
1818
const RawProps &rawProps)
1919
: ViewProps(context, sourceProps, rawProps),
2020
sources(
21-
convertRawProp(context, rawProps, "source", sourceProps.sources, {})),
22-
defaultSources(convertRawProp(
23-
context,
24-
rawProps,
25-
"defaultSource",
26-
sourceProps.defaultSources,
27-
{})),
28-
resizeMode(convertRawProp(
29-
context,
30-
rawProps,
31-
"resizeMode",
32-
sourceProps.resizeMode,
33-
ImageResizeMode::Stretch)),
34-
blurRadius(convertRawProp(
35-
context,
36-
rawProps,
37-
"blurRadius",
38-
sourceProps.blurRadius,
39-
{})),
40-
capInsets(convertRawProp(
41-
context,
42-
rawProps,
43-
"capInsets",
44-
sourceProps.capInsets,
45-
{})),
46-
tintColor(convertRawProp(
47-
context,
48-
rawProps,
49-
"tintColor",
50-
sourceProps.tintColor,
51-
{})),
52-
internal_analyticTag(convertRawProp(
53-
context,
54-
rawProps,
55-
"internal_analyticTag",
56-
sourceProps.internal_analyticTag,
57-
{})) {}
21+
Props::enablePropIteratorSetter ? sourceProps.sources
22+
: convertRawProp(
23+
context,
24+
rawProps,
25+
"source",
26+
sourceProps.sources,
27+
{})),
28+
defaultSources(
29+
Props::enablePropIteratorSetter ? sourceProps.defaultSources
30+
: convertRawProp(
31+
context,
32+
rawProps,
33+
"defaultSource",
34+
sourceProps.defaultSources,
35+
{})),
36+
resizeMode(
37+
Props::enablePropIteratorSetter ? sourceProps.resizeMode
38+
: convertRawProp(
39+
context,
40+
rawProps,
41+
"resizeMode",
42+
sourceProps.resizeMode,
43+
ImageResizeMode::Stretch)),
44+
blurRadius(
45+
Props::enablePropIteratorSetter ? sourceProps.blurRadius
46+
: convertRawProp(
47+
context,
48+
rawProps,
49+
"blurRadius",
50+
sourceProps.blurRadius,
51+
{})),
52+
capInsets(
53+
Props::enablePropIteratorSetter ? sourceProps.capInsets
54+
: convertRawProp(
55+
context,
56+
rawProps,
57+
"capInsets",
58+
sourceProps.capInsets,
59+
{})),
60+
tintColor(
61+
Props::enablePropIteratorSetter ? sourceProps.tintColor
62+
: convertRawProp(
63+
context,
64+
rawProps,
65+
"tintColor",
66+
sourceProps.tintColor,
67+
{})),
68+
internal_analyticTag(
69+
Props::enablePropIteratorSetter
70+
? sourceProps.internal_analyticTag
71+
: convertRawProp(
72+
context,
73+
rawProps,
74+
"internal_analyticTag",
75+
sourceProps.internal_analyticTag,
76+
{})) {}
77+
78+
void ImageProps::setProp(
79+
const PropsParserContext &context,
80+
RawPropsPropNameHash hash,
81+
const char *propName,
82+
RawValue const &value) {
83+
// All Props structs setProp methods must always, unconditionally,
84+
// call all super::setProp methods, since multiple structs may
85+
// reuse the same values.
86+
ViewProps::setProp(context, hash, propName, value);
87+
88+
switch (hash) {
89+
RAW_SET_PROP_SWITCH_CASE(sources, "source", {});
90+
RAW_SET_PROP_SWITCH_CASE(defaultSources, "defaultSource", {});
91+
RAW_SET_PROP_SWITCH_CASE_BASIC(resizeMode, ImageResizeMode::Stretch);
92+
RAW_SET_PROP_SWITCH_CASE_BASIC(blurRadius, {});
93+
RAW_SET_PROP_SWITCH_CASE_BASIC(capInsets, {});
94+
RAW_SET_PROP_SWITCH_CASE_BASIC(tintColor, {});
95+
RAW_SET_PROP_SWITCH_CASE_BASIC(internal_analyticTag, {});
96+
}
97+
}
5898

5999
} // namespace react
60100
} // namespace facebook

ReactCommon/react/renderer/components/image/ImageProps.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ class ImageProps final : public ViewProps {
2222
const ImageProps &sourceProps,
2323
const RawProps &rawProps);
2424

25+
void setProp(
26+
const PropsParserContext &context,
27+
RawPropsPropNameHash hash,
28+
const char *propName,
29+
RawValue const &value);
30+
2531
#pragma mark - Props
2632

27-
const ImageSources sources{};
28-
const ImageSources defaultSources{};
29-
const ImageResizeMode resizeMode{ImageResizeMode::Stretch};
30-
const Float blurRadius{};
31-
const EdgeInsets capInsets{};
32-
const SharedColor tintColor{};
33-
const std::string internal_analyticTag{};
33+
ImageSources sources{};
34+
ImageSources defaultSources{};
35+
ImageResizeMode resizeMode{ImageResizeMode::Stretch};
36+
Float blurRadius{};
37+
EdgeInsets capInsets{};
38+
SharedColor tintColor{};
39+
std::string internal_analyticTag{};
3440
};
3541

3642
} // namespace react

ReactCommon/react/renderer/components/scrollview/ScrollViewProps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ void ScrollViewProps::setProp(
303303
RawPropsPropNameHash hash,
304304
const char *propName,
305305
RawValue const &value) {
306+
// All Props structs setProp methods must always, unconditionally,
307+
// call all super::setProp methods, since multiple structs may
308+
// reuse the same values.
306309
ViewProps::setProp(context, hash, propName, value);
310+
307311
switch (hash) {
308312
RAW_SET_PROP_SWITCH_CASE_BASIC(alwaysBounceHorizontal, {});
309313
RAW_SET_PROP_SWITCH_CASE_BASIC(alwaysBounceVertical, {});

0 commit comments

Comments
 (0)