added delay only for tabbar change & added webPageChanged notificationtype

This commit is contained in:
Krishna Kishore Bandaru 2023-07-06 16:53:59 +05:30
parent fedd056175
commit 49ba311d26

View File

@ -8,10 +8,11 @@
import Foundation
import Combine
import MVMCore
public enum AccessibilityNotificationType {
public enum AccessibilityNotificationType: String, Codable {
case controllerChanged, layoutChanged, screenChanged, announcement
case controllerChanged, layoutChanged, screenChanged, announcement, webPageChanged
//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,
@ -36,6 +37,8 @@ public enum AccessibilityNotificationType {
return .screenChanged
case .layoutChanged, .controllerChanged:
return .layoutChanged
case .webPageChanged:
return .layoutChanged
}
}
}
@ -94,14 +97,13 @@ open class AccessibilityHandler {
private var anyCancellable: Set<AnyCancellable> = []
private weak var delegate: MVMCoreViewControllerProtocol?
private var accessibilityId: String?
private var operationType: UINavigationController.Operation?
private var previousAccessiblityElement: Any?
public init() {
registerWithNotificationCenter()
registerForPageChanges()
registerForFocusChanges()
// registerForTopNotificationsChanges()
registerForTopNotificationsChanges()
registerForWebpageNavigation()
}
@ -141,7 +143,7 @@ open class AccessibilityHandler {
private func registerForWebpageNavigation() {
webPageNavigated.sink { [weak self] _ in
self?.post(notification: .controllerChanged, argument: self?.getFirstFocusedElementOnScreen())
self?.post(notification: .layoutChanged, argument: self?.getFirstFocusedElementOnScreen())
}.store(in: &anyCancellable)
}
@ -153,7 +155,7 @@ open class AccessibilityHandler {
accessibilityOperationQueue.cancelAllOperations()
}
public func post(notification type: AccessibilityNotificationType, argument: Any?) {
public func post(notification type: AccessibilityNotificationType, argument: Any? = nil) {
guard UIAccessibility.isVoiceOverRunning else { return }
let accessbilityOperation = AccessbilityOperation(notificationType: type, argument: argument)
add(operation: accessbilityOperation)
@ -168,16 +170,17 @@ extension AccessibilityHandler: MVMCorePresentationDelegateProtocol {
public func navigationController(_ navigationController: UINavigationController, prepareDisplayFor viewController: UIViewController) {
delegate = viewController as? MVMCoreViewControllerProtocol
operationType = navigationController.viewControllers.contains(viewController) ? .pop : .push
}
public func navigationController(_ navigationController: UINavigationController, displayedViewController viewController: UIViewController) {
//TODO: - For push operation we are posting accessibility notification to the top left item or the identified accessibility element from pageJSON. Need to check the logic for pop operation
guard UIAccessibility.isVoiceOverRunning,
operationType == .push,
canPostAccessbilityNotification(for: viewController) else { return }
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.
}
let accessbilityElement = getAccessbilityFocusedElement()
post(notification: .controllerChanged, argument: accessbilityElement ?? getFirstFocusedElementOnScreen())
post(notification: navigationOperationType == .set ? .controllerChanged : .layoutChanged, argument: accessbilityElement ?? getFirstFocusedElementOnScreen())
}
}
@ -190,7 +193,6 @@ extension AccessibilityHandler {
return nil
}
return (delegate as? UIViewController)?.view?.getMoleculeViews { (subView: MoleculeViewProtocol) in
print("subview: \(subView)")
guard let moleculeModel = (subView as? MoleculeViewModelProtocol)?.getMoleculeModel() as? (any AccessibilityElementProtocol),
moleculeModel.id == (accessibilityModel as? (any AccessibilityElementProtocol))?.id else {
return false