accessibility and page control fixes
This commit is contained in:
parent
8866e91caa
commit
39cb930263
@ -57,6 +57,7 @@ open class Carousel: ViewConstrainingView {
|
||||
collectionView.delegate = self
|
||||
collectionView.showsHorizontalScrollIndicator = false
|
||||
collectionView.backgroundColor = .clear
|
||||
collectionView.isAccessibilityElement = false
|
||||
addSubview(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).
|
||||
loop = true
|
||||
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[1])
|
||||
}
|
||||
@ -140,6 +141,7 @@ open class Carousel: ViewConstrainingView {
|
||||
var pagingView: (UIView & MVMCoreUIPagingProtocol)? = nil
|
||||
if let json = json {
|
||||
pagingView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: json, delegateObject: delegateObject, constrainIfNeeded: true) as? (UIView & MVMCoreUIPagingProtocol)
|
||||
pagingView?.isAccessibilityElement = true
|
||||
}
|
||||
addPaging(view: pagingView, position: (json?.optionalCGFloatForKey("position") ?? 20))
|
||||
}
|
||||
@ -196,7 +198,7 @@ open class Carousel: ViewConstrainingView {
|
||||
}
|
||||
let currentPage = pager.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
|
||||
@ -244,12 +246,27 @@ extension Carousel: UICollectionViewDataSource {
|
||||
protocolCell.setWithJSON(moleculeInfo.molecule, delegateObject: nil, additionalData: nil)
|
||||
protocolCell.updateView(collectionView.bounds.width)
|
||||
}
|
||||
|
||||
if indexPath.row == currentIndex {
|
||||
cell.accessibilityElementsHidden = false
|
||||
// self.accessibilityElements = @[cell.containerView, self.pageControl];
|
||||
} else {
|
||||
cell.accessibilityElementsHidden = true
|
||||
}
|
||||
|
||||
return cell
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
guard loop else {
|
||||
return
|
||||
@ -257,8 +274,7 @@ extension Carousel: UIScrollViewDelegate {
|
||||
|
||||
let lastPageIndex = numberOfPages + 1
|
||||
let goToIndex = {(index: Int) in
|
||||
self.currentIndex = index
|
||||
self.collectionView.scrollToItem(at: IndexPath(row: self.currentIndex, section: 0), at: self.itemAlignment, animated: false)
|
||||
self.goTo(index, animated: false)
|
||||
self.collectionView.layoutIfNeeded()
|
||||
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.
|
||||
if let separatorWidth = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.minimumLineSpacing {
|
||||
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
|
||||
if index < 0 {
|
||||
if index < 1 {
|
||||
self.currentIndex = 0
|
||||
} else if index > lastCellIndex {
|
||||
} else if index > CGFloat(lastCellIndex - 1) {
|
||||
self.currentIndex = lastCellIndex
|
||||
}
|
||||
}
|
||||
@ -326,9 +342,7 @@ extension Carousel: UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
// Cap the index.
|
||||
currentIndex = min(max(cellToSwipeTo, 0), lastCellIndex)
|
||||
|
||||
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: itemAlignment, animated: true)
|
||||
goTo(min(max(cellToSwipeTo, 0), lastCellIndex), animated: true)
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
showPeaking(true)
|
||||
|
||||
//UIAccessibility.post(notification: .layoutChanged, argument: currentIndex) UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,currentCell.containerView);
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ static CGFloat const IndicatorRectangleHeight = 4;
|
||||
|
||||
#pragma mark - MVMCoreUIPagingProtocol
|
||||
|
||||
- (void)setPage:(NSUInteger)page {
|
||||
- (void)setPage:(NSInteger)page {
|
||||
self.currentPage = page;
|
||||
}
|
||||
|
||||
@ -349,6 +349,7 @@ static CGFloat const IndicatorRectangleHeight = 4;
|
||||
if ((index < self.numberOfPages && index >= 0) || self.alwaysSendingControlEvent) {
|
||||
[self setCurrentPage:index animated:NO];
|
||||
[self sendActionsForControlEvents:UIControlEventValueChanged];
|
||||
self.pagingTouchBlock(self);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,9 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
|
||||
guard peakingCover.superview == nil else {
|
||||
return
|
||||
}
|
||||
isAccessibilityElement = false
|
||||
contentView.isAccessibilityElement = false
|
||||
|
||||
// Covers the card when peaking.
|
||||
peakingCover.backgroundColor = .white
|
||||
peakingCover.alpha = 0
|
||||
@ -109,7 +112,6 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
|
||||
self.peakingRightArrow.alpha = peaking ? 1 : 0
|
||||
self.peakingLeftArrow.alpha = peaking ? 1 : 0
|
||||
self.peakingCover.alpha = peaking ? 0.5 : 0
|
||||
print("\(self.peakingCover.alpha)")
|
||||
}
|
||||
if animated {
|
||||
UIView.animate(withDuration: 0.4, animations: animation)
|
||||
|
||||
@ -40,6 +40,9 @@
|
||||
"AccOn" = "on";
|
||||
"AccOff" = "off";
|
||||
"AccToggleHint" = "double tap to toggle";
|
||||
// Carousel
|
||||
"MVMCoreUIPageControl_currentpage_index" = "page %ld of %ld";
|
||||
"MVMCoreUIPageControlslides_currentpage_index" = "slide %ld of %ld";
|
||||
//Styler
|
||||
"CountDownDay" = " day";
|
||||
"CountDownHour" = " hour";
|
||||
|
||||
@ -39,6 +39,9 @@
|
||||
"AccOn" = "encendido";
|
||||
"AccOff" = "apagado";
|
||||
"AccToggleHint" = "toca dos veces para alternar";
|
||||
// Carousel
|
||||
"MVMCoreUIPageControl_currentpage_index" = "página %ld de %ld";
|
||||
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %ld of %ld";
|
||||
//Styler
|
||||
"CountDownDay" = " día";
|
||||
"CountDownHour" = " hora";
|
||||
|
||||
@ -39,6 +39,9 @@
|
||||
"AccOn" = "encendido";
|
||||
"AccOff" = "apagado";
|
||||
"AccToggleHint" = "toca dos veces para alternar";
|
||||
// Carousel
|
||||
"MVMCoreUIPageControl_currentpage_index" = "página %ld de %ld";
|
||||
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %ld of %ld";
|
||||
//Styler
|
||||
"CountDownDay" = " día";
|
||||
"CountDownHour" = " hora";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user