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

Allow UIView subviews to be a part of Accessibility Tree #2111

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

patryk-sredzinski
Copy link

If you add views to node.view, then those views aren't visible by AccessibilityInspector. This PR allows that

@CLAassistant
Copy link

CLAassistant commented Jun 25, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ patryk-sredzinski
❌ Patryk Średziński


Patryk Średziński seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@@ -302,6 +307,36 @@ static void CollectAccessibilityElements(ASDisplayNode *node, NSMutableArray *el
[elements addObject:subnode.view];
}
}

if (modalSubnode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a long complicated method. It is quite possible that in the future someone will add to it, likely at the end of the method. This early return could cause newly added logic to be skipped. To protect against that, I'd prefer you put your logic inside of an if and not early return:

if (!modalSubnode) {
   // your logic
    ....
}

}

// If a view is hidden or has an alpha of 0.0 we should not include it
if (viewIsHiddenFromAcessibility(subview)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is cheaper than iterating over elements and should be done first.

NSArray *subviews = view.subviews;
for (UIView *subview in subviews) {
// If a view is is already added then skip it
if ([elements containsObject:subview]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We are looping over subviews and elements for each subview. It would be more efficient to put the elements in a set so lookup is O(1), or use a smart diff algorithm to get only the subviews not in elements and iterate over those.

[elements containsObject:subview] is likely the most expensive operation in this loop, so it should at the very least be moved to the last possible check. e.g.,

if ((subview.isAccessibilityElement || subview.accessibilityElementCount > 0)) && ! [elements containsObject:subview]) {
      [elements addObject:subview];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants