Skip to content

Commit 6716e0f

Browse files
committed
cpp TextAttributes settings crash RNTester
1 parent c683779 commit 6716e0f

10 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.util.LayoutDirection;
1414
import android.view.Gravity;
1515
import androidx.annotation.Nullable;
16+
import com.facebook.common.logging.FLog;
1617
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
1718
import com.facebook.react.bridge.ReadableArray;
1819
import com.facebook.react.bridge.ReadableMap;
@@ -53,6 +54,7 @@ public class TextAttributeProps {
5354
public static final short TA_KEY_IS_HIGHLIGHTED = 20;
5455
public static final short TA_KEY_LAYOUT_DIRECTION = 21;
5556
public static final short TA_KEY_ACCESSIBILITY_ROLE = 22;
57+
public static final short TA_KEY_VERTICAL_ALIGN = 23;
5658

5759
public static final int UNSET = -1;
5860

@@ -99,6 +101,7 @@ public class TextAttributeProps {
99101
protected boolean mIsUnderlineTextDecorationSet = false;
100102
protected boolean mIsLineThroughTextDecorationSet = false;
101103
protected boolean mIncludeFontPadding = true;
104+
protected String mVerticalAlign;
102105

103106
protected @Nullable ReactAccessibilityDelegate.AccessibilityRole mAccessibilityRole = null;
104107
protected boolean mIsAccessibilityRoleSet = false;
@@ -205,6 +208,9 @@ public static TextAttributeProps fromMapBuffer(MapBuffer props) {
205208
case TA_KEY_ACCESSIBILITY_ROLE:
206209
result.setAccessibilityRole(entry.getStringValue());
207210
break;
211+
case TA_KEY_VERTICAL_ALIGN:
212+
result.setVerticalAlign(entry.getStringValue());
213+
break;
208214
}
209215
}
210216

@@ -609,6 +615,13 @@ private void setAccessibilityRole(@Nullable String accessibilityRole) {
609615
}
610616
}
611617

618+
private void setVerticalAlign(@Nullable String verticalAlign) {
619+
FLog.w("React::", "verticalAlign: " + (verticalAlign));
620+
if (verticalAlign != null) {
621+
mVerticalAlign = verticalAlign;
622+
}
623+
}
624+
612625
public static int getTextBreakStrategy(@Nullable String textBreakStrategy) {
613626
int androidTextBreakStrategy = DEFAULT_BREAK_STRATEGY;
614627
if (textBreakStrategy != null) {

‎ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManagerMapBuffer.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,12 @@ private static void buildSpannableFromFragment(
140140
sb.length(),
141141
new TextInlineViewPlaceholderSpan(reactTag, (int) width, (int) height)));
142142
} else if (end >= start) {
143-
if (textAttributes.mIsAccessibilityLink) {
143+
if (textAttributes.mVerticalAlign == "super") {
144144
ops.add(new SetSpanOperation(start, end, new ReactSuperscriptSpan()));
145145
}
146+
if (textAttributes.mIsAccessibilityLink) {
147+
ops.add(new SetSpanOperation(start, end, new ReactClickableSpan(reactTag)));
148+
}
146149
if (textAttributes.mIsColorSet) {
147150
ops.add(
148151
new SetSpanOperation(

‎ReactCommon/react/renderer/attributedstring/TextAttributes.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void TextAttributes::apply(TextAttributes textAttributes) {
101101
accessibilityRole = textAttributes.accessibilityRole.has_value()
102102
? textAttributes.accessibilityRole
103103
: accessibilityRole;
104+
textVerticalAlign = !textAttributes.textVerticalAlign.empty() ? textAttributes.textVerticalAlign : textVerticalAlign;
104105
}
105106

106107
#pragma mark - Operators
@@ -126,6 +127,7 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
126127
isHighlighted,
127128
layoutDirection,
128129
accessibilityRole,
130+
textVerticalAlign,
129131
textTransform) ==
130132
std::tie(
131133
rhs.foregroundColor,
@@ -147,6 +149,7 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
147149
rhs.isHighlighted,
148150
rhs.layoutDirection,
149151
rhs.accessibilityRole,
152+
rhs.textVerticalAlign,
150153
rhs.textTransform) &&
151154
floatEquality(opacity, rhs.opacity) &&
152155
floatEquality(fontSize, rhs.fontSize) &&
@@ -215,6 +218,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {
215218
debugStringConvertibleItem("isHighlighted", isHighlighted),
216219
debugStringConvertibleItem("layoutDirection", layoutDirection),
217220
debugStringConvertibleItem("accessibilityRole", accessibilityRole),
221+
debugStringConvertibleItem("textVerticalAlign", textVerticalAlign),
218222
};
219223
}
220224
#endif

‎ReactCommon/react/renderer/attributedstring/TextAttributes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class TextAttributes : public DebugStringConvertible {
8181
// construction.
8282
std::optional<LayoutDirection> layoutDirection{};
8383
std::optional<AccessibilityRole> accessibilityRole{};
84+
std::string textVerticalAlign{""};
8485

8586
#pragma mark - Operations
8687

‎ReactCommon/react/renderer/attributedstring/conversions.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,10 @@ inline folly::dynamic toDynamic(const TextAttributes &textAttributes) {
10361036
_textAttributes(
10371037
"accessibilityRole", toString(*textAttributes.accessibilityRole));
10381038
}
1039+
if (!textAttributes.textVerticalAlign.empty()) {
1040+
_textAttributes(
1041+
"textVerticalAlign", textAttributes.textVerticalAlign);
1042+
}
10391043
return _textAttributes;
10401044
}
10411045

@@ -1110,6 +1114,7 @@ constexpr static MapBuffer::Key TA_KEY_IS_HIGHLIGHTED = 20;
11101114
constexpr static MapBuffer::Key TA_KEY_LAYOUT_DIRECTION = 21;
11111115
constexpr static MapBuffer::Key TA_KEY_ACCESSIBILITY_ROLE = 22;
11121116
constexpr static MapBuffer::Key TA_KEY_LINE_BREAK_STRATEGY = 23;
1117+
constexpr static MapBuffer::Key TA_KEY_VERTICAL_ALIGN = 24;
11131118

11141119
// constants for ParagraphAttributes serialization
11151120
constexpr static MapBuffer::Key PA_KEY_MAX_NUMBER_OF_LINES = 0;
@@ -1256,6 +1261,10 @@ inline MapBuffer toMapBuffer(const TextAttributes &textAttributes) {
12561261
builder.putString(
12571262
TA_KEY_ACCESSIBILITY_ROLE, toString(*textAttributes.accessibilityRole));
12581263
}
1264+
if (textAttributes.textVerticalAlign.empty()) {
1265+
builder.putString(
1266+
TA_KEY_VERTICAL_ALIGN, textAttributes.textVerticalAlign);
1267+
}
12591268
return builder.build();
12601269
}
12611270

‎ReactCommon/react/renderer/components/text/BaseTextProps.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ static TextAttributes convertRawProp(
196196
"backgroundColor",
197197
sourceTextAttributes.backgroundColor,
198198
defaultTextAttributes.backgroundColor);
199+
200+
textAttributes.textVerticalAlign = convertRawProp(
201+
context,
202+
rawProps,
203+
"textVerticalAlign",
204+
sourceTextAttributes.textVerticalAlign,
205+
defaultTextAttributes.textVerticalAlign);
199206

200207
return textAttributes;
201208
}
@@ -297,6 +304,8 @@ void BaseTextProps::setProp(
297304
defaults, value, textAttributes, opacity, "opacity");
298305
REBUILD_FIELD_SWITCH_CASE(
299306
defaults, value, textAttributes, backgroundColor, "backgroundColor");
307+
REBUILD_FIELD_SWITCH_CASE(
308+
defaults, value, textAttributes, backgroundColor, "textVerticalAlign");
300309
}
301310
}
302311

‎ReactCommon/react/renderer/components/view/ViewProps.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ ViewProps::ViewProps(
5151
"backgroundColor",
5252
sourceProps.backgroundColor,
5353
{})),
54+
textVerticalAlign(
55+
CoreFeatures::enablePropIteratorSetter
56+
? sourceProps.textVerticalAlign
57+
: convertRawProp(
58+
context,
59+
rawProps,
60+
"textVerticalAlign",
61+
sourceProps.textVerticalAlign,
62+
{})),
5463
borderRadii(
5564
CoreFeatures::enablePropIteratorSetter ? sourceProps.borderRadii
5665
: convertRawProp(
@@ -293,6 +302,7 @@ void ViewProps::setProp(
293302
RAW_SET_PROP_SWITCH_CASE_BASIC(opacity, (Float)1.0);
294303
RAW_SET_PROP_SWITCH_CASE_BASIC(foregroundColor, {});
295304
RAW_SET_PROP_SWITCH_CASE_BASIC(backgroundColor, {});
305+
RAW_SET_PROP_SWITCH_CASE_BASIC(textVerticalAlign, {});
296306
RAW_SET_PROP_SWITCH_CASE_BASIC(shadowColor, {});
297307
RAW_SET_PROP_SWITCH_CASE_BASIC(shadowOffset, {});
298308
RAW_SET_PROP_SWITCH_CASE_BASIC(shadowOpacity, {});

‎ReactCommon/react/renderer/components/view/ViewProps.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ViewProps : public YogaStylableProps, public AccessibilityProps {
5151
Float opacity{1.0};
5252
SharedColor foregroundColor{};
5353
SharedColor backgroundColor{};
54+
std::string textVerticalAlign{""};
5455

5556
// Borders
5657
CascadedBorderRadii borderRadii{};

‎ReactCommon/react/renderer/components/view/ViewPropsMapBuffer.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ void ViewProps::propsDiffMapBuffer(
6060
builder.putInt(VP_FG_COLOR, toAndroidRepr(newProps.foregroundColor));
6161
}
6262

63+
if (oldProps.textVerticalAlign != newProps.textVerticalAlign) {
64+
builder.putString(VP_TEXT_VERTICAL_ALIGN, newProps.textVerticalAlign);
65+
}
66+
6367
if (oldProps.borderCurves != newProps.borderCurves) {
6468
builder.putMapBuffer(
6569
VP_BORDER_CURVES, convertCascadedCorners(newProps.borderCurves));

‎ReactCommon/react/renderer/components/view/ViewPropsMapBuffer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ constexpr MapBuffer::Key VP_POINTER_OUT = 43;
4646
constexpr MapBuffer::Key VP_POINTER_OUT_CAPTURE = 44;
4747
constexpr MapBuffer::Key VP_BORDER_CURVES = 45;
4848
constexpr MapBuffer::Key VP_FG_COLOR = 46;
49+
constexpr MapBuffer::Key VP_TEXT_VERTICAL_ALIGN = 47;
4950

5051
// Yoga values
5152
constexpr MapBuffer::Key YG_BORDER_WIDTH = 100;

0 commit comments

Comments
 (0)