Allow link role to be announced if its set on entire text in nested text (#50236)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50236

If you do something like

```
<Text>
  <Text accessibilityRole="link">
    I am a link!
  </Text>
</Text>
```

we do not announce "link".

We skip any sort of spans on the entire text on iOS, which I feel like is not ideal. This case would be common enough, and users may not have access to the top level text component.

Note Android correctly handles this already.

Changelog: [iOS] [Fixed] - Correctly announce "link" on nested text if its the entire text element

Reviewed By: javache

Differential Revision: D71770798

fbshipit-source-id: 4a0781a95cb27cf244d6d2b1d1df8a0451964301
This commit is contained in:
Joe Vilches
2025-03-25 12:56:47 -07:00
committed by Facebook GitHub Bot
parent 0437c4071b
commit bffb414291
@@ -81,11 +81,16 @@ using namespace facebook::react;
enumerateAttribute:RCTTextAttributesAccessibilityRoleAttributeName
frame:_frame
usingBlock:^(CGRect fragmentRect, NSString *_Nonnull fragmentText, NSString *value) {
if ([fragmentText isEqualToString:firstElement.accessibilityLabel]) {
// The fragment is the entire paragraph. This is handled as `firstElement`.
if ((![value isEqualToString:@"button"] && ![value isEqualToString:@"link"])) {
return;
}
if ((![value isEqualToString:@"button"] && ![value isEqualToString:@"link"])) {
if ([fragmentText isEqualToString:firstElement.accessibilityLabel]) {
if ([value isEqualToString:@"link"]) {
firstElement.accessibilityTraits |= UIAccessibilityTraitLink;
} else if ([value isEqualToString:@"button"]) {
firstElement.accessibilityTraits |= UIAccessibilityTraitButton;
}
// The fragment is the entire paragraph. This is handled as `firstElement`.
return;
}
if ([value isEqualToString:@"button"] &&