-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,11 @@ static BOOL nodeIsHiddenFromAcessibility(ASDisplayNode *node) { | |
return node.isHidden || node.alpha == 0.0 || node.accessibilityElementsHidden; | ||
} | ||
|
||
/// returns YES if this view should be considered "hidden" from the screen reader. | ||
static BOOL viewIsHiddenFromAcessibility(UIView *view) { | ||
return view.isHidden || view.alpha == 0.0 || view.accessibilityElementsHidden; | ||
} | ||
|
||
/// Collect all accessibliity elements for a given view and view node | ||
static void CollectAccessibilityElements(ASDisplayNode *node, NSMutableArray *elements) | ||
{ | ||
|
@@ -302,6 +307,36 @@ static void CollectAccessibilityElements(ASDisplayNode *node, NSMutableArray *el | |
[elements addObject:subnode.view]; | ||
} | ||
} | ||
|
||
if (modalSubnode) { | ||
return; | ||
} | ||
|
||
NSArray *subviews = view.subviews; | ||
for (UIView *subview in subviews) { | ||
// If a view is is already added then skip it | ||
if ([elements containsObject:subview]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
continue; | ||
} | ||
|
||
// If a view is hidden or has an alpha of 0.0 we should not include it | ||
if (viewIsHiddenFromAcessibility(subview)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is cheaper than iterating over |
||
continue; | ||
} | ||
|
||
// If a subview is outside of the view's window, exclude it UNLESS it is a subview of an UIScrollView. | ||
// In this case UIKit will return the element even if it is outside of the window or the scrollView's visible rect (contentOffset + contentSize) | ||
CGRect viewInWindowCoords = [node convertRect:subview.frame toNode:nil]; | ||
if (!CGRectIntersectsRect(view.window.frame, viewInWindowCoords) && !recusivelyCheckSuperviewsForScrollView(view)) { | ||
continue; | ||
} | ||
|
||
if (subview.isAccessibilityElement) { | ||
[elements addObject:subview]; | ||
} else if (subview.accessibilityElementCount > 0) { | ||
[elements addObject:subview]; | ||
} | ||
} | ||
} | ||
|
||
@implementation _ASDisplayView (UIAccessibilityContainer) | ||
|
There was a problem hiding this comment.
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: