From bffb414291cfbd3d6e3e51448dd68b7bddddf658 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Tue, 25 Mar 2025 12:56:47 -0700 Subject: [PATCH] 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 ``` I am a link! ``` 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 --- .../RCTParagraphComponentAccessibilityProvider.mm | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm index b3676564857..31f7ed37837 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm @@ -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"] &&