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

Visibility matching on SLElement #232

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,18 @@ - (NSString *)slAccessibilityDescription {
if ([traitNames count]) {
[properties addObject:[NSString stringWithFormat:@"traits = (%@)", [traitNames componentsJoinedByString:@", "]]];
}

if (self.isAccessibilityElement) {
[properties addObject:@"accessibilityElement = YES"];
}

if ([self respondsToSelector:@selector(isHidden)]) {
BOOL hidden = [(UIView *)self isHidden];
if (hidden) {
[properties addObject:@"hidden = YES"];
}
}

return [NSString stringWithFormat:@"<%@>", [properties componentsJoinedByString:@"; "]];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@
*/
- (void)logElement;

/**
Controls whether an element is only matched when it is not hidden.
*/
@property (nonatomic, assign) BOOL matchOnlyIfVisible;

@end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ - (BOOL)matchesObject:(NSObject *)object
NSAssert(_matchesObject, @"matchesObject called on %@, which has no _matchesObject predicate", self);
BOOL matchesObject = _matchesObject(object);

// Non-UIView objects are assumed to be "not hidden"
if (self.matchOnlyIfVisible) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You'd want to use -[NSObject slAccessibilityIsVisible], and check all objects, here--there are a bunch of reasons why objects, including non-views, might not be visible from both the user's and UIAutomation's perspectives.

(Making this change would cause matchOnlyIfVisible to fail in non-portrait orientations (#135), but would be generally more robust. It would be nice if you could fall back to UIAElement.isVisible as does -[SLElement isVisible] but I'm not sure how you'd do that given that matching takes place on the main thread.)

if ([object respondsToSelector:@selector(isHidden)]) {
matchesObject = matchesObject && ![(UIView *)object isHidden];
}
}

return (matchesObject && [object willAppearInAccessibilityHierarchy]);
}

Expand Down