Add accessibility actions for opening attachments

This commit is contained in:
Justin Mazzocchi 2021-03-20 14:22:04 -07:00
parent eb57176a8f
commit 1f21c3fe3f
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
3 changed files with 19 additions and 6 deletions

View File

@ -97,6 +97,10 @@ extension AttachmentView {
playerView.player = nil playerView.player = nil
playerView.isHidden = true playerView.isHidden = true
} }
func selectAttachment() {
parentViewModel.attachmentSelected(viewModel: viewModel)
}
} }
private extension AttachmentView { private extension AttachmentView {
@ -136,11 +140,7 @@ private extension AttachmentView {
selectionButton.translatesAutoresizingMaskIntoConstraints = false selectionButton.translatesAutoresizingMaskIntoConstraints = false
selectionButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted) selectionButton.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
selectionButton.addAction( selectionButton.addAction(
UIAction { [weak self] _ in UIAction { [weak self] _ in self?.selectAttachment() },
guard let self = self else { return }
self.parentViewModel.attachmentSelected(viewModel: self.viewModel)
},
for: .touchUpInside) for: .touchUpInside)
selectionButton.accessibilityLabel = NSLocalizedString("compose.attachment.edit", comment: "") selectionButton.accessibilityLabel = NSLocalizedString("compose.attachment.edit", comment: "")

View File

@ -131,6 +131,18 @@ extension AttachmentsView {
return viewModel.attachmentViewModels.allSatisfy(\.shouldAutoplay) 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 { private extension AttachmentsView {

View File

@ -88,7 +88,8 @@ final class StatusBodyView: UIView {
}) })
} }
self.accessibilityCustomActions = accessibilityCustomActions self.accessibilityCustomActions =
accessibilityCustomActions + attachmentsView.attachmentViewAccessibilityCustomActions
} }
} }