Description
new branch https://github.com/fabriziobertoglio1987/react-native/tree/independent-links-rebased
old branch https://github.com/fabriziobertoglio1987/react-native/tree/independent-links
facebook/react-native@b352e2d
Right now nested Text components are not accessible on Android. This is because we only create a native
ReactTextView
for the parent component; the styling and touch handling for the child component are handled using spans. In order for TalkBack to announce the link, we need to linkify the text using aClickableSpan
.
This diff addsReactClickableSpan
, whichTextLayoutManager
uses to linkify a span of text when its corresponding React component hasaccessibilityRole="link"
. For example:
<Text>
A paragraph with some
<Text accessible={true} accessibilityRole="link" onPress={onPress} onClick={onClick}>links</Text>
surrounded by other text.
</Text>
With this diff, the child Text component will be announced by TalkBack ('links available') and exposed as an option in the context menu. Clicking on the link in the context menu fires the Text component's onClick, which we're explicitly forwarding to onPress in Text.js (for now - ideally this would probably use a separate event, but that would involve wiring it up in the renderer as well).
Summary:
This follows up on D23553222 (facebook/react-native@b352e2d), which made links functional by using Talkback's Links menu. We don't often use this as the sole access point for links due to it being more difficult for users to navigate to, and easy for users to miss if they don't listen to the entire description, including the hint text that announces that links are available.
The PR allows TalkBack to move the focus directly on the nested Text link (accessibilityRole="link"
).
The nested link becomes the next focusable element after the that contains it.
If there are multiple links within a single text element, they will each be focusable in order after the main element.
Related facebook/react-native#30375 https://developer.android.com/reference/android/text/style/ClickableSpan https://developer.android.com/reference/androidx/core/view/ViewCompat#enableAccessibleClickableSpanSupport(android.view.View) https://stackoverflow.com/a/62222068/7295772 facebook/react-native#32004