diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift index 22491a49..359be549 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/CollapsableNotification.swift @@ -128,6 +128,8 @@ import MVMCore MVMCoreDispatchUtility.performBlock(onMainThread: { if MVMCoreUIUtility.viewContainsAccessiblityFocus(self) { NotificationCenter.default.addObserver(self, selector: #selector(self.accessibilityFocusChanged(notification:)), name: UIAccessibility.elementFocusedNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(self.accessibilityFocusChanged(notification:)), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil) + } else { self.collapse() } @@ -202,8 +204,9 @@ import MVMCore /// Collapse if focus is no longer on this top alert. @objc func accessibilityFocusChanged(notification: Notification) { - if (notification.userInfo?[UIAccessibility.focusedElementUserInfoKey] != nil) && !MVMCoreUIUtility.viewContainsAccessiblityFocus(self) { + if !UIAccessibility.isVoiceOverRunning || ((notification.userInfo?[UIAccessibility.focusedElementUserInfoKey] != nil) && !MVMCoreUIUtility.viewContainsAccessiblityFocus(self)) { NotificationCenter.default.removeObserver(self, name: UIAccessibility.elementFocusedNotification, object: nil) + NotificationCenter.default.removeObserver(self, name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil) collapse() } } diff --git a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift index f05ffc26..c731f6d6 100644 --- a/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift +++ b/MVMCoreUI/Atomic/Molecules/TopNotification/NotificationMoleculeView.swift @@ -77,6 +77,7 @@ import Foundation NotificationMoleculeView.amendAccesibilityLabel(for: headline) NotificationMoleculeView.amendAccesibilityLabel(for: body) NotificationMoleculeView.amendAccesibilityLabel(for: button) + NotificationMoleculeView.amendAccesibilityLabel(for: closeButton) } /// Formats the accessibilityLabel so voice over users know it's in the notification. diff --git a/MVMCoreUI/Notification/NotificationHandler.swift b/MVMCoreUI/Notification/NotificationHandler.swift index ea0c7781..d79d7ebb 100644 --- a/MVMCoreUI/Notification/NotificationHandler.swift +++ b/MVMCoreUI/Notification/NotificationHandler.swift @@ -224,6 +224,7 @@ public class NotificationOperation: MVMCoreOperation { // If voice over is on and the notification is focused, do not collapse until unfocused. guard !MVMCoreUIUtility.viewContainsAccessiblityFocus(notification) else { NotificationCenter.default.addObserver(self, selector: #selector(accessibilityFocusChanged), name: UIAccessibility.elementFocusedNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(accessibilityFocusChanged), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil) return } self.stop() @@ -237,10 +238,20 @@ public class NotificationOperation: MVMCoreOperation { /// If the voice over user leaves top alert focus, hide. @objc func accessibilityFocusChanged(_ notification: NSNotification) { + guard UIAccessibility.isVoiceOverRunning else { + accessibilityFocusFinished() + return + } guard let _ = notification.userInfo?[UIAccessibility.focusedElementUserInfoKey], !MVMCoreUIUtility.viewContainsAccessiblityFocus(self.notification) else { return } - self.log(message: "Operation Accessibility Focus Removed") + accessibilityFocusFinished() + } + + /// Dismisses the nofitication when we lose focus. + private func accessibilityFocusFinished() { + log(message: "Operation Accessibility Focus Removed") NotificationCenter.default.removeObserver(self, name: UIAccessibility.elementFocusedNotification, object: nil) + NotificationCenter.default.removeObserver(self, name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil) stop() }