From f54d4d757ff4e0d8dc9fc0dde31316d51e4038bf Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 6 Jun 2021 22:31:11 -0400 Subject: [PATCH] Make status attachments VoiceOver accessible --- Tusker/Views/Attachments/AttachmentView.swift | 10 ++++++++++ .../Views/Attachments/AttachmentsContainerView.swift | 6 ++++-- Tusker/Views/Status/BaseStatusTableViewCell.swift | 3 --- Tusker/Views/Status/TimelineStatusTableViewCell.swift | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index 8a41cf61..efb49ab9 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -75,6 +75,9 @@ class AttachmentView: UIImageView, GIFAnimatable { NotificationCenter.default.addObserver(self, selector: #selector(gifPlaybackModeChanged), name: .NSProcessInfoPowerStateDidChange, object: nil) addInteraction(UIContextMenuInteraction(delegate: self)) + + isAccessibilityElement = true + accessibilityTraits = [.image, .button] } @objc private func preferencesChanged() { @@ -293,6 +296,13 @@ class AttachmentView: UIImageView, GIFAnimatable { @objc func imagePressed() { showGallery() } + + // MARK: - Accessibility + + override func accessibilityActivate() -> Bool { + showGallery() + return true + } } diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index 6c7bb080..e8bdc0d7 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -248,9 +248,11 @@ class AttachmentsContainerView: UIView { let attachmentView = AttachmentView(attachment: attachments[index], index: index, expectedSize: size) attachmentView.delegate = delegate attachmentView.translatesAutoresizingMaskIntoConstraints = false - attachmentView.isAccessibilityElement = true - attachmentView.accessibilityTraits = [.image, .button] attachmentView.accessibilityLabel = String(format: NSLocalizedString("Attachment %d", comment: "attachment at index accessiblity label"), index + 1) + attachmentView.accessibilityLabel = "Attachment \(index + 1)" + if let desc = attachments[index].description { + attachmentView.accessibilityLabel! += ", \(desc)" + } attachmentViews.add(attachmentView) return attachmentView } diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 821fd9df..2381d0bb 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -95,7 +95,6 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { collapseButton.layer.cornerRadius = 5 accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!, pollView!] - attachmentsView.isAccessibilityElement = true moreButton.showsMenuAsPrimaryAction = true @@ -157,8 +156,6 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { cardView.navigationDelegate = navigationDelegate attachmentsView.updateUI(status: status) - attachmentsView.isAccessibilityElement = status.attachments.count > 0 - attachmentsView.accessibilityLabel = String(format: NSLocalizedString("%d attachments", comment: "status attachments count accessibility label"), status.attachments.count) updateStatusState(status: status) diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 407cd84b..6027a412 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -219,6 +219,11 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { } set {} } + + override func accessibilityActivate() -> Bool { + didSelectCell() + return true + } }