Skip to content

Commit

Permalink
[#1451] Add support for UIAccessibilityCustomAction (#1452)
Browse files Browse the repository at this point in the history
This PR adds support for UIAccessibilityCustomAction propagation through ASPendingState so that it can be picked up by VoiceOver.
  • Loading branch information
shamanskyh authored and nguyenhuy committed Apr 17, 2019
1 parent f48d778 commit e4f4220
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ AS_EXTERN NSInteger const ASDefaultDrawingPriority;
@property BOOL accessibilityViewIsModal;
@property BOOL shouldGroupAccessibilityChildren;
@property UIAccessibilityNavigationStyle accessibilityNavigationStyle;
@property (nullable, copy) NSArray *accessibilityCustomActions API_AVAILABLE(ios(8.0),tvos(9.0));
#if TARGET_OS_TV
@property (nullable, copy) NSArray *accessibilityHeaderElements;
#endif
Expand Down
14 changes: 14 additions & 0 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,20 @@ - (UIAccessibilityNavigationStyle)accessibilityNavigationStyle
return _getAccessibilityFromViewOrProperty(_accessibilityNavigationStyle, accessibilityNavigationStyle);
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
- (void)setAccessibilityCustomActions:(NSArray *)accessibilityCustomActions
{
_bridge_prologue_write;
_setAccessibilityToViewAndProperty(_accessibilityCustomActions, accessibilityCustomActions, accessibilityCustomActions, accessibilityCustomActions);
}

- (NSArray *)accessibilityCustomActions
{
_bridge_prologue_read;
return _getAccessibilityFromViewOrProperty(_accessibilityCustomActions, accessibilityCustomActions);
}
#endif

#if TARGET_OS_TV
- (void)setAccessibilityHeaderElements:(NSArray *)accessibilityHeaderElements
{
Expand Down
1 change: 1 addition & 0 deletions Source/Private/ASDisplayNodeInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ static constexpr CACornerMask kASCACornerAllCorners =
BOOL _shouldGroupAccessibilityChildren;
NSString *_accessibilityIdentifier;
UIAccessibilityNavigationStyle _accessibilityNavigationStyle;
NSArray *_accessibilityCustomActions;
NSArray *_accessibilityHeaderElements;
CGPoint _accessibilityActivationPoint;
UIBezierPath *_accessibilityPath;
Expand Down
29 changes: 28 additions & 1 deletion Source/Private/_ASPendingState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
int setShouldGroupAccessibilityChildren:1;
int setAccessibilityIdentifier:1;
int setAccessibilityNavigationStyle:1;
int setAccessibilityCustomActions:1;
int setAccessibilityHeaderElements:1;
int setAccessibilityActivationPoint:1;
int setAccessibilityPath:1;
Expand Down Expand Up @@ -141,6 +142,7 @@ @implementation _ASPendingState
BOOL shouldGroupAccessibilityChildren;
NSString *accessibilityIdentifier;
UIAccessibilityNavigationStyle accessibilityNavigationStyle;
NSArray *accessibilityCustomActions;
NSArray *accessibilityHeaderElements;
CGPoint accessibilityActivationPoint;
UIBezierPath *accessibilityPath;
Expand Down Expand Up @@ -289,6 +291,7 @@ - (instancetype)init
shouldGroupAccessibilityChildren = NO;
accessibilityIdentifier = nil;
accessibilityNavigationStyle = UIAccessibilityNavigationStyleAutomatic;
accessibilityCustomActions = nil;
accessibilityHeaderElements = nil;
accessibilityActivationPoint = CGPointZero;
accessibilityPath = nil;
Expand Down Expand Up @@ -797,6 +800,19 @@ - (void)setAccessibilityNavigationStyle:(UIAccessibilityNavigationStyle)newAcces
accessibilityNavigationStyle = newAccessibilityNavigationStyle;
}

- (NSArray *)accessibilityCustomActions
{
return accessibilityCustomActions;
}

- (void)setAccessibilityCustomActions:(NSArray *)newAccessibilityCustomActions
{
_flags.setAccessibilityCustomActions = YES;
if (accessibilityCustomActions != newAccessibilityCustomActions) {
accessibilityCustomActions = [newAccessibilityCustomActions copy];
}
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (NSArray *)accessibilityHeaderElements
Expand Down Expand Up @@ -1155,7 +1171,13 @@ - (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPr

if (flags.setAccessibilityNavigationStyle)
view.accessibilityNavigationStyle = accessibilityNavigationStyle;


if (AS_AVAILABLE_IOS_TVOS(8, 9)) {
if (flags.setAccessibilityCustomActions) {
view.accessibilityCustomActions = accessibilityCustomActions;
}
}

#if TARGET_OS_TV
if (flags.setAccessibilityHeaderElements)
view.accessibilityHeaderElements = accessibilityHeaderElements;
Expand Down Expand Up @@ -1294,6 +1316,11 @@ + (_ASPendingState *)pendingViewStateFromView:(UIView *)view
pendingState.shouldGroupAccessibilityChildren = view.shouldGroupAccessibilityChildren;
pendingState.accessibilityIdentifier = view.accessibilityIdentifier;
pendingState.accessibilityNavigationStyle = view.accessibilityNavigationStyle;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
if (AS_AVAILABLE_IOS_TVOS(8, 9)) {
pendingState.accessibilityCustomActions = view.accessibilityCustomActions;
}
#endif
#if TARGET_OS_TV
pendingState.accessibilityHeaderElements = view.accessibilityHeaderElements;
#endif
Expand Down
15 changes: 15 additions & 0 deletions Tests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ - (void)checkValuesMatchDefaults:(ASDisplayNode *)node isLayerBacked:(BOOL)isLay
XCTAssertEqual(NO, node.accessibilityElementsHidden, @"default accessibilityElementsHidden is broken %@", hasLoadedView);
XCTAssertEqual(NO, node.accessibilityViewIsModal, @"default accessibilityViewIsModal is broken %@", hasLoadedView);
XCTAssertEqual(NO, node.shouldGroupAccessibilityChildren, @"default shouldGroupAccessibilityChildren is broken %@", hasLoadedView);
XCTAssertEqual((id)nil, node.accessibilityCustomActions, @"default acccessibilityCustomActions is broken %@", hasLoadedView);

if (!isLayerBacked) {
XCTAssertEqual(YES, node.userInteractionEnabled, @"default userInteractionEnabled broken %@", hasLoadedView);
Expand Down Expand Up @@ -555,6 +556,12 @@ - (UIImage *)bogusImage
return bogusImage;
}

- (BOOL)dummySelector
{
// no-op; only used for testing of UIAccessibilityCustomAction propagation
return YES;
}

- (void)checkValuesMatchSetValues:(ASDisplayNode *)node isLayerBacked:(BOOL)isLayerBacked
{
NSString *targetName = isLayerBacked ? @"layer" : @"view";
Expand Down Expand Up @@ -609,6 +616,11 @@ - (void)checkValuesMatchSetValues:(ASDisplayNode *)node isLayerBacked:(BOOL)isLa
XCTAssertEqual(YES, node.accessibilityViewIsModal, @"accessibilityViewIsModal broken %@", hasLoadedView);
XCTAssertEqual(YES, node.shouldGroupAccessibilityChildren, @"shouldGroupAccessibilityChildren broken %@", hasLoadedView);
XCTAssertEqual(UIAccessibilityNavigationStyleSeparate, node.accessibilityNavigationStyle, @"accessibilityNavigationStyle broken %@", hasLoadedView);
if (AS_AVAILABLE_IOS_TVOS(8, 9)) {
XCTAssertNotNil(node.accessibilityCustomActions, @"accessibilityCustomActions broken %@", hasLoadedView);
XCTAssertEqualObjects(@"custom action", ((UIAccessibilityCustomAction *)(node.accessibilityCustomActions.firstObject)).name, @"accessibilityCustomActions broken %@", hasLoadedView);
}

XCTAssertTrue(CGPointEqualToPoint(CGPointMake(1.0, 1.0), node.accessibilityActivationPoint), @"accessibilityActivationPoint broken %@", hasLoadedView);
XCTAssertNotNil(node.accessibilityPath, @"accessibilityPath broken %@", hasLoadedView);

Expand Down Expand Up @@ -680,6 +692,9 @@ - (void)checkSimpleBridgePropertiesSetPropagate:(BOOL)isLayerBacked
node.accessibilityViewIsModal = YES;
node.shouldGroupAccessibilityChildren = YES;
node.accessibilityNavigationStyle = UIAccessibilityNavigationStyleSeparate;
if (AS_AVAILABLE_IOS_TVOS(8, 9)) {
node.accessibilityCustomActions = @[ [[UIAccessibilityCustomAction alloc] initWithName:@"custom action" target:self selector:@selector(dummySelector)] ];
}
node.accessibilityActivationPoint = CGPointMake(1.0, 1.0);
node.accessibilityPath = [UIBezierPath bezierPath];

Expand Down

0 comments on commit e4f4220

Please sign in to comment.