Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds isPressable native prop to TextAttributes
Browse files Browse the repository at this point in the history
Summary:
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
rozele authored and facebook-github-bot committed Oct 12, 2023
1 parent 11d9b9c commit 79e1894
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
@@ -125,6 +131,7 @@ bool TextAttributes::operator==(const TextAttributes& rhs) const {
textShadowOffset,
textShadowColor,
isHighlighted,
isPressable,
layoutDirection,
accessibilityRole,
role,
@@ -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,
@@ -216,6 +224,7 @@ SharedDebugStringConvertibleList TextAttributes::getDebugProps() const {

// Special
debugStringConvertibleItem("isHighlighted", isHighlighted),
debugStringConvertibleItem("isPressable", isPressable),
debugStringConvertibleItem("layoutDirection", layoutDirection),
debugStringConvertibleItem("accessibilityRole", accessibilityRole),
debugStringConvertibleItem("role", role),
Original file line number Diff line number Diff line change
@@ -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.
@@ -132,6 +133,7 @@ struct hash<facebook::react::TextAttributes> {
textAttributes.textShadowRadius,
textAttributes.textShadowColor,
textAttributes.isHighlighted,
textAttributes.isPressable,
textAttributes.layoutDirection,
textAttributes.accessibilityRole,
textAttributes.role);

0 comments on commit 79e1894

Please sign in to comment.