Minor refactoring

This commit is contained in:
Keerthy 2023-10-30 13:54:48 +05:30
parent 8f002f9422
commit e48db9495d

View File

@ -24,9 +24,9 @@ public class AccessibilityOperation: MVMCoreOperation {
/** /**
This method will post accessibility notification. This method will post accessibility notification.
If we have announcement notification then operation will wait untill announcement is finished.
*/ */
public override func main() { public override func main() {
guard !checkAndHandleForCancellation() else { return }
guard UIAccessibility.isVoiceOverRunning else { guard UIAccessibility.isVoiceOverRunning else {
markAsFinished() markAsFinished()
return return
@ -37,13 +37,7 @@ public class AccessibilityOperation: MVMCoreOperation {
return return
} }
UIAccessibility.post(notification: self.notificationType, argument: self.argument) UIAccessibility.post(notification: self.notificationType, argument: self.argument)
if self.notificationType == .announcement {///Marking task as finished only if announcement did finished so that user will listen complete announcement. self.markAsFinished()
NotificationCenter.default.addObserver(forName: UIAccessibility.announcementDidFinishNotification, object: nil, queue: .main) { _ in
self.markAsFinished()
}
} else {
self.markAsFinished()
}
} }
} }
} }
@ -131,16 +125,12 @@ extension AccessibilityHandler {
/** /**
This method is used to notify rotor handler about page loaded and capturing the accessibilityId if any. This method is used to notify rotor handler about page loaded and capturing the accessibilityId if any.
Will announce text if the page is has announcementText in the response.
*/ */
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) { public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
previousAccessiblityElement = nil previousAccessiblityElement = nil
rotorHandler.onPageNew(rootMolecules: rootMolecules, delegateObject) rotorHandler.onPageNew(rootMolecules: rootMolecules, delegateObject)
guard let loadObject = (delegateObject?.loadDelegate as? MVMCoreViewControllerProtocol)?.loadObject else { return } guard let loadObject = (delegateObject?.loadDelegate as? MVMCoreViewControllerProtocol)?.loadObject else { return }
accessibilityId = loadObject?.pageJSON?.optionalStringForKey("accessibilityId") accessibilityId = loadObject?.pageJSON?.optionalStringForKey("accessibilityId")
if let announcementText = loadObject?.pageJSON?.optionalStringForKey("announcementText") {
post(notification: .announcement, argument: announcementText)
}
self.delegateObject = delegateObject self.delegateObject = delegateObject
} }