Uh oh!
There was an error while loading. Please reload this page.
Prevent duplicate accessibilityLabel on parent views - #31924
Prevent duplicate accessibilityLabel on parent views#31924newyankeecodeshop wants to merge 2 commits into
Conversation
Base commit: cbec66e |
Base commit: cbec66e |
newyankeecodeshop
commented
Jul 29, 2021
| static NSString *RCTRecursiveAccessibilityLabel(UIView *view) | ||
| { | ||
| NSMutableString *result = [NSMutableString stringWithString:@""]; | ||
| NSMutableString *result = [NSMutableString string]; |
At first glance, this looks fine to me. I would recommend getting out a physical device, turning on the screen reader, and testing the behavior before and after this change. (The screen reader doesn't work in the iOS simulator.) I think this PR is going to behave better than mine in that regard, but I don't know this stuff well enough to say for sure. In my case, the concerns were mainly performance related, and we mitigated it by special-casing React Native apps and bypassing RCTRecursiveAccessibilityLabel entirely. (I just now closed my PR.) (Also, FWIW, #31222 is kind of orthogonal to this, as it only improves performance without changing behavior.) |
p-sun
commented
Aug 2, 2021
Hi! Could you create a test in AccessibilityExample.js or AccessibilityIOSExample.js for this? |
newyankeecodeshop
commented
Aug 12, 2021
@p-sun is my test adequate? |
newyankeecodeshop
commented
Sep 14, 2021
Hi @p-sun is there anything I can do to help move this forward? |
p-sun
commented
Sep 14, 2021
I will take a look at this within the next three days. Thanks for waiting! |
newyankeecodeshop
commented
Oct 21, 2021
Hi @p-sun will you have a chance to review this? |
ls-erin-walker
commented
Nov 30, 2021
Is there any chance this has been reviewed? |
newyankeecodeshop
commented
Feb 1, 2022
Hi @p-sun will this get a review or should I close it? |
Summary
In testing React Native apps using Appium, the
accessibilityLabelis an important prop which provides an additional means to lookup elements in addition to thetestID. More importantly, theaccessibilityLabelprovides detail to screen readers and other accessibility helpers. React Native on iOS has custom logic (compared to Android), whereby it concatenates the accessibility labels of children. This is useful in a case such as this:The above creates the following accessibility view:
and when viewed in Appium Studio
However, if the above is in one or more views, such as:
You can get the following from XCUITest and Appium:
This happens because the parent Views are using
RCTRecursiveAccessibilityLabel()to populate the label from the child Touchable. This doesn't make sense semantically because the TouchableHighlight is an accessible element. It benefits from the concatenation to create its label from the two Text elements, but the container views are not part of that label. They should not include it.This PR should fix#21830, and it represents a possibly lower impact alternative to #24113, #24118, #29801, and #31222. It's not clear what functionality is relying on the string concatenation as it is currently implemented.
Changelog
Change the recursion algorithm to include labels from accessible elements only if they are not other types of
RCTViewinstances. For example,RCTTextViewshould be included. This helps to minimize the impact of this change on other developers of custom views.[iOS] [Changed] - When iterating over subviews, ignore subviews that are accessible elements (e.g. Touchable).
Test Plan
Verified that accessibility labels on
<Touchable>elements maintain existing behavior with nested Text elements.Verified that accessibility labels on non-accessible views do not include all child labels.
I added an example to
AccessibilityIOSExample.jswhich can be used with VoiceOver to see the new behavior. In the example, text nested inside accessible subviews is not part of the spoken label.