Skip to content

Commit

Permalink
A11y for scrollnode (TextureGroup#1188)
Browse files Browse the repository at this point in the history
* fix SIMULATE_WEB_RESPONSE not imported TextureGroup#449

* Fix to make rangeMode update in right time

* remove uncessary assert

* Fix collection cell editing bug for iOS 9 & 10

* Revert "Fix collection cell editing bug for iOS 9 & 10"

This reverts commit 06e18a1.

* Add a11y support for ASSCrollNode.

* Changelog

* Clean up.

* fix braces

* add test

* disable for ci
  • Loading branch information
wsdwsd0829 authored and mikezucc committed Nov 7, 2018
1 parent 62130bd commit 8ff1daa
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master
* Add your own contributions to the next release on the line below this with your name.
- [ASScrollNode] A11y support for ASScrollNode. [Max Wang](https://github.com/wsdwsd0829). [#1188](https://github.com/TextureGroup/Texture/pull/1188)
- [ASDisplayNode.m] Make sure node is loaded before enter visible. [Max Wang](https://github.com/wsdwsd0829). [#886](https://github.com/TextureGroup/Texture/pull/886)
- [ASTextNode2] Add improved support for all line-break modes in experimental text node. [Kevin Smith](https://github.com/wiseoldduck). [#1150](https://github.com/TextureGroup/Texture/pull/1150)
- [ASExperimentalFeatures.m] Fix mismatch name in experimental features. [Max Wang](https://github.com/wsdwsd0829). [#1159](https://github.com/TextureGroup/Texture/pull/1159)
Expand Down
5 changes: 5 additions & 0 deletions Source/ASScrollNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ - (void)didMoveToWindow
}
}

- (NSArray *)accessibilityElements
{
return [self.asyncdisplaykit_node accessibilityElements];
}

@end

@implementation ASScrollNode
Expand Down
27 changes: 19 additions & 8 deletions Source/Details/_ASDisplayViewAccessiblity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void CollectUIAccessibilityElementsForNode(ASDisplayNode *node, ASDisplay
});
}

static void CollectAccessibilityElementsForContainer(ASDisplayNode *container, _ASDisplayView *view, NSMutableArray *elements) {
static void CollectAccessibilityElementsForContainer(ASDisplayNode *container, UIView *view, NSMutableArray *elements) {
UIAccessibilityElement *accessiblityElement = [ASAccessibilityElement accessibilityElementWithContainer:view node:container containerNode:container];

NSMutableArray<ASAccessibilityElement *> *labeledNodes = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -202,7 +202,7 @@ static void CollectAccessibilityElementsForContainer(ASDisplayNode *container, _
}

/// Collect all accessibliity elements for a given view and view node
static void CollectAccessibilityElementsForView(_ASDisplayView *view, NSMutableArray *elements)
static void CollectAccessibilityElementsForView(UIView *view, NSMutableArray *elements)
{
ASDisplayNodeCAssertNotNil(elements, @"Should pass in a NSMutableArray");

Expand Down Expand Up @@ -265,17 +265,28 @@ - (NSArray *)accessibilityElements
if (viewNode == nil) {
return @[];
}

if (_accessibilityElements == nil) {
NSMutableArray *accessibilityElements = [[NSMutableArray alloc] init];
CollectAccessibilityElementsForView(self, accessibilityElements);
SortAccessibilityElements(accessibilityElements);
_accessibilityElements = accessibilityElements;
_accessibilityElements = [viewNode accessibilityElements];
}

return _accessibilityElements;
}

@end

@implementation ASDisplayNode (AccessibilityInternal)

- (NSArray *)accessibilityElements
{
if (!self.isNodeLoaded) {
ASDisplayNodeFailAssert(@"Cannot access accessibilityElements since node is not loaded");
return @[];
}
NSMutableArray *accessibilityElements = [[NSMutableArray alloc] init];
CollectAccessibilityElementsForView(self.view, accessibilityElements);
SortAccessibilityElements(accessibilityElements);
return accessibilityElements;
}

@end

#endif
4 changes: 4 additions & 0 deletions Source/Private/ASDisplayNode+FrameworkPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ __unused static NSString * _Nonnull NSStringFromASHierarchyStateChange(ASHierarc

@end

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

@interface UIView (ASDisplayNodeInternal)
@property (nullable, weak) ASDisplayNode *asyncdisplaykit_node;
@end
Expand Down
31 changes: 31 additions & 0 deletions Tests/ASScrollNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,35 @@ - (void)testAutomaticallyManagesContentSizeWithInvalidCalculatedSizeForLayout
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}

- (void)testASScrollNodeAccessibility {
ASDisplayNode *scrollNode = [[ASDisplayNode alloc] init];
ASDisplayNode *node = [[ASDisplayNode alloc] init];
node.isAccessibilityContainer = YES;
node.accessibilityLabel = @"node";
[scrollNode addSubnode:node];
node.frame = CGRectMake(0,0,100,100);
ASTextNode2 *text = [[ASTextNode2 alloc] init];
text.attributedText = [[NSAttributedString alloc] initWithString:@"text"];
[node addSubnode:text];

ASTextNode2 *text2 = [[ASTextNode2 alloc] init];
text2.attributedText = [[NSAttributedString alloc] initWithString:@"text2"];
[node addSubnode:text2];
__unused UIView *view = scrollNode.view;
XCTAssertTrue(node.view.accessibilityElements.firstObject, @"node");

// Following tests will only pass when accessibility is enabled.
// More details: https://github.com/TextureGroup/Texture/pull/1188

// A bunch of a11y containers each of which hold aggregated labels.
/* NSArray *a11yElements = [scrollNode.view accessibilityElements];
XCTAssertTrue(a11yElements.count > 0, @"accessibilityElements should exist");
UIAccessibilityElement *container = a11yElements.firstObject;
XCTAssertTrue(container.isAccessibilityElement == false && container.accessibilityElements.count > 0);
UIAccessibilityElement *ae = container.accessibilityElements.firstObject;
XCTAssertTrue([[ae accessibilityLabel] isEqualToString:@"node, text, text2"]);
*/
}

@end

0 comments on commit 8ff1daa

Please sign in to comment.