From f3847eeec2679450fcb4fe52e351b9a9c3b0d2a6 Mon Sep 17 00:00:00 2001 From: fabriziobertoglio1987 Date: Mon, 19 Sep 2022 20:38:29 -0700 Subject: [PATCH] Text with onPress or onLongPress handler is not accessible with TalkBack (#34284) Summary: >Finally, the last catch relates to why these views are considered focusable. We've been working with the assumption that they are only focusable because accessible="true", but this is not the only property that can make a view focusable on Android. Android also makes all elements with onClick listeners or onLongPress listeners focusable Adding onPress handler to a Text Component does not call setClickable(true) ([test case](https://github.com/facebook/react-native/issues/30851#issuecomment-1194957300)) https://github.com/facebook/react-native/issues/30851#issuecomment-1196297746 Pressable, TouchableOpacity, Switch, TextInput, and TouchableNativeFeedback are focusable/accessible by default without an onPress handler or accessible prop. ```jsx ``` The TouchableOpacity is accessible ```jsx ``` The TouchableOpacity is not accessible ```jsx console.log('pressed')} /> ``` The TouchableOpacity is accessible. https://github.com/facebook/react-native/blob/a70354df12ef71aec08583cca4f1fed5fb77d874/Libraries/Components/Touchable/TouchableOpacity.js#L249-L251 This and other PRs fixes https://github.com/facebook/react-native/issues/30851 ## Changelog [Android] [Fixed] - Text with onPress or onLongPress handler is not accessible with TalkBack Pull Request resolved: https://github.com/facebook/react-native/pull/34284 Test Plan: main branch https://github.com/facebook/react-native/issues/30
pr branch

Reviewed By: cipolleschi Differential Revision: D39179107 Pulled By: blavalla fbshipit-source-id: 3301fb2b799f233660e3e08f6a87dad294ddbcd8 --- Libraries/Text/Text.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Libraries/Text/Text.js b/Libraries/Text/Text.js index 8539f92c422d1f..1961c7b3595a8a 100644 --- a/Libraries/Text/Text.js +++ b/Libraries/Text/Text.js @@ -207,6 +207,9 @@ const Text: React.AbstractComponent< flattenedStyle.fontWeight = flattenedStyle?.fontWeight.toString(); } + const _hasOnPressOrOnLongPress = + props.onPress != null || props.onLongPress != null; + return hasTextAncestor ? (