Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: a11y crash when an accessible link is ellipsized away #37050

Closed
wants to merge 1 commit into from

Conversation

dhleong
Copy link
Contributor

@dhleong dhleong commented Apr 22, 2023

Summary:

If an accessible link is ellipsized out of being rendered, the AccessibilityDelegate will still attempt to populate an accessibility node for it; doing so results in an invalid request to a TextLayout API, however, causing a crash. This crash occurs as soon as the element is rendered, so long as a Screen Reader (or app using similar a11y APIs) is enabled. This change uses a technique similar to those existing to make the node "blank" in such cases, so Talkback can filter it out—and, more importantly, not crash.

Changelog:

[Android] [Fixed] - Fix links hidden via ellipsis crashing screen readers

Test Plan:

  • Added a block to the "Accessibility Android APIs" page in the rn-tester app. Without the changes to ReactAccessibilityDelegate, this component crashes the app; with the changes, the component renders without problem.
  • You can also see the crash "in the wild" using this Expo Snack that I put together when trying to isolate this issue.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 22, 2023
@analysis-bot
Copy link

analysis-bot commented Apr 22, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,623,046 +242
android hermes armeabi-v7a 7,936,389 +231
android hermes x86 9,109,684 +231
android hermes x86_64 8,964,706 +232
android jsc arm64-v8a 9,187,196 +142
android jsc armeabi-v7a 8,378,077 +147
android jsc x86 9,245,254 +143
android jsc x86_64 9,503,921 +147

Base commit: 01d80c1
Branch: main

@dhleong dhleong force-pushed the dhleong/ellipsized-a11y-nodes branch from b5ea6cb to eb5d823 Compare April 22, 2023 18:37
Comment on lines +642 to +646
if (bounds == null) {
node.setContentDescription("");
node.setBoundsInParent(new Rect(0, 0, 1, 1));
return;
}
Copy link
Contributor

@Pranav-yadav Pranav-yadav Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why we're not adding the "action" AccessibilityNodeInfoCompat.ACTION_CLICK as well; here?

Suggested change
if (bounds == null) {
node.setContentDescription("");
node.setBoundsInParent(new Rect(0, 0, 1, 1));
return;
}
if (bounds == null) {
node.setContentDescription("");
node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
node.setBoundsInParent(new Rect(0, 0, 1, 1));
return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link has been ellipsized away so it's not visible (IE would not actually be tappable). The two checks above don't include it when there isn't a valid link, etc; that seemed to apply in this case, so I mirrored that approach.

@Pranav-yadav
Copy link
Contributor

@NickGerleman seems like no one reviewed this PR?

@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jun 4, 2023
@facebook-github-bot
Copy link
Contributor

@NickGerleman merged this pull request in d54f486.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants