notification register for voice over off
This commit is contained in:
parent
a72fa2af2a
commit
5324869f0b
@ -128,6 +128,8 @@ import MVMCore
|
|||||||
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
MVMCoreDispatchUtility.performBlock(onMainThread: {
|
||||||
if MVMCoreUIUtility.viewContainsAccessiblityFocus(self) {
|
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.elementFocusedNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(self.accessibilityFocusChanged(notification:)), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self.collapse()
|
self.collapse()
|
||||||
}
|
}
|
||||||
@ -202,8 +204,9 @@ import MVMCore
|
|||||||
|
|
||||||
/// Collapse if focus is no longer on this top alert.
|
/// Collapse if focus is no longer on this top alert.
|
||||||
@objc func accessibilityFocusChanged(notification: Notification) {
|
@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.elementFocusedNotification, object: nil)
|
||||||
|
NotificationCenter.default.removeObserver(self, name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)
|
||||||
collapse()
|
collapse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,6 +77,7 @@ import Foundation
|
|||||||
NotificationMoleculeView.amendAccesibilityLabel(for: headline)
|
NotificationMoleculeView.amendAccesibilityLabel(for: headline)
|
||||||
NotificationMoleculeView.amendAccesibilityLabel(for: body)
|
NotificationMoleculeView.amendAccesibilityLabel(for: body)
|
||||||
NotificationMoleculeView.amendAccesibilityLabel(for: button)
|
NotificationMoleculeView.amendAccesibilityLabel(for: button)
|
||||||
|
NotificationMoleculeView.amendAccesibilityLabel(for: closeButton)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats the accessibilityLabel so voice over users know it's in the notification.
|
/// Formats the accessibilityLabel so voice over users know it's in the notification.
|
||||||
|
|||||||
@ -224,6 +224,7 @@ public class NotificationOperation: MVMCoreOperation {
|
|||||||
// If voice over is on and the notification is focused, do not collapse until unfocused.
|
// If voice over is on and the notification is focused, do not collapse until unfocused.
|
||||||
guard !MVMCoreUIUtility.viewContainsAccessiblityFocus(notification) else {
|
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.elementFocusedNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(accessibilityFocusChanged), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.stop()
|
self.stop()
|
||||||
@ -237,10 +238,20 @@ public class NotificationOperation: MVMCoreOperation {
|
|||||||
|
|
||||||
/// If the voice over user leaves top alert focus, hide.
|
/// If the voice over user leaves top alert focus, hide.
|
||||||
@objc func accessibilityFocusChanged(_ notification: NSNotification) {
|
@objc func accessibilityFocusChanged(_ notification: NSNotification) {
|
||||||
|
guard UIAccessibility.isVoiceOverRunning else {
|
||||||
|
accessibilityFocusFinished()
|
||||||
|
return
|
||||||
|
}
|
||||||
guard let _ = notification.userInfo?[UIAccessibility.focusedElementUserInfoKey],
|
guard let _ = notification.userInfo?[UIAccessibility.focusedElementUserInfoKey],
|
||||||
!MVMCoreUIUtility.viewContainsAccessiblityFocus(self.notification) else { return }
|
!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.elementFocusedNotification, object: nil)
|
||||||
|
NotificationCenter.default.removeObserver(self, name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)
|
||||||
stop()
|
stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user