removed accessibility notification for webpages.

This commit is contained in:
Krishna Kishore Bandaru 2023-07-26 20:13:08 +05:30
parent 646210f1a3
commit 9bbcd6a8ea

View File

@ -13,7 +13,7 @@ import WebKit
public enum AccessibilityNotificationType: String, Codable {
case controllerChanged, layoutChanged, screenChanged, announcement, webPageChanged, webPageLoaded
case controllerChanged, layoutChanged, screenChanged, announcement
//TODO: - Foucs is shifting to respective element only if we add delay only on new viewcontroller appear. Need to investigate futher.
//https://developer.apple.com/forums/thread/132699,
@ -23,10 +23,6 @@ public enum AccessibilityNotificationType: String, Codable {
switch self {
case .controllerChanged:
return 1.5
case .webPageLoaded:
return 2.0
case .screenChanged, .layoutChanged:
return 0.0
default:
return 0.0
}
@ -40,8 +36,6 @@ public enum AccessibilityNotificationType: String, Codable {
return .screenChanged
case .layoutChanged, .controllerChanged:
return .layoutChanged
case .webPageChanged, .webPageLoaded:
return .layoutChanged
}
}
}
@ -50,15 +44,13 @@ public typealias ArgumentHandler = ((NavigationOperationType?) -> Any?)
public class AccessbilityOperation: MVMCoreOperation {
private let operationType: NavigationOperationType
private let argumentHandler: ArgumentHandler?
private let argument: Any?
private let notificationType: AccessibilityNotificationType
private var timerSource: DispatchSourceTimer?
public init(notificationType: AccessibilityNotificationType, operationType: NavigationOperationType = .default, argumentHandler: ArgumentHandler?) {
public init(notificationType: AccessibilityNotificationType, argument: Any?) {
self.notificationType = notificationType
self.argumentHandler = argumentHandler
self.operationType = operationType
self.argument = argument
}
public override func main() {
@ -70,8 +62,7 @@ public class AccessbilityOperation: MVMCoreOperation {
timerSource?.setEventHandler {
Task { @MainActor [weak self] in
if !(self?.isCancelled ?? false), let notification = self?.notificationType.accessibilityNotification {
print("argumentHandler \(self?.argumentHandler?(self?.operationType))")
UIAccessibility.post(notification: notification, argument: self?.argumentHandler?(self?.operationType))
UIAccessibility.post(notification: notification, argument: self?.argument)
self?.markAsFinished()
} else {
self?.stop()
@ -99,13 +90,13 @@ open class AccessibilityHandler {
}
public weak var delegate: MVMCoreViewControllerProtocol?
public var previousAccessiblityElement: Any?
public var anyCancellable: Set<AnyCancellable> = []
private var accessibilityOperationQueue: OperationQueue = {
let queue = OperationQueue()
queue.maxConcurrentOperationCount = 1
return queue
}()
private var anyCancellable: Set<AnyCancellable> = []
private var accessibilityId: String?
private var announcementText: String?
private var hasTopNotitificationInPage: Bool = false
@ -127,7 +118,7 @@ open class AccessibilityHandler {
}
/// Registers to know when pages change.
private func registerForPageChanges() {
open func registerForPageChanges() {
MVMCoreNavigationHandler.shared()?.addDelegate(self)
}
@ -135,8 +126,6 @@ open class AccessibilityHandler {
//Since foucs shifted to other elements cancelling existing focus shift notifications if any
NotificationCenter.default.publisher(for: UIAccessibility.elementFocusedNotification)
.sink { [weak self] notification in
print("testing \(UIAccessibility.focusedElement(using: .notificationVoiceOver))")
print("testing \(notification.userInfo)")
self?.cancelAllOperations()
}.store(in: &anyCancellable)
}
@ -145,7 +134,7 @@ open class AccessibilityHandler {
NotificationHandler.shared()?.onNotificationWillShow
.sink { [weak self] (_, model) in
self?.hasTopNotitificationInPage = true
self?.capturePreviousFocusElement(for: model.molecule)
self?.capturePreviousFocusElement()
}.store(in: &anyCancellable)
NotificationHandler.shared()?.onNotificationShown
.sink { [weak self] (view, model) in
@ -157,15 +146,15 @@ open class AccessibilityHandler {
}.store(in: &anyCancellable)
NotificationHandler.shared()?.onNotificationDismissed
.sink { [weak self] (view, model) in
self?.postAccessbilityToPrevElement(for: model.molecule)
self?.postAccessbilityToPrevElement()
}.store(in: &anyCancellable)
}
open func capturePreviousFocusElement(for model: MoleculeModelProtocol) {
open func capturePreviousFocusElement() {
previousAccessiblityElement = UIAccessibility.focusedElement(using: .notificationVoiceOver)
}
open func postAccessbilityToPrevElement(for model: MoleculeModelProtocol) {
open func postAccessbilityToPrevElement() {
post(notification: .layoutChanged, argument: previousAccessiblityElement)
}
@ -177,15 +166,9 @@ open class AccessibilityHandler {
accessibilityOperationQueue.cancelAllOperations()
}
open func post(webpageChanged type: AccessibilityNotificationType) {
post(notification: type)
}
public func post(notification type: AccessibilityNotificationType, operationType: NavigationOperationType = .default, argument: Any? = nil) {
public func post(notification type: AccessibilityNotificationType, argument: Any? = nil) {
guard UIAccessibility.isVoiceOverRunning else { return }
let accessbilityOperation = AccessbilityOperation(notificationType: type, operationType: operationType) { [weak self] in
($0 == .tab) ? self?.getFirstFocusedElementOnScreen() : argument
}
let accessbilityOperation = AccessbilityOperation(notificationType: type, argument: argument)
add(operation: accessbilityOperation)
}
@ -204,8 +187,7 @@ extension AccessibilityHandler: MVMCorePresentationDelegateProtocol {
previousAccessiblityElement = nil
delegate = viewController as? MVMCoreViewControllerProtocol
if let announcementText {
let accessbilityOperation = AccessbilityOperation(notificationType: .announcement) { _ in announcementText }
add(operation: accessbilityOperation)
post(notification: .announcement, argument: announcementText)
}
}
@ -213,17 +195,13 @@ extension AccessibilityHandler: MVMCorePresentationDelegateProtocol {
open func navigationController(_ navigationController: UINavigationController, displayedViewController viewController: UIViewController) {
guard UIAccessibility.isVoiceOverRunning,
canPostAccessbilityNotification(for: viewController) else { return }
//TODO: - For Tabbar change: adding 1.5 sec delay to shift focus to the top. for Temp fix added to check on childern count
/*var navigationOperationType: NavigationType = .push
if let presentationStyle = delegate?.loadObject??.pageJSON?.optionalStringForKey(KeyPresentationStyle) ?? delegate?.loadObject??.requestParameters?.actionMap?.optionalStringForKey(KeyPresentationStyle), presentationStyle == "root" {
navigationOperationType = .set
}*/
//TODO: - For Tabbar change: adding 1.5 sec delay to shift focus to the top. for Temp fix added to check on childern count. If we have top notification in page on pageLoad, we have postnotification for shifting the focus so in this case we are not posting accessiblity notifcation
if hasTopNotitificationInPage {
previousAccessiblityElement = getFirstFocusedElementOnScreen()
} else {
let accessbilityElement = getAccessbilityFocusedElement()
let operationType: NavigationOperationType = navigationController.children.count == 1 ? .tab : .default //TODO: - need to identify the operationType
post(notification: operationType == .tab ? .controllerChanged : .layoutChanged, operationType: operationType, argument: accessbilityElement ?? getFirstFocusedElementOnScreen())
post(notification: operationType == .tab ? .controllerChanged : .layoutChanged, argument: accessbilityElement ?? getFirstFocusedElementOnScreen())
accessibilityId = nil
}
}