Skip to content

Commit 4766755

Browse files
rshestfacebook-github-bot
authored andcommitted
Support iterator-style prop parsing in ParagraphProps
Summary: Support iterator-style prop parsing in ParagraphProps Changelog: [Internal] Reviewed By: javache Differential Revision: D38833627 fbshipit-source-id: 31eac4e86c5855bb47f634da7cffaf2418273a36
1 parent 7de2b6b commit 4766755

File tree

3 files changed

+85
-22
lines changed

3 files changed

+85
-22
lines changed

ReactCommon/react/renderer/components/text/ParagraphProps.cpp

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,29 @@ ParagraphProps::ParagraphProps(
2323
RawProps const &rawProps)
2424
: ViewProps(context, sourceProps, rawProps),
2525
BaseTextProps(context, sourceProps, rawProps),
26-
paragraphAttributes(convertRawProp(
27-
context,
28-
rawProps,
29-
sourceProps.paragraphAttributes,
30-
{})),
31-
isSelectable(convertRawProp(
32-
context,
33-
rawProps,
34-
"selectable",
35-
sourceProps.isSelectable,
36-
false)),
37-
onTextLayout(convertRawProp(
38-
context,
39-
rawProps,
40-
"onTextLayout",
41-
sourceProps.onTextLayout,
42-
{})) {
26+
paragraphAttributes(
27+
Props::enablePropIteratorSetter ? sourceProps.paragraphAttributes
28+
: convertRawProp(
29+
context,
30+
rawProps,
31+
sourceProps.paragraphAttributes,
32+
{})),
33+
isSelectable(
34+
Props::enablePropIteratorSetter ? sourceProps.isSelectable
35+
: convertRawProp(
36+
context,
37+
rawProps,
38+
"selectable",
39+
sourceProps.isSelectable,
40+
false)),
41+
onTextLayout(
42+
Props::enablePropIteratorSetter ? sourceProps.onTextLayout
43+
: convertRawProp(
44+
context,
45+
rawProps,
46+
"onTextLayout",
47+
sourceProps.onTextLayout,
48+
{})) {
4349
/*
4450
* These props are applied to `View`, therefore they must not be a part of
4551
* base text attributes.
@@ -59,6 +65,63 @@ void ParagraphProps::setProp(
5965
ViewProps::setProp(context, hash, propName, value);
6066
BaseTextProps::setProp(context, hash, propName, value);
6167

68+
// ParagraphAttributes has its own switch statement - to keep all
69+
// of these fields together, and because there are some collisions between
70+
// propnames parsed here and outside of ParagraphAttributes.
71+
// This code is also duplicated in AndroidTextInput.
72+
static auto paDefaults = ParagraphAttributes{};
73+
switch (hash) {
74+
REBUILD_FIELD_SWITCH_CASE(
75+
paDefaults,
76+
value,
77+
paragraphAttributes,
78+
maximumNumberOfLines,
79+
"numberOfLines");
80+
REBUILD_FIELD_SWITCH_CASE(
81+
paDefaults, value, paragraphAttributes, ellipsizeMode, "ellipsizeMode");
82+
REBUILD_FIELD_SWITCH_CASE(
83+
paDefaults,
84+
value,
85+
paragraphAttributes,
86+
textBreakStrategy,
87+
"textBreakStrategy");
88+
REBUILD_FIELD_SWITCH_CASE(
89+
paDefaults,
90+
value,
91+
paragraphAttributes,
92+
adjustsFontSizeToFit,
93+
"adjustsFontSizeToFit");
94+
REBUILD_FIELD_SWITCH_CASE(
95+
paDefaults,
96+
value,
97+
paragraphAttributes,
98+
minimumFontSize,
99+
"minimumFontSize");
100+
REBUILD_FIELD_SWITCH_CASE(
101+
paDefaults,
102+
value,
103+
paragraphAttributes,
104+
maximumFontSize,
105+
"maximumFontSize");
106+
REBUILD_FIELD_SWITCH_CASE(
107+
paDefaults,
108+
value,
109+
paragraphAttributes,
110+
includeFontPadding,
111+
"includeFontPadding");
112+
REBUILD_FIELD_SWITCH_CASE(
113+
paDefaults,
114+
value,
115+
paragraphAttributes,
116+
android_hyphenationFrequency,
117+
"android_hyphenationFrequency");
118+
}
119+
120+
switch (hash) {
121+
RAW_SET_PROP_SWITCH_CASE_BASIC(isSelectable, false);
122+
RAW_SET_PROP_SWITCH_CASE_BASIC(onTextLayout, {});
123+
}
124+
62125
/*
63126
* These props are applied to `View`, therefore they must not be a part of
64127
* base text attributes.

ReactCommon/react/renderer/components/text/ParagraphProps.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class ParagraphProps : public ViewProps, public BaseTextProps {
4444
* Contains all prop values that affect visual representation of the
4545
* paragraph.
4646
*/
47-
ParagraphAttributes const paragraphAttributes{};
47+
ParagraphAttributes paragraphAttributes{};
4848

4949
/*
5050
* Defines can the text be selected (and copied) or not.
5151
*/
52-
bool const isSelectable{};
52+
bool isSelectable{};
5353

54-
bool const onTextLayout{};
54+
bool onTextLayout{};
5555

5656
#pragma mark - DebugStringConvertible
5757

ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,12 @@ void AndroidTextInputProps::setProp(
269269
ViewProps::setProp(context, hash, propName, value);
270270
BaseTextProps::setProp(context, hash, propName, value);
271271

272-
static auto paDefaults = ParagraphAttributes{};
273-
274272
// ParagraphAttributes has its own switch statement - to keep all
275273
// of these fields together, and because there are some collisions between
276274
// propnames parsed here and outside of ParagraphAttributes. For example,
277275
// textBreakStrategy is duplicated.
276+
// This code is also duplicated in ParagraphProps.
277+
static auto paDefaults = ParagraphAttributes{};
278278
switch (hash) {
279279
REBUILD_FIELD_SWITCH_CASE(
280280
paDefaults,

0 commit comments

Comments
 (0)