Skip to content

Commit 0b70b38

Browse files
fabOnReactfacebook-github-bot
authored andcommitted
Re-implement accessibilityHint on Android to use AccessibililltyNodeInfo#setToolTipText instead of contentDescription (facebook#34427)
Summary: facebook#31056 (comment) >Re-implement accessibilityHint on Android so that rather that concatenate into the contentDescription, it sets the toolTipText property on the AccessibilityNodeInfo (not on the view). This is the closest analog to iOS's hint that Android has, as the text is announced after the contentDescription rather than part of it. It will will not adhere to users preferences on whether they want hints disabled or not, and still has no pause before it like real hints have, but it's far closer than using the contentDescription directly. fixes facebook#31056 ## Changelog [Android] [Fixed] - Re-implement accessibilityHint on Android to use AccessibililltyNodeInfo#setToolTipText instead of contentDescription Pull Request resolved: facebook#34427 Test Plan: https://user-images.githubusercontent.com/24992535/184837154-5c65dbf1-1031-4d56-ac1e-066af7e08edc.mp4 Reviewed By: christophpurrer Differential Revision: D38982158 Pulled By: cipolleschi fbshipit-source-id: 7a616e6df9f83bd21ca02cc26b5918986a1d64f8
1 parent 04ee52b commit 0b70b38

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilitySta
317317
private void updateViewContentDescription(@NonNull T view) {
318318
final String accessibilityLabel = (String) view.getTag(R.id.accessibility_label);
319319
final ReadableMap accessibilityState = (ReadableMap) view.getTag(R.id.accessibility_state);
320-
final String accessibilityHint = (String) view.getTag(R.id.accessibility_hint);
321320
final List<String> contentDescription = new ArrayList<>();
322321
final ReadableMap accessibilityValue = (ReadableMap) view.getTag(R.id.accessibility_value);
323322
if (accessibilityLabel != null) {
@@ -352,9 +351,6 @@ private void updateViewContentDescription(@NonNull T view) {
352351
contentDescription.add(text.asString());
353352
}
354353
}
355-
if (accessibilityHint != null) {
356-
contentDescription.add(accessibilityHint);
357-
}
358354
if (contentDescription.size() > 0) {
359355
view.setContentDescription(TextUtils.join(", ", contentDescription));
360356
}

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactAccessibilityDelegate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,15 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
225225
super.onInitializeAccessibilityNodeInfo(host, info);
226226
final AccessibilityRole accessibilityRole =
227227
(AccessibilityRole) host.getTag(R.id.accessibility_role);
228+
final String accessibilityHint = (String) host.getTag(R.id.accessibility_hint);
228229
if (accessibilityRole != null) {
229230
setRole(info, accessibilityRole, host.getContext());
230231
}
231232

233+
if (accessibilityHint != null) {
234+
info.setTooltipText(accessibilityHint);
235+
}
236+
232237
final Object accessibilityLabelledBy = host.getTag(R.id.labelled_by);
233238
if (accessibilityLabelledBy != null) {
234239
mAccessibilityLabelledBy =

0 commit comments

Comments
 (0)