Skip to content

Commit

Permalink
Adds isPressable prop to TextAttributes (facebook#38585)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#38585

Although we don't currently use this for iOS and Android, platforms with less performant text hit testing algorithms or input devices like a mouse may wish to only hit test text on mouse move if there are pressable inline spans.

This change adds the `isPressable` prop, which has been wired up in JS since facebook@f3bf2e4 to Fabric TextAttributes.

Reviewed By: christophpurrer

Differential Revision: D47722096

fbshipit-source-id: 325897f81552a733af6cb98c7f382e3f33449c94
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 25, 2023
1 parent e64756a commit e6b57b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ void TextAttributes::apply(TextAttributes textAttributes) {
isHighlighted = textAttributes.isHighlighted.has_value()
? textAttributes.isHighlighted
: isHighlighted;

// If an ancestor text component has set `isPressable`, this text component
// should not reset `isPressable` to false.
isPressable =
textAttributes.isPressable.has_value() && *textAttributes.isPressable
? textAttributes.isPressable
: isPressable;

layoutDirection = textAttributes.layoutDirection.has_value()
? textAttributes.layoutDirection
: layoutDirection;
Expand Down Expand Up @@ -125,6 +133,7 @@ bool TextAttributes::operator==(const TextAttributes &rhs) const {
textShadowOffset,
textShadowColor,
isHighlighted,
isPressable,
layoutDirection,
accessibilityRole,
role,
Expand All @@ -147,6 +156,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 +226,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
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ static TextAttributes convertRawProp(
"isHighlighted",
sourceTextAttributes.isHighlighted,
defaultTextAttributes.isHighlighted);
textAttributes.isPressable = convertRawProp(
context,
rawProps,
"isPressable",
sourceTextAttributes.isPressable,
defaultTextAttributes.isPressable);

// In general, we want this class to access props in the same order
// that ViewProps accesses them in, so that RawPropParser can optimize
Expand Down Expand Up @@ -294,6 +300,8 @@ void BaseTextProps::setProp(
defaults, value, textAttributes, textShadowColor, "textShadowColor");
REBUILD_FIELD_SWITCH_CASE(
defaults, value, textAttributes, isHighlighted, "isHighlighted");
REBUILD_FIELD_SWITCH_CASE(
defaults, value, textAttributes, isPressable, "isPressable");
REBUILD_FIELD_SWITCH_CASE(
defaults,
value,
Expand Down

0 comments on commit e6b57b2

Please sign in to comment.