accessibility

This commit is contained in:
Pfeil, Scott Robert 2019-07-12 14:49:16 -04:00
parent 39cb930263
commit 5e2d009313
7 changed files with 59 additions and 29 deletions

View File

@ -85,4 +85,7 @@
/// Convenience function for getting the alignment from a map. /// Convenience function for getting the alignment from a map.
+ (UIStackViewAlignment)getAlignmentForString:(nullable NSString *)alignmentString defaultAlignment:(UIStackViewAlignment)defaultAlignment; + (UIStackViewAlignment)getAlignmentForString:(nullable NSString *)alignmentString defaultAlignment:(UIStackViewAlignment)defaultAlignment;
/// Makes the view isAccessibilityElement false and adds molecule elements to accessbilityElements.
- (void)setMoleculeAccessibility;
@end @end

View File

@ -27,6 +27,7 @@
[self addConstrainedView:molecule alignment:alignment]; [self addConstrainedView:molecule alignment:alignment];
[self setAsMolecule]; [self setAsMolecule];
} }
[self setMoleculeAccessibility];
self.molecule = molecule; self.molecule = molecule;
} }
return self; return self;
@ -327,6 +328,17 @@
#pragma mark - MVMCoreUIMoleculeViewProtocol #pragma mark - MVMCoreUIMoleculeViewProtocol
- (void)setMoleculeAccessibility {
if (self.molecule) {
self.isAccessibilityElement = NO;
if (self.molecule.accessibilityElements) {
self.accessibilityElements = self.molecule.accessibilityElements;
} else {
self.accessibilityElements = @[self.molecule];
}
}
}
- (void)reset { - (void)reset {
if ([self.molecule respondsToSelector:@selector(reset)]) { if ([self.molecule respondsToSelector:@selector(reset)]) {
[self.molecule performSelector:@selector(reset)]; [self.molecule performSelector:@selector(reset)];
@ -350,6 +362,7 @@
[self pinViewToSuperView:molecule]; [self pinViewToSuperView:molecule];
} }
} }
[self setMoleculeAccessibility];
} }
if (self.molecule) { if (self.molecule) {
if ([self.molecule respondsToSelector:@selector(copyBackgroundColor)] && [self.molecule performSelector:@selector(copyBackgroundColor)]) { if ([self.molecule respondsToSelector:@selector(copyBackgroundColor)] && [self.molecule performSelector:@selector(copyBackgroundColor)]) {

View File

@ -68,6 +68,7 @@ open class Carousel: ViewConstrainingView {
open override func updateView(_ size: CGFloat) { open override func updateView(_ size: CGFloat) {
super.updateView(size) super.updateView(size)
collectionView.collectionViewLayout.invalidateLayout() collectionView.collectionViewLayout.invalidateLayout()
showPeaking(false)
// Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled. // Go to current cell. layoutIfNeeded is needed otherwise cellForItem returns nil for peaking logic. The dispatch is a sad way to ensure the collection view is ready to be scrolled.
DispatchQueue.main.async { DispatchQueue.main.async {
@ -141,7 +142,6 @@ open class Carousel: ViewConstrainingView {
var pagingView: (UIView & MVMCoreUIPagingProtocol)? = nil var pagingView: (UIView & MVMCoreUIPagingProtocol)? = nil
if let json = json { if let json = json {
pagingView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: json, delegateObject: delegateObject, constrainIfNeeded: true) as? (UIView & MVMCoreUIPagingProtocol) pagingView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: json, delegateObject: delegateObject, constrainIfNeeded: true) as? (UIView & MVMCoreUIPagingProtocol)
pagingView?.isAccessibilityElement = true
} }
addPaging(view: pagingView, position: (json?.optionalCGFloatForKey("position") ?? 20)) addPaging(view: pagingView, position: (json?.optionalCGFloatForKey("position") ?? 20))
} }
@ -205,7 +205,7 @@ open class Carousel: ViewConstrainingView {
} }
open func showPeaking(_ peaking: Bool) { open func showPeaking(_ peaking: Bool) {
if peaking { if peaking && !UIAccessibility.isVoiceOverRunning {
// Show overlay and arrow in peaking Cell // Show overlay and arrow in peaking Cell
let visibleItemsPaths = collectionView.indexPathsForVisibleItems.sorted { $0.row < $1.row } let visibleItemsPaths = collectionView.indexPathsForVisibleItems.sorted { $0.row < $1.row }
if let firstItem = visibleItemsPaths.first, firstItem.row != currentIndex { if let firstItem = visibleItemsPaths.first, firstItem.row != currentIndex {
@ -221,6 +221,26 @@ open class Carousel: ViewConstrainingView {
} }
} }
} }
func setAccessiblity(_ cell: UICollectionViewCell?, index: Int) {
guard let cell = cell else {
return
}
if index == currentIndex {
cell.accessibilityElementsHidden = false
var array = cell.accessibilityElements
if let acc = pagingView?.accessibilityElements {
array?.append(contentsOf: acc)
} else {
array?.append(pagingView!)
}
self.accessibilityElements = array
} else {
cell.accessibilityElementsHidden = true
}
}
} }
extension Carousel: UICollectionViewDelegateFlowLayout { extension Carousel: UICollectionViewDelegateFlowLayout {
@ -246,14 +266,7 @@ extension Carousel: UICollectionViewDataSource {
protocolCell.setWithJSON(moleculeInfo.molecule, delegateObject: nil, additionalData: nil) protocolCell.setWithJSON(moleculeInfo.molecule, delegateObject: nil, additionalData: nil)
protocolCell.updateView(collectionView.bounds.width) protocolCell.updateView(collectionView.bounds.width)
} }
setAccessiblity(cell, index: indexPath.row)
if indexPath.row == currentIndex {
cell.accessibilityElementsHidden = false
// self.accessibilityElements = @[cell.containerView, self.pageControl];
} else {
cell.accessibilityElementsHidden = true
}
return cell return cell
} }
} }
@ -261,10 +274,14 @@ extension Carousel: UICollectionViewDataSource {
extension Carousel: UIScrollViewDelegate { extension Carousel: UIScrollViewDelegate {
func goTo(_ index: Int, animated: Bool) { func goTo(_ index: Int, animated: Bool) {
collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0))?.accessibilityElementsHidden = true showPeaking(false)
setAccessiblity(collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0)), index: index)
self.currentIndex = index self.currentIndex = index
collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0))?.accessibilityElementsHidden = false
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: animated) self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: animated)
if let cell = collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0)) {
setAccessiblity(collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0)), index: index)
UIAccessibility.post(notification: .layoutChanged, argument: cell)
}
} }
func handleUserOnBufferCell() { func handleUserOnBufferCell() {
@ -353,7 +370,5 @@ extension Carousel: UIScrollViewDelegate {
pagingView?.setPage(pageIndex) pagingView?.setPage(pageIndex)
showPeaking(true) showPeaking(true)
//UIAccessibility.post(notification: .layoutChanged, argument: currentIndex) UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,currentCell.containerView);
} }
} }

View File

@ -241,6 +241,8 @@ static CGFloat const IndicatorRectangleHeight = 4;
- (void)setupView { - (void)setupView {
if (!self.containerView) { if (!self.containerView) {
self.isAccessibilityElement = YES;
// Create a container view that keeps everything centered // Create a container view that keeps everything centered
UIView *containerView = [MVMCoreUICommonViewsUtility commonView]; UIView *containerView = [MVMCoreUICommonViewsUtility commonView];
[self addSubview:containerView]; [self addSubview:containerView];

View File

@ -31,6 +31,13 @@ open class ModuleMolecule: ViewConstrainingView {
addSubview(moleculeView) addSubview(moleculeView)
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values)) NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values))
moduleMolecule = moleculeView moduleMolecule = moleculeView
isAccessibilityElement = false
if moleculeView.accessibilityElements != nil {
accessibilityElements = moleculeView.accessibilityElements
} else {
accessibilityElements = [moleculeView]
}
} }
} else { } else {
moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData) moduleMolecule?.setWithJSON(module, delegateObject: delegateObject, additionalData: additionalData)

View File

@ -73,13 +73,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
if molecule == nil { if molecule == nil {
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) { if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) {
contentView.insertSubview(moleculeView, at: 0) contentView.insertSubview(moleculeView, at: 0)
let standardConstraints = (moleculeView as? MVMCoreUIViewConstrainingProtocol)?.useStandardConstraints?() ?? true NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: false).values))
NSLayoutConstraint.activate(Array(NSLayoutConstraint.pinView(toSuperview: moleculeView, useMargins: standardConstraints).values))
if standardConstraints {
let constraint = contentView.heightAnchor.constraint(equalToConstant: 80)
constraint.priority = .defaultLow
constraint.isActive = true
}
molecule = moleculeView molecule = moleculeView
} }
} else { } else {
@ -91,6 +85,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
castView.shouldSetVerticalMargins?(standardConstraints) castView.shouldSetVerticalMargins?(standardConstraints)
} }
backgroundColor = molecule?.backgroundColor backgroundColor = molecule?.backgroundColor
accessibilityElements = molecule?.subviews
} }
public static func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? { public static func name(forReuse molecule: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> String? {

View File

@ -175,13 +175,8 @@ public class MoleculeStackView: ViewConstrainingView {
spacing = json?.optionalCGFloatForKey("spacing") ?? 16 spacing = json?.optionalCGFloatForKey("spacing") ?? 16
// Set the alignment for the stack in the containing view. The json driven value is for the axis direction alignment. // Set the alignment for the stack in the containing view. The json driven value is for the axis direction alignment.
if axis == .vertical { alignHorizontal(ViewConstrainingView.getAlignmentFor(json?.optionalStringForKey("horizontalAlignment"), defaultAlignment: .fill))
alignHorizontal(.fill) alignVertical(ViewConstrainingView.getAlignmentFor(json?.optionalStringForKey("verticalAlignment"), defaultAlignment: .fill))
alignVertical(ViewConstrainingView.getAlignmentFor(json?.optionalStringForKey("alignment"), defaultAlignment: .fill))
} else {
alignHorizontal(ViewConstrainingView.getAlignmentFor(json?.optionalStringForKey("alignment"), defaultAlignment: .fill))
alignVertical(.fill)
}
// Adds the molecules and sets the json. // Adds the molecules and sets the json.
for (index, map) in molecules.enumerated() { for (index, map) in molecules.enumerated() {