Skip to content

Commit eef823b

Browse files
rozelefacebook-github-bot
authored andcommitted
Adds isPressable native prop to TextAttributes (#40871)
Summary: Pull Request resolved: #40871 If we pass isPressable to the native props object (via TextAttributes), we can use this information to bypass hit testing on some spans. This is rather important on some platforms where pointerenter/pointerleave/ mousemove events force frequent hit testing. ## Changelog: [General] [Internal] Reviewed By: javache Differential Revision: D50228473 fbshipit-source-id: 4fce85f4b18617fbe10d3c804e943484bf990664
1 parent 14eb4c9 commit eef823b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ void TextAttributes::apply(TextAttributes textAttributes) {
9595
isHighlighted = textAttributes.isHighlighted.has_value()
9696
? textAttributes.isHighlighted
9797
: isHighlighted;
98+
// TextAttributes "inherits" the isPressable value from ancestors, so this
99+
// only applies the current node's value for isPressable if it is truthy.
100+
isPressable =
101+
textAttributes.isPressable.has_value() && *textAttributes.isPressable
102+
? textAttributes.isPressable
103+
: isPressable;
98104
layoutDirection = textAttributes.layoutDirection.has_value()
99105
? textAttributes.layoutDirection
100106
: layoutDirection;
@@ -125,6 +131,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
125131
textShadowOffset,
126132
textShadowColor,
127133
isHighlighted,
134+
isPressable,
128135
layoutDirection,
129136
accessibilityRole,
130137
role,
@@ -147,6 +154,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
147154
rhs.textShadowOffset,
148155
rhs.textShadowColor,
149156
rhs.isHighlighted,
157+
rhs.isPressable,
150158
rhs.layoutDirection,
151159
rhs.accessibilityRole,
152160
rhs.role,
@@ -216,6 +224,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {
216224

217225
// Special
218226
debugStringConvertibleItem("isHighlighted", isHighlighted),
227+
debugStringConvertibleItem("isPressable", isPressable),
219228
debugStringConvertibleItem("layoutDirection", layoutDirection),
220229
debugStringConvertibleItem("accessibilityRole", accessibilityRole),
221230
debugStringConvertibleItem("role", role),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class TextAttributes : public DebugStringConvertible {
7474

7575
// Special
7676
std::optional<bool> isHighlighted{};
77+
std::optional<bool> isPressable{};
7778

7879
// TODO T59221129: document where this value comes from and how it is set.
7980
// It's not clear if this is being used properly, or if it's being set at all.
@@ -132,6 +133,7 @@ struct hash<facebook::react::TextAttributes> {
132133
textAttributes.textShadowRadius,
133134
textAttributes.textShadowColor,
134135
textAttributes.isHighlighted,
136+
textAttributes.isPressable,
135137
textAttributes.layoutDirection,
136138
textAttributes.accessibilityRole,
137139
textAttributes.role);

0 commit comments

Comments
 (0)