Skip to content

Commit

Permalink
Adds accessibility support to the framework.
Browse files Browse the repository at this point in the history
Closes #64
  • Loading branch information
LeoNatan committed Apr 30, 2016
1 parent f27186d commit f723fd0
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
3947E1B01B61CE4A0001178B /* LNPopupController.h */,
3947E1B11B61CE4A0001178B /* LNPopupController.m */,
394A85BB1B6306AE004FFC61 /* LNPopupItem+Private.h */,
394A85B81B6304F5004FFC61 /* LNPopupItem.m */,
394A85C71B63FB96004FFC61 /* UIViewController+LNPopupSupportPrivate.h */,
394A85C81B63FE52004FFC61 /* UIViewController+LNPopupSupportPrivate.m */,
3947E1A01B61CD1F0001178B /* UIViewController+LNPopupSupport.m */,
394A85B81B6304F5004FFC61 /* LNPopupItem.m */,
);
name = "Private Implementation";
path = Private;
Expand Down
14 changes: 14 additions & 0 deletions LNPopupController/LNPopupController/LNPopupItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface LNPopupItem (Accessibility)

/**
* The accessibility label of the progress, in a localized string.
*/
@property (nonatomic, copy, nullable) NSString* accessibilityProgressLabel;

/**
* The accessibility value of the progress, in a localized string.
*/
@property (nonatomic, copy, nullable) NSString* accessibilityProgressValue;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extern const CGFloat LNPopupBarHeight;

@property (nonatomic, strong) UIProgressView* progressView;

@property (nonatomic, copy) NSString* accessibilityCenterLabel;
@property (nonatomic, copy) NSString* accessibilityCenterHint;
@property (nonatomic, copy) NSString* accessibilityProgressLabel;
@property (nonatomic, copy) NSString* accessibilityProgressValue;

- (void)_delayBarButtonLayout;
- (void)_layoutBarButtonItems;

Expand Down
96 changes: 74 additions & 22 deletions LNPopupController/LNPopupController/Private/LNPopupBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
_toolbar.layer.masksToBounds = YES;
[self addSubview:_toolbar];

_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressView.trackImage = [UIImage alloc];
[_toolbar addSubview:_progressView];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_progressView(1)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_progressView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressView)]];

_highlightView = [[UIView alloc] initWithFrame:self.bounds];
_highlightView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_highlightView.userInteractionEnabled = NO;
Expand All @@ -70,10 +63,23 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
_titlesView = [[UIView alloc] initWithFrame:fullFrame];
_titlesView.userInteractionEnabled = NO;
_titlesView.autoresizingMask = UIViewAutoresizingNone;

_titlesView.accessibilityTraits = UIAccessibilityTraitButton;
_titlesView.isAccessibilityElement = YES;

[self _layoutTitles];
[self.toolbar addSubview:_titlesView];

_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
_progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressView.trackImage = [UIImage alloc];
[_toolbar addSubview:_progressView];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_progressView(1)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressView)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_progressView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressView)]];

_needsLabelsLayout = YES;

self.accessibilityLabel = @"Popup Asshole";
}

return self;
Expand Down Expand Up @@ -224,6 +230,34 @@ - (void)setSubtitle:(NSString *)subtitle
[self _setNeedsTitleLayout];
}

- (void)setAccessibilityCenterHint:(NSString *)accessibilityCenterHint
{
_accessibilityCenterHint = accessibilityCenterHint;

[self _setNeedsAccessibilityUpdate];
}

- (void)setAccessibilityCenterLabel:(NSString *)accessibilityCenterLabel
{
_accessibilityCenterLabel = accessibilityCenterLabel;

[self _setNeedsAccessibilityUpdate];
}

- (void)setAccessibilityProgressLabel:(NSString *)accessibilityProgressLabel
{
_accessibilityProgressLabel = accessibilityProgressLabel;

_progressView.accessibilityLabel = accessibilityProgressLabel;
}

- (void)setAccessibilityProgressValue:(NSString *)accessibilityProgressValue
{
_accessibilityProgressValue = accessibilityProgressValue;

_progressView.accessibilityValue = accessibilityProgressValue;
}

- (__MarqueeLabel*)_newMarqueeLabel
{
__MarqueeLabel* rv = [[__MarqueeLabel alloc] initWithFrame:_titlesView.bounds rate:20 andFadeLength:10];
Expand Down Expand Up @@ -313,21 +347,6 @@ - (void)_layoutTitles
titleLabelFrame.origin.y -= _titleLabel.font.lineHeight / 2;
subtitleLabelFrame.origin.y += _subtitleLabel.font.lineHeight / 2;

if(_needsLabelsLayout == YES)
{
// NSTimeInterval titleDuration = [_titleLabel animationDuration];
// NSTimeInterval subtitleDuration = [_subtitleLabel animationDuration];
//
// if(_titleLabel.animationDuration < _subtitleLabel.animationDuration)
// {
// _titleLabel.animationDelayAfter = -20; //(subtitleDuration - titleDuration);
// }
// else
// {
// _subtitleLabel.animationDelayAfter = - 20;//(subtitleDuration - titleDuration);
// }
}

_subtitleLabel.frame = subtitleLabelFrame;
_subtitleLabel.hidden = NO;

Expand All @@ -349,12 +368,45 @@ - (void)_layoutTitles
}
}

[self _setNeedsAccessibilityUpdate];

_titleLabel.frame = titleLabelFrame;

_needsLabelsLayout = NO;
});
}

- (void)_setNeedsAccessibilityUpdate
{
if(_accessibilityCenterLabel.length > 0)
{
_titlesView.accessibilityLabel = _accessibilityCenterLabel;
}
else
{
NSMutableString* accessibilityLabel = [NSMutableString new];
if(_title.length > 0)
{
[accessibilityLabel appendString:_title];
[accessibilityLabel appendString:@"\n"];
}
if(_subtitle.length > 0)
{
[accessibilityLabel appendString:_subtitle];
}
_titlesView.accessibilityLabel = accessibilityLabel;
}

if(_accessibilityCenterHint.length > 0)
{
_titlesView.accessibilityHint = _accessibilityCenterHint;
}
else
{
_titlesView.accessibilityHint = NSLocalizedString(@"Double tap to open.", @"");
}
}

- (void)_setNeedsTitleLayout
{
_needsLabelsLayout = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ - (nonnull instancetype)initWithFrame:(CGRect)frame
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[self setImage:[UIImage imageNamed:@"DismissChevron" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];

self.accessibilityLabel = NSLocalizedString(@"Close", @"");
}

return self;
Expand Down
33 changes: 32 additions & 1 deletion LNPopupController/LNPopupController/Private/LNPopupController.m
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,16 @@ - (void)_transitionToState:(LNPopupPresentationState)state animated:(BOOL)animat
[_popupBar addGestureRecognizer:self.popupContentView.popupInteractionGestureRecognizer];

[_popupBar _setTitleViewMarqueesPaused:NO];

_popupContentView.accessibilityViewIsModal = NO;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
}
else if(state == LNPopupPresentationStateOpen)
{
[_popupBar _setTitleViewMarqueesPaused:YES];

_popupContentView.accessibilityViewIsModal = YES;
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, _popupContentView.popupCloseButton);
}

_popupControllerState = state;
Expand Down Expand Up @@ -480,6 +486,26 @@ - (void)_reconfigure_progress
}];
}

- (void)_reconfigure_accessibilityLavel
{
_popupBar.accessibilityCenterLabel = _currentPopupItem.accessibilityLabel;
}

- (void)_reconfigure_accessibilityHint
{
_popupBar.accessibilityCenterHint = _currentPopupItem.accessibilityHint;
}

- (void)_reconfigure_accessibilityProgressLabel
{
_popupBar.accessibilityProgressLabel = _currentPopupItem.accessibilityProgressLabel;
}

- (void)_reconfigure_accessibilityProgressValue
{
_popupBar.accessibilityProgressValue = _currentPopupItem.accessibilityProgressValue;
}

- (void)_reconfigureBarItems
{
[_popupBar _delayBarButtonLayout];
Expand Down Expand Up @@ -534,9 +560,14 @@ - (void)_reconfigureContent
[_currentContentController endAppearanceTransition];

_currentContentController = newContentController;

if(_popupControllerState == LNPopupPresentationStateOpen)
{
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
}
}

NSArray<NSString*>* keys = @[@"title", @"subtitle", @"progress", @"leftBarButtonItems"];
NSArray<NSString*>* keys = @[@"title", @"subtitle", @"progress", @"leftBarButtonItems", @"accessibilityLavel", @"accessibilityHint", @"accessibilityProgressLabel", @"accessibilityProgressValue"];
[keys enumerateObjectsUsingBlock:^(NSString * __nonnull key, NSUInteger idx, BOOL * __nonnull stop) {
[self _popupItem:_currentPopupItem didChangeValueForKey:key];
}];
Expand Down
10 changes: 10 additions & 0 deletions LNPopupController/LNPopupController/Private/LNPopupItem+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@

@interface LNPopupItem ()

/**
* The accessibility label of the progress, in a localized string.
*/
@property (nonatomic, copy) NSString* accessibilityProgressLabel;

/**
* The accessibility value of the progress, in a localized string.
*/
@property (nonatomic, copy) NSString* accessibilityProgressValue;

@property (nonatomic, weak, setter=_setItemDelegate:, getter=_itemDelegate) id<_LNPopupItemDelegate> itemDelegate;
@property (nonatomic, weak, setter=_setContainerController:, getter=_containerController) __kindof UIViewController* containerController;

Expand Down
11 changes: 11 additions & 0 deletions LNPopupController/LNPopupController/Private/LNPopupItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

@implementation LNPopupItem

@synthesize accessibilityProgressLabel = _accessibilityProgressLabel;
@synthesize accessibilityProgressValue = _accessibilityProgressValue;

- (instancetype)init
{
self = [super init];
Expand All @@ -24,6 +27,10 @@ - (instancetype)init
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(progress)) options:0 context:_LNPopupItemObservationContext];
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(leftBarButtonItems)) options:0 context:_LNPopupItemObservationContext];
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(rightBarButtonItems)) options:0 context:_LNPopupItemObservationContext];
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityLabel)) options:0 context:_LNPopupItemObservationContext];
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityHint)) options:0 context:_LNPopupItemObservationContext];
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityProgressLabel)) options:0 context:_LNPopupItemObservationContext];
[self addObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityProgressValue)) options:0 context:_LNPopupItemObservationContext];
}

return self;
Expand All @@ -36,6 +43,10 @@ - (void)dealloc
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(progress)) context:_LNPopupItemObservationContext];
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(leftBarButtonItems)) context:_LNPopupItemObservationContext];
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(rightBarButtonItems)) context:_LNPopupItemObservationContext];
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityLabel)) context:_LNPopupItemObservationContext];
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityHint)) context:_LNPopupItemObservationContext];
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityProgressLabel)) context:_LNPopupItemObservationContext];
[self removeObserver:self forKeyPath:NSStringFromSelector(@selector(accessibilityProgressValue)) context:_LNPopupItemObservationContext];
}

- (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary<NSString *, id> *)change context:(nullable void *)context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
TargetAttributes = {
39277A031B58228000293F95 = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = 6Z9ASVU98Y;
};
};
};
Expand Down Expand Up @@ -412,11 +413,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = LNPopupControllerExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.LeoNatan.LNPopupControllerExample;
PRODUCT_BUNDLE_IDENTIFIER = com.LeoNatan.LNPopupControllerExampleZZZZ;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "LNPopupControllerExample/LNPopupControllerExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -429,11 +433,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = LNPopupControllerExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.LeoNatan.LNPopupControllerExample;
PRODUCT_BUNDLE_IDENTIFIER = com.LeoNatan.LNPopupControllerExampleZZZZ;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OBJC_BRIDGING_HEADER = "LNPopupControllerExample/LNPopupControllerExample-Bridging-Header.h";
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class DemoAlbumTableViewController: UITableViewController {
popupContentController.songTitle = titles[indexPath.row]
popupContentController.albumTitle = subtitles[indexPath.row]

popupContentController.popupItem.accessibilityHint = NSLocalizedString("Double Tap to Expand the Mini Player", comment: "")
tabBarController?.popupContentView.popupCloseButton?.accessibilityLabel = NSLocalizedString("Dismiss Now Playing Screen", comment: "")

tabBarController?.presentPopupBarWithContentViewController(popupContentController, animated: true, completion: nil)

tableView.deselectRowAtIndexPath(indexPath, animated: true)
Expand Down
Loading

0 comments on commit f723fd0

Please sign in to comment.