Skip to content

Commit 8fb1bb8

Browse files
ZHUANGPPfacebook-github-bot
authored andcommitted
Add accessibilityRole to TextAttributes
Summary: Changelog: [Internal] - The accessibilityRole will be used to specially distinguish normal fragments and fragments with embedded link, which is helpful when building accessibilityElement. According to this document: https://reactnative.dev/docs/accessibility, the accessibilityRole is a common accessibility props that could be inherited, and this is why I add accessibilityRole to the TextAttributes. Reviewed By: sammy-SC Differential Revision: D22249140 fbshipit-source-id: 408b4415bf44539d8671d3d98f1ec06f8035baf6
1 parent 40f37b9 commit 8fb1bb8

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

ReactCommon/fabric/attributedstring/TextAttributes.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ void TextAttributes::apply(TextAttributes textAttributes) {
9494
layoutDirection = textAttributes.layoutDirection.hasValue()
9595
? textAttributes.layoutDirection
9696
: layoutDirection;
97+
accessibilityRole = !textAttributes.accessibilityRole.empty()
98+
? textAttributes.accessibilityRole
99+
: accessibilityRole;
97100
}
98101

99102
#pragma mark - Operators
@@ -116,7 +119,8 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
116119
textShadowOffset,
117120
textShadowColor,
118121
isHighlighted,
119-
layoutDirection) ==
122+
layoutDirection,
123+
accessibilityRole) ==
120124
std::tie(
121125
rhs.foregroundColor,
122126
rhs.backgroundColor,
@@ -134,7 +138,8 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
134138
rhs.textShadowOffset,
135139
rhs.textShadowColor,
136140
rhs.isHighlighted,
137-
rhs.layoutDirection) &&
141+
rhs.layoutDirection,
142+
rhs.accessibilityRole) &&
138143
floatEquality(opacity, rhs.opacity) &&
139144
floatEquality(fontSize, rhs.fontSize) &&
140145
floatEquality(fontSizeMultiplier, rhs.fontSizeMultiplier) &&
@@ -202,6 +207,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {
202207
// Special
203208
debugStringConvertibleItem("isHighlighted", isHighlighted),
204209
debugStringConvertibleItem("layoutDirection", layoutDirection),
210+
debugStringConvertibleItem("accessibilityRole", accessibilityRole),
205211
};
206212
}
207213
#endif

ReactCommon/fabric/attributedstring/TextAttributes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class TextAttributes : public DebugStringConvertible {
7777
// Currently, it is intentionally *not* being set as part of BaseTextProps
7878
// construction.
7979
folly::Optional<LayoutDirection> layoutDirection{};
80+
std::string accessibilityRole{""};
8081

8182
#pragma mark - Operations
8283

@@ -127,7 +128,8 @@ struct hash<facebook::react::TextAttributes> {
127128
textAttributes.textShadowRadius,
128129
textAttributes.textShadowColor,
129130
textAttributes.isHighlighted,
130-
textAttributes.layoutDirection);
131+
textAttributes.layoutDirection,
132+
textAttributes.accessibilityRole);
131133
}
132134
};
133135
} // namespace std

ReactCommon/fabric/components/text/basetext/BaseTextProps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ static TextAttributes convertRawProp(
143143
sourceTextAttributes.isHighlighted,
144144
defaultTextAttributes.isHighlighted);
145145

146+
textAttributes.accessibilityRole = convertRawProp(
147+
rawProps,
148+
"accessibilityRole",
149+
sourceTextAttributes.accessibilityRole,
150+
defaultTextAttributes.accessibilityRole);
151+
146152
return textAttributes;
147153
}
148154

0 commit comments

Comments
 (0)