Skip to content

Commit

Permalink
Adds isPressable native prop to TextAttributes (#40871)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rozele authored and facebook-github-bot committed Oct 12, 2023
1 parent 14eb4c9 commit eef823b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ void TextAttributes::apply(TextAttributes textAttributes) {
isHighlighted = textAttributes.isHighlighted.has_value()
? textAttributes.isHighlighted
: isHighlighted;
// TextAttributes "inherits" the isPressable value from ancestors, so this
// only applies the current node's value for isPressable if it is truthy.
isPressable =
textAttributes.isPressable.has_value() && *textAttributes.isPressable
? textAttributes.isPressable
: isPressable;
layoutDirection = textAttributes.layoutDirection.has_value()
? textAttributes.layoutDirection
: layoutDirection;
Expand Down Expand Up @@ -125,6 +131,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
textShadowOffset,
textShadowColor,
isHighlighted,
isPressable,
layoutDirection,
accessibilityRole,
role,
Expand All @@ -147,6 +154,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
rhs.textShadowOffset,
rhs.textShadowColor,
rhs.isHighlighted,
rhs.isPressable,
rhs.layoutDirection,
rhs.accessibilityRole,
rhs.role,
Expand Down Expand Up @@ -216,6 +224,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {

// Special
debugStringConvertibleItem("isHighlighted", isHighlighted),
debugStringConvertibleItem("isPressable", isPressable),
debugStringConvertibleItem("layoutDirection", layoutDirection),
debugStringConvertibleItem("accessibilityRole", accessibilityRole),
debugStringConvertibleItem("role", role),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class TextAttributes : public DebugStringConvertible {

// Special
std::optional<bool> isHighlighted{};
std::optional<bool> isPressable{};

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

0 comments on commit eef823b

Please sign in to comment.