Skip to content

Commit

Permalink
Re-implement accessibilityHint on Android to use AccessibililltyNodeI…
Browse files Browse the repository at this point in the history
…nfo#setToolTipText instead of contentDescription (#34427)

Summary:
#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 #31056

## Changelog

[Android] [Fixed] - Re-implement accessibilityHint on Android to use AccessibililltyNodeInfo#setToolTipText instead of contentDescription

Pull Request resolved: #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
  • Loading branch information
fabOnReact authored and facebook-github-bot committed Aug 25, 2022
1 parent 04ee52b commit 0b70b38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilitySta
private void updateViewContentDescription(@NonNull T view) {
final String accessibilityLabel = (String) view.getTag(R.id.accessibility_label);
final ReadableMap accessibilityState = (ReadableMap) view.getTag(R.id.accessibility_state);
final String accessibilityHint = (String) view.getTag(R.id.accessibility_hint);
final List<String> contentDescription = new ArrayList<>();
final ReadableMap accessibilityValue = (ReadableMap) view.getTag(R.id.accessibility_value);
if (accessibilityLabel != null) {
Expand Down Expand Up @@ -352,9 +351,6 @@ private void updateViewContentDescription(@NonNull T view) {
contentDescription.add(text.asString());
}
}
if (accessibilityHint != null) {
contentDescription.add(accessibilityHint);
}
if (contentDescription.size() > 0) {
view.setContentDescription(TextUtils.join(", ", contentDescription));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,15 @@ public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCo
super.onInitializeAccessibilityNodeInfo(host, info);
final AccessibilityRole accessibilityRole =
(AccessibilityRole) host.getTag(R.id.accessibility_role);
final String accessibilityHint = (String) host.getTag(R.id.accessibility_hint);
if (accessibilityRole != null) {
setRole(info, accessibilityRole, host.getContext());
}

if (accessibilityHint != null) {
info.setTooltipText(accessibilityHint);
}

final Object accessibilityLabelledBy = host.getTag(R.id.labelled_by);
if (accessibilityLabelledBy != null) {
mAccessibilityLabelledBy =
Expand Down

0 comments on commit 0b70b38

Please sign in to comment.