Fix WKWebView Accessibility by ZevEisenberg · Pull Request #1955 · TextureGroup/Texture · GitHub
Skip to content
Merged
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
4 changes: 4 additions & 0 deletions AsyncDisplayKit.xcodeproj/project.pbxproj
12 changes: 7 additions & 5 deletions Source/Details/_ASDisplayViewAccessiblity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ @implementation _ASDisplayView (UIAccessibilityContainer)

#pragma mark - UIAccessibility

- (void)setAccessibilityElements:(NSArray *)accessibilityElements
- (void)setAccessibilityElements:(nullable NSArray *)accessibilityElements
{
ASDisplayNodeAssertMainThread();
// While it looks very strange to ignore the accessibilyElements param and set _accessibilityElements to nil, it is actually on purpose.
Expand All @@ -331,7 +331,7 @@ - (void)setAccessibilityElements:(NSArray *)accessibilityElements
_accessibilityElements = nil;
}

- (NSArray *)accessibilityElements
- (nullable NSArray *)accessibilityElements
{
ASDisplayNodeAssertMainThread();

Expand All @@ -352,7 +352,7 @@ - (NSArray *)accessibilityElements

@implementation ASDisplayNode (AccessibilityInternal)

- (NSArray *)accessibilityElements
- (nullable NSArray *)accessibilityElements
{
// NSObject implements the informal accessibility protocol. This means that all ASDisplayNodes already have an accessibilityElements
// property. If an ASDisplayNode subclass has explicitly set the property, let's use that instead of traversing the node tree to try
Expand All @@ -364,12 +364,14 @@ - (NSArray *)accessibilityElements

if (!self.isNodeLoaded) {
ASDisplayNodeFailAssert(@"Cannot access accessibilityElements since node is not loaded");
return @[];
return nil;
}
NSMutableArray *accessibilityElements = [[NSMutableArray alloc] init];
CollectAccessibilityElements(self, accessibilityElements);
SortAccessibilityElements(accessibilityElements);
return accessibilityElements;
// If we did not find any accessibility elements, return nil instead of empty array. This allows a WKWebView within the node
// to participate in accessibility.
return accessibilityElements.count == 0 ? nil : accessibilityElements;
}

@end
Expand Down
2 changes: 1 addition & 1 deletion Source/Private/ASDisplayNode+FrameworkPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ NS_INLINE UIAccessibilityTraits ASInteractiveAccessibilityTraitsMask() {
}

@interface ASDisplayNode (AccessibilityInternal)
- (NSArray *)accessibilityElements;
- (nullable NSArray *)accessibilityElements;
@end;

@interface UIView (ASDisplayNodeInternal)
Expand Down
29 changes: 29 additions & 0 deletions Tests/ASDisplayViewAccessibilityTests.mm