Skip to content

Commit 7b82a10

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Fixup focusability logic of PreparedLayoutTextView (#51508)
Summary: For now, we are opting to not auto-focus `PreparedLayoutTextViews` if they have links. The reason being this would not work well with Text nested in a View which is also accessible. If that Text had links, and was set to focusable, then TalkBack would individually focus that Text, which users may not want. So this diff removes that link detection, and fixes up accessibility in general. Since this isn't a TextView, we need to explicitly set the `text` on the `AccessibilityNodeInfo` object in the delegate so TalkBack know what to annouce. In the future we aim to bring back auto-focusing with links, but only if a screen reader is not on, so that keyboard users can benefit from this. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D75103779
1 parent 0f73a7a commit 7b82a10

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/PreparedLayoutTextView.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ internal class PreparedLayoutTextView(context: Context) : ViewGroup(context) {
5252

5353
clickableSpans = value?.text?.let { filterClickableSpans(it) } ?: emptyList()
5454

55-
// T221698736: This and `accessible` prop can clobber each other, and ShadowTree does not
56-
// know
57-
// about this. Need to figure out desired behavior for controlling implicit focusability.
58-
isFocusable = clickableSpans.isNotEmpty()
59-
6055
field = value
6156
invalidate()
6257
}
@@ -92,7 +87,6 @@ internal class PreparedLayoutTextView(context: Context) : ViewGroup(context) {
9287
public fun recycleView(): Unit {
9388
initView()
9489
BackgroundStyleApplicator.reset(this)
95-
isFocusable = false
9690
overflow = Overflow.HIDDEN
9791
}
9892

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextViewAccessibilityDelegate.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ internal class ReactTextViewAccessibilityDelegate : ReactAccessibilityDelegate {
174174
}
175175
}
176176

177+
override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfoCompat) {
178+
super.onInitializeAccessibilityNodeInfo(host, info)
179+
// PreparedLayoutTextView isn't actually a TextView, so we need to teach it about its text that
180+
// it is holding so TalkBack knows what to announce when focusing it.
181+
if (host is PreparedLayoutTextView) {
182+
info.text = host.text
183+
}
184+
}
185+
177186
@Suppress("DEPRECATION")
178187
override fun onPopulateNodeForVirtualView(virtualViewId: Int, node: AccessibilityNodeInfoCompat) {
179188
// If we get an invalid virtualViewId for some reason (which is known to happen in API 19 and

0 commit comments

Comments
 (0)