From a18152f6b95763c664bc1e19087ea8a630a3a885 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jul 2020 12:18:34 -0400 Subject: [PATCH] status observer for accessibility changes --- MVMCoreUI/Atomic/Organisms/Carousel.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MVMCoreUI/Atomic/Organisms/Carousel.swift b/MVMCoreUI/Atomic/Organisms/Carousel.swift index 4fb7b413..6cc67d4e 100644 --- a/MVMCoreUI/Atomic/Organisms/Carousel.swift +++ b/MVMCoreUI/Atomic/Organisms/Carousel.swift @@ -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?