status observer for accessibility changes

This commit is contained in:
Pfeil, Scott Robert 2020-07-09 12:18:34 -04:00
parent 4469387e4d
commit a18152f6b9

View File

@ -114,6 +114,9 @@ open class Carousel: View {
if UIAccessibility.isVoiceOverRunning {
collectionView.isScrollEnabled = false
}
// Listen for accessibility changes
NotificationCenter.default.addObserver(self, selector: #selector(accessibilityStatusChanged(_:)), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)
}
open override func updateView(_ size: CGFloat) {
@ -191,6 +194,8 @@ open class Carousel: View {
molecules?.insert(contentsOf: newMolecules.suffix(2), at: 0)
molecules?.append(contentsOf: newMolecules.prefix(2))
} else {
loop = false
}
pageIndex = 0
@ -306,6 +311,15 @@ open class Carousel: View {
}
}
/// Resets view
@objc private func accessibilityStatusChanged(_ sender: Notification) {
// Fixes defects where it scrolls when it shouldn't with voiceover
collectionView.isScrollEnabled = !UIAccessibility.isVoiceOverRunning
if let model = model {
set(with: model, delegateObject, nil)
}
}
/// Accessibility element that allows for adjustable carousel.
private var carouselAccessibilityElement: CarouselAccessibilityElement?