pkluz / PKHUD

A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8.
MIT License
3.79k stars 494 forks source link

VoiceOver Accessibility #212

Closed awall1 closed 7 years ago

awall1 commented 7 years ago

Currently, it doesn't seem that there is any compatibility for VoiceOver. I've played with adding these lines into PKHUD, but that's not enough (or always the right) context for each PKHUD type.

init() {
    ...
    self.container.accessibilityLabel = "In progress, please wait."
    UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.container)
}

I've also tried setting the label for each Content View type in HUD, but then the UIAccessibilityPostNotification(...) doesn't work when trying to set the focus on the container.

fileprivate extension UIView {
    fileprivate func setAccessibilityProperties(for content: HUDContentType) {
        self.accessibilityLabel = "Please wait."
        switch content {
        case .success:
            self.accessibilityLabel = "Success!"
        case .error:
            self.accessibilityLabel = "Error!"
        case .image(_),
             .rotatingImage(_):
            self.accessibilityLabel = "Image"
        case .label(let title):
            guard let label = title else { break }
            self.accessibilityLabel = label
        case .labeledSuccess(let title, let subtitle),
             .labeledError(let title, let subtitle),
             .labeledProgress(let title, let subtitle),
             .labeledImage(_, let title, let subtitle),
             .labeledRotatingImage(_, let title, let subtitle):
            guard title != nil || subtitle != nil else { break }
            self.accessibilityLabel = (title ?? "") + "\n" + (subtitle ?? "")
        default:
            self.accessibilityLabel = "In progress, please wait."
        }
    }
}

Suggestions?

awall1 commented 7 years ago

I created the PR: #213 to address this.