diff --git a/MVMCoreUI/Accessibility/AccessibilityHandler.swift b/MVMCoreUI/Accessibility/AccessibilityHandler.swift index 2cfcf4a9..65ae8272 100644 --- a/MVMCoreUI/Accessibility/AccessibilityHandler.swift +++ b/MVMCoreUI/Accessibility/AccessibilityHandler.swift @@ -53,12 +53,14 @@ open class AccessibilityHandler { guard let shared = CoreUIObject.sharedInstance()?.accessibilityHandler else { return nil } return MVMCoreActionUtility.fatalClassCheck(object: shared) } + //TODO: Revisit to avoid state properties to store in handler. public var accessibilityId: String? ///This property is used to post accessibility to the UIElement mapped to this accessibilityId public var previousAccessiblityElement: Any? ///This property is capture accessiblity element public var anyCancellable: Set = [] - public weak var delegate: MVMCoreViewControllerProtocol? { delegateObject?.loadDelegate as? MVMCoreViewControllerProtocol } + public weak var currentController: UIViewController? { MVMCoreUIUtility.getCurrentVisibleController() } public var delegateObject: MVMCoreUIDelegateObject? - private var hasTopNotificationInPage: Bool { delegate?.loadObject??.responseJSON?.optionalDictionaryForKey("TopNotification") != nil || delegate?.loadObject??.responseInfoMap?.optionalStringForKey("messageStyle") != nil } + //TODO: Revisit to identify the page has top notification or not. + private var hasTopNotificationInPage: Bool { (currentController as? MVMCoreViewControllerProtocol)?.loadObject??.responseJSON?.optionalDictionaryForKey("TopNotification") != nil || (currentController as? MVMCoreViewControllerProtocol)?.loadObject??.responseInfoMap?.optionalStringForKey("messageStyle") != nil } private let accessibilityOperationQueue: OperationQueue = { let queue = OperationQueue() queue.maxConcurrentOperationCount = 1 @@ -103,7 +105,7 @@ open class AccessibilityHandler { If navigationBar is hidden then we are returning nil so that voice over will shift to the first interactive element. */ open func getFirstFocusedElementOnScreen() -> Any? { - ((delegate as? PageProtocol)?.pageModel?.navigationBar?.hidden ?? false) ? nil : (delegate as? UIViewController)?.navigationController?.navigationBar + ((currentController as? PageProtocol)?.pageModel?.navigationBar?.hidden ?? false) ? nil : currentController?.navigationController?.navigationBar } /** @@ -115,7 +117,7 @@ open class AccessibilityHandler { This method is used to identify the UIElement that is mapped to accessibilityId from server response. */ func getPreDefinedFocusedElementIfAny() -> UIView? { - guard let accessibilityId, let view = (delegate as? UIViewController)?.view else { return nil } + guard let accessibilityId, let view = currentController?.view else { return nil } return MVMCoreUIUtility.findViews(by: MoleculeViewProtocol.self, views: [view]).first { $0.model?.id == accessibilityId }