Announces errors when VoiceOver is enabled

This commit is contained in:
Riley Testut
2020-08-27 15:24:26 -07:00
parent a3a4af182d
commit f02fcad3a0

View File

@@ -31,6 +31,8 @@ class ToastView: RSTToastView
super.init(text: text, detailText: detailedText)
self.isAccessibilityElement = true
self.layoutMargins = UIEdgeInsets(top: 8, left: 16, bottom: 10, right: 16)
self.setNeedsLayout()
@@ -106,6 +108,19 @@ class ToastView: RSTToastView
self.show(in: viewController.navigationController?.view ?? viewController.view, duration: self.preferredDuration)
}
override func show(in view: UIView, duration: TimeInterval)
{
super.show(in: view, duration: duration)
let announcement = (self.textLabel.text ?? "") + ". " + (self.detailTextLabel.text ?? "")
self.accessibilityLabel = announcement
// Minimum 0.75 delay to prevent announcement being cut off by VoiceOver.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.75) {
UIAccessibility.post(notification: .announcement, argument: announcement)
}
}
override func show(in view: UIView)
{
self.show(in: view, duration: self.preferredDuration)