accessibility and page control fixes

This commit is contained in:
Pfeil, Scott Robert 2019-07-12 10:25:42 -04:00
parent 8866e91caa
commit 39cb930263
6 changed files with 40 additions and 12 deletions

View File

@ -57,6 +57,7 @@ open class Carousel: ViewConstrainingView {
collectionView.delegate = self collectionView.delegate = self
collectionView.showsHorizontalScrollIndicator = false collectionView.showsHorizontalScrollIndicator = false
collectionView.backgroundColor = .clear collectionView.backgroundColor = .clear
collectionView.isAccessibilityElement = false
addSubview(collectionView) addSubview(collectionView)
pinView(toSuperView: collectionView) pinView(toSuperView: collectionView)
@ -117,7 +118,7 @@ open class Carousel: ViewConstrainingView {
// Sets up the row data with buffer cells on each side (for illusion of endless scroll... also has one more buffer cell on each side in case we can peek that cell). // Sets up the row data with buffer cells on each side (for illusion of endless scroll... also has one more buffer cell on each side in case we can peek that cell).
loop = true loop = true
molecules?.insert(newMolecules.last!, at: 0) molecules?.insert(newMolecules.last!, at: 0)
molecules?.insert(newMolecules[(newMolecules.count - 1)], at: 0) molecules?.insert(newMolecules[(newMolecules.count - 2)], at: 0)
molecules?.append(newMolecules.first!) molecules?.append(newMolecules.first!)
molecules?.append(newMolecules[1]) molecules?.append(newMolecules[1])
} }
@ -140,6 +141,7 @@ 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))
} }
@ -196,7 +198,7 @@ open class Carousel: ViewConstrainingView {
} }
let currentPage = pager.currentPage() let currentPage = pager.currentPage()
localSelf.pageIndex = currentPage localSelf.pageIndex = currentPage
self?.collectionView.scrollToItem(at: IndexPath(row: localSelf.currentIndex, section: 0), at: (self?.itemAlignment ?? .left), animated: true) localSelf.goTo(localSelf.currentIndex, animated: !UIAccessibility.isVoiceOverRunning)
}) })
} }
self.pagingView = pagingView self.pagingView = pagingView
@ -245,11 +247,26 @@ extension Carousel: UICollectionViewDataSource {
protocolCell.updateView(collectionView.bounds.width) protocolCell.updateView(collectionView.bounds.width)
} }
if indexPath.row == currentIndex {
cell.accessibilityElementsHidden = false
// self.accessibilityElements = @[cell.containerView, self.pageControl];
} else {
cell.accessibilityElementsHidden = true
}
return cell return cell
} }
} }
extension Carousel: UIScrollViewDelegate { extension Carousel: UIScrollViewDelegate {
func goTo(_ index: Int, animated: Bool) {
collectionView.cellForItem(at: IndexPath(row: self.currentIndex, section: 0))?.accessibilityElementsHidden = true
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)
}
func handleUserOnBufferCell() { func handleUserOnBufferCell() {
guard loop else { guard loop else {
return return
@ -257,8 +274,7 @@ extension Carousel: UIScrollViewDelegate {
let lastPageIndex = numberOfPages + 1 let lastPageIndex = numberOfPages + 1
let goToIndex = {(index: Int) in let goToIndex = {(index: Int) in
self.currentIndex = index self.goTo(index, animated: false)
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false)
self.collectionView.layoutIfNeeded() self.collectionView.layoutIfNeeded()
self.pagingView?.setPage(self.pageIndex) self.pagingView?.setPage(self.pageIndex)
} }
@ -279,11 +295,11 @@ extension Carousel: UIScrollViewDelegate {
// Checks if the user is not paging but attempting to drag endlessly and goes out of bounds. Caps the index. // Checks if the user is not paging but attempting to drag endlessly and goes out of bounds. Caps the index.
if let separatorWidth = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing { if let separatorWidth = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing {
let itemWidth = collectionView.bounds.width * itemWidthPercent let itemWidth = collectionView.bounds.width * itemWidthPercent
let index = Int(scrollView.contentOffset.x / (itemWidth + separatorWidth)) let index = scrollView.contentOffset.x / (itemWidth + separatorWidth)
let lastCellIndex = collectionView(collectionView, numberOfItemsInSection: 0) - 1 let lastCellIndex = collectionView(collectionView, numberOfItemsInSection: 0) - 1
if index < 0 { if index < 1 {
self.currentIndex = 0 self.currentIndex = 0
} else if index > lastCellIndex { } else if index > CGFloat(lastCellIndex - 1) {
self.currentIndex = lastCellIndex self.currentIndex = lastCellIndex
} }
} }
@ -326,9 +342,7 @@ extension Carousel: UIScrollViewDelegate {
} }
// Cap the index. // Cap the index.
currentIndex = min(max(cellToSwipeTo, 0), lastCellIndex) goTo(min(max(cellToSwipeTo, 0), lastCellIndex), animated: true)
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: true)
} }
// To give the illusion of endless scrolling. Since we are always calling scrollToItem we can assume finished paging in here. // To give the illusion of endless scrolling. Since we are always calling scrollToItem we can assume finished paging in here.
@ -339,5 +353,7 @@ 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

@ -302,7 +302,7 @@ static CGFloat const IndicatorRectangleHeight = 4;
#pragma mark - MVMCoreUIPagingProtocol #pragma mark - MVMCoreUIPagingProtocol
- (void)setPage:(NSUInteger)page { - (void)setPage:(NSInteger)page {
self.currentPage = page; self.currentPage = page;
} }
@ -349,6 +349,7 @@ static CGFloat const IndicatorRectangleHeight = 4;
if ((index < self.numberOfPages && index >= 0) || self.alwaysSendingControlEvent) { if ((index < self.numberOfPages && index >= 0) || self.alwaysSendingControlEvent) {
[self setCurrentPage:index animated:NO]; [self setCurrentPage:index animated:NO];
[self sendActionsForControlEvents:UIControlEventValueChanged]; [self sendActionsForControlEvents:UIControlEventValueChanged];
self.pagingTouchBlock(self);
} }
} }

View File

@ -30,6 +30,9 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
guard peakingCover.superview == nil else { guard peakingCover.superview == nil else {
return return
} }
isAccessibilityElement = false
contentView.isAccessibilityElement = false
// Covers the card when peaking. // Covers the card when peaking.
peakingCover.backgroundColor = .white peakingCover.backgroundColor = .white
peakingCover.alpha = 0 peakingCover.alpha = 0
@ -109,7 +112,6 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
self.peakingRightArrow.alpha = peaking ? 1 : 0 self.peakingRightArrow.alpha = peaking ? 1 : 0
self.peakingLeftArrow.alpha = peaking ? 1 : 0 self.peakingLeftArrow.alpha = peaking ? 1 : 0
self.peakingCover.alpha = peaking ? 0.5 : 0 self.peakingCover.alpha = peaking ? 0.5 : 0
print("\(self.peakingCover.alpha)")
} }
if animated { if animated {
UIView.animate(withDuration: 0.4, animations: animation) UIView.animate(withDuration: 0.4, animations: animation)

View File

@ -40,6 +40,9 @@
"AccOn" = "on"; "AccOn" = "on";
"AccOff" = "off"; "AccOff" = "off";
"AccToggleHint" = "double tap to toggle"; "AccToggleHint" = "double tap to toggle";
// Carousel
"MVMCoreUIPageControl_currentpage_index" = "page %ld of %ld";
"MVMCoreUIPageControlslides_currentpage_index" = "slide %ld of %ld";
//Styler //Styler
"CountDownDay" = " day"; "CountDownDay" = " day";
"CountDownHour" = " hour"; "CountDownHour" = " hour";

View File

@ -39,6 +39,9 @@
"AccOn" = "encendido"; "AccOn" = "encendido";
"AccOff" = "apagado"; "AccOff" = "apagado";
"AccToggleHint" = "toca dos veces para alternar"; "AccToggleHint" = "toca dos veces para alternar";
// Carousel
"MVMCoreUIPageControl_currentpage_index" = "página %ld de %ld";
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %ld of %ld";
//Styler //Styler
"CountDownDay" = " día"; "CountDownDay" = " día";
"CountDownHour" = " hora"; "CountDownHour" = " hora";

View File

@ -39,6 +39,9 @@
"AccOn" = "encendido"; "AccOn" = "encendido";
"AccOff" = "apagado"; "AccOff" = "apagado";
"AccToggleHint" = "toca dos veces para alternar"; "AccToggleHint" = "toca dos veces para alternar";
// Carousel
"MVMCoreUIPageControl_currentpage_index" = "página %ld de %ld";
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %ld of %ld";
//Styler //Styler
"CountDownDay" = " día"; "CountDownDay" = " día";
"CountDownHour" = " hora"; "CountDownHour" = " hora";