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

A11y for scrollnode #1188

Merged
merged 39 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
929d118
fix SIMULATE_WEB_RESPONSE not imported #449
wsdwsd0829 Jul 16, 2017
dd24d8f
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Sep 6, 2017
b8eaffa
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 4, 2017
2918ea0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 11, 2017
9c42266
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 12, 2017
329f35f
Fix to make rangeMode update in right time
wsdwsd0829 Feb 5, 2018
5f8b7ec
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Feb 7, 2018
d87bb11
merge master from upstream
wsdwsd0829 Feb 15, 2018
269c2ab
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 10, 2018
24c1ce8
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 12, 2018
233169e
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 26, 2018
b19f90d
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 28, 2018
b50cec4
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Apr 5, 2018
b75a5f3
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 May 3, 2018
64b46e0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 May 16, 2018
5fabc1e
remove uncessary assert
wsdwsd0829 May 17, 2018
3d5b84b
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 May 21, 2018
098b978
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Jun 8, 2018
77eefd6
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Jun 13, 2018
0310ed7
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Jul 3, 2018
0b886de
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Jul 25, 2018
a63d438
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Aug 21, 2018
06e18a1
Fix collection cell editing bug for iOS 9 & 10
wsdwsd0829 Aug 22, 2018
918434d
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Aug 31, 2018
41d3680
Revert "Fix collection cell editing bug for iOS 9 & 10"
wsdwsd0829 Sep 10, 2018
34833a3
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Sep 19, 2018
8d82d21
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Sep 25, 2018
f02d47c
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 3, 2018
dfe9123
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 11, 2018
1a6298c
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 23, 2018
820bc11
Add a11y support for ASSCrollNode.
wsdwsd0829 Oct 23, 2018
462f825
Changelog
wsdwsd0829 Oct 24, 2018
4bd3754
Clean up.
wsdwsd0829 Oct 25, 2018
df78e3d
fix braces
wsdwsd0829 Oct 25, 2018
55b2b1b
Merge branch 'master' into a11y-for-scrollnode
wsdwsd0829 Oct 25, 2018
fb91a89
add test
wsdwsd0829 Oct 26, 2018
d8e1d58
merge upstream
wsdwsd0829 Oct 26, 2018
df0e6e0
merge Changelog
wsdwsd0829 Oct 26, 2018
1a91b7a
disable for ci
wsdwsd0829 Oct 29, 2018
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
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 @@ -195,7 +195,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 @@ -258,17 +258,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