Merge pull request #1406 from rahul-malik/rmalik-button-a11y

[Accessibility] Basic a11y support for ASButtonNode (adopt text node title as a11y label)
This commit is contained in:
appleguy
2016-03-20 19:24:55 -07:00
2 changed files with 18 additions and 2 deletions

View File

@@ -60,6 +60,7 @@
_contentHorizontalAlignment = ASAlignmentMiddle;
_contentVerticalAlignment = ASAlignmentCenter;
_contentEdgeInsets = UIEdgeInsetsZero;
self.accessibilityTraits = UIAccessibilityTraitButton;
}
return self;
}
@@ -102,6 +103,11 @@
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
if (enabled) {
self.accessibilityTraits = UIAccessibilityTraitButton;
} else {
self.accessibilityTraits = UIAccessibilityTraitButton | UIAccessibilityTraitNotEnabled;
}
[self updateButtonContent];
}
@@ -135,7 +141,7 @@
- (void)updateImage
{
ASDN::MutexLocker l(_propertyLock);
UIImage *newImage;
if (self.enabled == NO && _disabledImage) {
newImage = _disabledImage;
@@ -170,9 +176,10 @@
} else {
newTitle = _normalAttributedTitle;
}
if ((_titleNode != nil || newTitle.length > 0) && newTitle != self.titleNode.attributedString) {
_titleNode.attributedString = newTitle;
self.accessibilityLabel = _titleNode.accessibilityLabel;
[self setNeedsLayout];
}
}
@@ -331,6 +338,7 @@
default:
break;
}
[self updateTitle];
}

View File

@@ -77,6 +77,7 @@ static BOOL _enableHitTestDebug = NO;
}
#pragma mark - Lifecycle
- (id)init
{
if (!(self = [super init]))
@@ -89,6 +90,13 @@ static BOOL _enableHitTestDebug = NO;
return self;
}
- (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled
{
[super setUserInteractionEnabled:userInteractionEnabled];
self.isAccessibilityElement = userInteractionEnabled;
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-missing-super-calls"