From 1f21c3fe3fbe6ee65738cf3ba82d774af20f00e1 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 20 Mar 2021 14:22:04 -0700 Subject: [PATCH] Add accessibility actions for opening attachments --- Views/UIKit/AttachmentView.swift | 10 +++++----- Views/UIKit/AttachmentsView.swift | 12 ++++++++++++ Views/UIKit/StatusBodyView.swift | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Views/UIKit/AttachmentView.swift b/Views/UIKit/AttachmentView.swift index 6da67f2..b9ea517 100644 --- a/Views/UIKit/AttachmentView.swift +++ b/Views/UIKit/AttachmentView.swift @@ -97,6 +97,10 @@ extension AttachmentView { playerView.player = nil playerView.isHidden = true } + + func selectAttachment() { + parentViewModel.attachmentSelected(viewModel: viewModel) + } } private extension AttachmentView { @@ -136,11 +140,7 @@ private extension AttachmentView { selectionButton.translatesAutoresizingMaskIntoConstraints = false selectionButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted) selectionButton.addAction( - UIAction { [weak self] _ in - guard let self = self else { return } - - self.parentViewModel.attachmentSelected(viewModel: self.viewModel) - }, + UIAction { [weak self] _ in self?.selectAttachment() }, for: .touchUpInside) selectionButton.accessibilityLabel = NSLocalizedString("compose.attachment.edit", comment: "") diff --git a/Views/UIKit/AttachmentsView.swift b/Views/UIKit/AttachmentsView.swift index 515f346..2c9e50d 100644 --- a/Views/UIKit/AttachmentsView.swift +++ b/Views/UIKit/AttachmentsView.swift @@ -131,6 +131,18 @@ extension AttachmentsView { return viewModel.attachmentViewModels.allSatisfy(\.shouldAutoplay) } + + var attachmentViewAccessibilityCustomActions: [UIAccessibilityCustomAction] { + attachmentViews.compactMap { attachmentView in + guard let accessibilityLabel = attachmentView.accessibilityLabel else { return nil } + + return UIAccessibilityCustomAction(name: accessibilityLabel) { _ in + attachmentView.selectAttachment() + + return true + } + } + } } private extension AttachmentsView { diff --git a/Views/UIKit/StatusBodyView.swift b/Views/UIKit/StatusBodyView.swift index d7eb57d..5f3e6de 100644 --- a/Views/UIKit/StatusBodyView.swift +++ b/Views/UIKit/StatusBodyView.swift @@ -88,7 +88,8 @@ final class StatusBodyView: UIView { }) } - self.accessibilityCustomActions = accessibilityCustomActions + self.accessibilityCustomActions = + accessibilityCustomActions + attachmentsView.attachmentViewAccessibilityCustomActions } }