Skip to content

Commit 8991f78

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Move textAlignVertical to paragraph props (facebook#51712)
Summary: Pull Request resolved: facebook#51712 This prop only works on top level text components, yet it is stored as a TextAttribute. It should be a ParagraphAttribute, so I moved it there. Changelog: [Android] [Breaking] - Move textAlignVertical to paragraph attributes instead of text attributes Reviewed By: NickGerleman Differential Revision: D75684576
1 parent 0a9092f commit 8991f78

File tree

9 files changed

+62
-48
lines changed

9 files changed

+62
-48
lines changed

packages/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ bool ParagraphAttributes::operator==(const ParagraphAttributes& rhs) const {
2121
textBreakStrategy,
2222
adjustsFontSizeToFit,
2323
includeFontPadding,
24-
android_hyphenationFrequency) ==
24+
android_hyphenationFrequency,
25+
textAlignVertical) ==
2526
std::tie(
2627
rhs.maximumNumberOfLines,
2728
rhs.ellipsizeMode,
2829
rhs.textBreakStrategy,
2930
rhs.adjustsFontSizeToFit,
3031
rhs.includeFontPadding,
31-
rhs.android_hyphenationFrequency) &&
32+
rhs.android_hyphenationFrequency,
33+
rhs.textAlignVertical) &&
3234
floatEquality(minimumFontSize, rhs.minimumFontSize) &&
3335
floatEquality(maximumFontSize, rhs.maximumFontSize) &&
3436
floatEquality(minimumFontScale, rhs.minimumFontScale);
@@ -73,7 +75,11 @@ SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const {
7375
debugStringConvertibleItem(
7476
"android_hyphenationFrequency",
7577
android_hyphenationFrequency,
76-
paragraphAttributes.android_hyphenationFrequency)};
78+
paragraphAttributes.android_hyphenationFrequency),
79+
debugStringConvertibleItem(
80+
"textAlignVertical",
81+
textAlignVertical,
82+
paragraphAttributes.textAlignVertical)};
7783
}
7884
#endif
7985

packages/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class ParagraphAttributes : public DebugStringConvertible {
7676
*/
7777
Float minimumFontScale{std::numeric_limits<Float>::quiet_NaN()};
7878

79+
/*
80+
* The vertical alignment of the text, causing the glyphs to be vertically
81+
* aligned in its container.
82+
*/
83+
std::optional<TextAlignmentVertical> textAlignVertical{};
84+
7985
bool operator==(const ParagraphAttributes&) const;
8086
bool operator!=(const ParagraphAttributes&) const;
8187

@@ -103,7 +109,8 @@ struct hash<facebook::react::ParagraphAttributes> {
103109
attributes.maximumFontSize,
104110
attributes.includeFontPadding,
105111
attributes.android_hyphenationFrequency,
106-
attributes.minimumFontScale);
112+
attributes.minimumFontScale,
113+
attributes.textAlignVertical);
107114
}
108115
};
109116
} // namespace std

packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ void TextAttributes::apply(TextAttributes textAttributes) {
114114
? textAttributes.accessibilityRole
115115
: accessibilityRole;
116116
role = textAttributes.role.has_value() ? textAttributes.role : role;
117-
118-
textAlignVertical = textAttributes.textAlignVertical.has_value()
119-
? textAttributes.textAlignVertical
120-
: textAlignVertical;
121117
}
122118

123119
#pragma mark - Operators
@@ -133,7 +129,6 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
133129
allowFontScaling,
134130
dynamicTypeRamp,
135131
alignment,
136-
textAlignVertical,
137132
baseWritingDirection,
138133
lineBreakStrategy,
139134
textDecorationColor,
@@ -146,8 +141,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
146141
layoutDirection,
147142
accessibilityRole,
148143
role,
149-
textTransform,
150-
textAlignVertical) ==
144+
textTransform) ==
151145
std::tie(
152146
rhs.foregroundColor,
153147
rhs.backgroundColor,
@@ -158,7 +152,6 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
158152
rhs.allowFontScaling,
159153
rhs.dynamicTypeRamp,
160154
rhs.alignment,
161-
rhs.textAlignVertical,
162155
rhs.baseWritingDirection,
163156
rhs.lineBreakStrategy,
164157
rhs.textDecorationColor,
@@ -171,8 +164,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
171164
rhs.layoutDirection,
172165
rhs.accessibilityRole,
173166
rhs.role,
174-
rhs.textTransform,
175-
rhs.textAlignVertical) &&
167+
rhs.textTransform) &&
176168
floatEquality(maxFontSizeMultiplier, rhs.maxFontSizeMultiplier) &&
177169
floatEquality(opacity, rhs.opacity) &&
178170
floatEquality(fontSize, rhs.fontSize) &&
@@ -289,11 +281,6 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {
289281
accessibilityRole,
290282
textAttributes.accessibilityRole),
291283
debugStringConvertibleItem("role", role, textAttributes.role),
292-
293-
debugStringConvertibleItem(
294-
"textAlignVertical",
295-
textAlignVertical,
296-
textAttributes.textAlignVertical),
297284
};
298285
}
299286
#endif

packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ class TextAttributes : public DebugStringConvertible {
8686
std::optional<AccessibilityRole> accessibilityRole{};
8787
std::optional<Role> role{};
8888

89-
std::optional<TextAlignmentVertical> textAlignVertical{};
90-
9189
#pragma mark - Operations
9290

9391
void apply(TextAttributes textAttributes);
@@ -127,7 +125,6 @@ struct hash<facebook::react::TextAttributes> {
127125
textAttributes.textTransform,
128126
textAttributes.lineHeight,
129127
textAttributes.alignment,
130-
textAttributes.textAlignVertical,
131128
textAttributes.baseWritingDirection,
132129
textAttributes.lineBreakStrategy,
133130
textAttributes.lineBreakMode,
@@ -141,8 +138,7 @@ struct hash<facebook::react::TextAttributes> {
141138
textAttributes.isPressable,
142139
textAttributes.layoutDirection,
143140
textAttributes.accessibilityRole,
144-
textAttributes.role,
145-
textAttributes.textAlignVertical);
141+
textAttributes.role);
146142
}
147143
};
148144
} // namespace std

packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <react/renderer/core/conversions.h>
2222
#include <react/renderer/core/graphicsConversions.h>
2323
#include <react/renderer/core/propsConversions.h>
24-
#include <cmath>
2524
#include <unordered_map>
2625

2726
#ifdef RN_SERIALIZABLE_STATE
@@ -978,6 +977,12 @@ inline ParagraphAttributes convertRawProp(
978977
"android_hyphenationFrequency",
979978
sourceParagraphAttributes.android_hyphenationFrequency,
980979
defaultParagraphAttributes.android_hyphenationFrequency);
980+
paragraphAttributes.textAlignVertical = convertRawProp(
981+
context,
982+
rawProps,
983+
"textAlignVertical",
984+
sourceParagraphAttributes.textAlignVertical,
985+
defaultParagraphAttributes.textAlignVertical);
981986

982987
return paragraphAttributes;
983988
}
@@ -1060,6 +1065,7 @@ constexpr static MapBuffer::Key PA_KEY_INCLUDE_FONT_PADDING = 4;
10601065
constexpr static MapBuffer::Key PA_KEY_HYPHENATION_FREQUENCY = 5;
10611066
constexpr static MapBuffer::Key PA_KEY_MINIMUM_FONT_SIZE = 6;
10621067
constexpr static MapBuffer::Key PA_KEY_MAXIMUM_FONT_SIZE = 7;
1068+
constexpr static MapBuffer::Key PA_KEY_TEXT_ALIGN_VERTICAL = 8;
10631069

10641070
inline MapBuffer toMapBuffer(const ParagraphAttributes& paragraphAttributes) {
10651071
auto builder = MapBufferBuilder();
@@ -1077,6 +1083,11 @@ inline MapBuffer toMapBuffer(const ParagraphAttributes& paragraphAttributes) {
10771083
builder.putString(
10781084
PA_KEY_HYPHENATION_FREQUENCY,
10791085
toString(paragraphAttributes.android_hyphenationFrequency));
1086+
if (paragraphAttributes.textAlignVertical.has_value()) {
1087+
builder.putString(
1088+
PA_KEY_TEXT_ALIGN_VERTICAL,
1089+
toString(*paragraphAttributes.textAlignVertical));
1090+
}
10801091
builder.putDouble(
10811092
PA_KEY_MINIMUM_FONT_SIZE, paragraphAttributes.minimumFontSize);
10821093
builder.putDouble(
@@ -1220,10 +1231,6 @@ inline MapBuffer toMapBuffer(const TextAttributes& textAttributes) {
12201231
if (textAttributes.role.has_value()) {
12211232
builder.putInt(TA_KEY_ROLE, static_cast<int32_t>(*textAttributes.role));
12221233
}
1223-
if (textAttributes.textAlignVertical.has_value()) {
1224-
builder.putString(
1225-
TA_KEY_ALIGNMENT_VERTICAL, toString(*textAttributes.textAlignVertical));
1226-
}
12271234
return builder.build();
12281235
}
12291236

packages/react-native/ReactCommon/react/renderer/components/text/BaseTextProps.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ static TextAttributes convertRawProp(
9898
"textTransform",
9999
sourceTextAttributes.textTransform,
100100
defaultTextAttributes.textTransform);
101-
textAttributes.textAlignVertical = convertRawProp(
102-
context,
103-
rawProps,
104-
"textAlignVertical",
105-
sourceTextAttributes.textAlignVertical,
106-
defaultTextAttributes.textAlignVertical);
107101

108102
// Paragraph
109103
textAttributes.lineHeight = convertRawProp(
@@ -287,12 +281,6 @@ void BaseTextProps::setProp(
287281
defaults, value, textAttributes, lineHeight, "lineHeight");
288282
REBUILD_FIELD_SWITCH_CASE(
289283
defaults, value, textAttributes, alignment, "textAlign");
290-
REBUILD_FIELD_SWITCH_CASE(
291-
defaults,
292-
value,
293-
textAttributes,
294-
textAlignVertical,
295-
"textAlignVertical");
296284
REBUILD_FIELD_SWITCH_CASE(
297285
defaults,
298286
value,
@@ -439,13 +427,6 @@ void BaseTextProps::appendTextAttributesProps(
439427
: nullptr;
440428
}
441429

442-
if (textAttributes.textAlignVertical !=
443-
oldProps->textAttributes.textAlignVertical) {
444-
result["textAlignVertical"] = textAttributes.textAlignVertical.has_value()
445-
? toString(textAttributes.textAlignVertical.value())
446-
: nullptr;
447-
}
448-
449430
if (!floatEquality(
450431
textAttributes.lineHeight, oldProps->textAttributes.lineHeight)) {
451432
result["lineHeight"] = textAttributes.lineHeight;

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ void ParagraphProps::setProp(
126126
paragraphAttributes,
127127
android_hyphenationFrequency,
128128
"android_hyphenationFrequency");
129+
REBUILD_FIELD_SWITCH_CASE(
130+
paDefaults,
131+
value,
132+
paragraphAttributes,
133+
textAlignVertical,
134+
"textAlignVertical");
129135
}
130136

131137
switch (hash) {
@@ -219,6 +225,14 @@ folly::dynamic ParagraphProps::getDiffProps(const Props* prevProps) const {
219225
toString(paragraphAttributes.android_hyphenationFrequency);
220226
}
221227

228+
if (paragraphAttributes.textAlignVertical !=
229+
oldProps->paragraphAttributes.textAlignVertical) {
230+
result["textAlignVertical"] =
231+
paragraphAttributes.textAlignVertical.has_value()
232+
? toString(paragraphAttributes.textAlignVertical.value())
233+
: nullptr;
234+
}
235+
222236
if (isSelectable != oldProps->isSelectable) {
223237
result["selectable"] = isSelectable;
224238
}

packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ void BaseTextInputProps::setProp(
201201
paragraphAttributes,
202202
android_hyphenationFrequency,
203203
"android_hyphenationFrequency");
204+
REBUILD_FIELD_SWITCH_CASE(
205+
paDefaults,
206+
value,
207+
paragraphAttributes,
208+
textAlignVertical,
209+
"textAlignVertical");
204210
}
205211

206212
switch (hash) {

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,16 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
425425
toString(paragraphAttributes.android_hyphenationFrequency);
426426
}
427427

428+
if (paragraphAttributes.textAlignVertical !=
429+
oldProps->paragraphAttributes.textAlignVertical) {
430+
if (!paragraphAttributes.textAlignVertical.has_value()) {
431+
result["textAlignVertical"] = nullptr;
432+
} else {
433+
result["textAlignVertical"] =
434+
toString(*paragraphAttributes.textAlignVertical);
435+
}
436+
}
437+
428438
// Base text input props
429439
if (defaultValue != oldProps->defaultValue) {
430440
result["defaultValue"] = defaultValue;

0 commit comments

Comments
 (0)