From 8d7d1e1ebbff2383c6e63fe9e3bfebad6976216c Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Thu, 9 Feb 2023 21:04:51 -0500 Subject: [PATCH] Add accessibility actions to the card --- ...Provider+StatusTableViewCellDelegate.swift | 22 +++++++++---------- .../StatusTableViewCellDelegate.swift | 4 ++-- .../View/Content/NotificationView.swift | 2 +- .../View/Content/StatusCardControl.swift | 16 +++++++++++--- .../MastodonUI/View/Content/StatusView.swift | 4 ++-- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift index 0b4cc3e8f..0ad68d717 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift @@ -182,24 +182,24 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte _ cell: UITableViewCell, statusView: StatusView, cardControlMenu statusCardControl: StatusCardControl - ) -> UIMenu? { + ) -> [LabeledAction]? { guard let card = statusView.viewModel.card, let url = card.url else { return nil } - return UIMenu(children: [ - UIAction( + return [ + LabeledAction( title: L10n.Common.Controls.Actions.copy, image: UIImage(systemName: "doc.on.doc") - ) { _ in + ) { UIPasteboard.general.url = url }, - UIAction( + LabeledAction( title: L10n.Common.Controls.Actions.share, - image: Asset.Arrow.squareAndArrowUp.image.withRenderingMode(.alwaysTemplate) - ) { _ in + asset: Asset.Arrow.squareAndArrowUp + ) { DispatchQueue.main.async { let activityViewController = UIActivityViewController( activityItems: [ @@ -224,10 +224,10 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte } }, - UIAction( + LabeledAction( title: L10n.Common.Controls.Status.Actions.shareLinkInPost, - image: Asset.ObjectsAndTools.squareAndPencil.image.withRenderingMode(.alwaysTemplate) - ) { _ in + asset: Asset.ObjectsAndTools.squareAndPencil + ) { DispatchQueue.main.async { self.coordinator.present( scene: .compose(viewModel: ComposeViewModel( @@ -241,7 +241,7 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte ) } } - ]) + ] } } diff --git a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCellDelegate.swift b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCellDelegate.swift index f21e0573c..b1ffedaee 100644 --- a/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCellDelegate.swift +++ b/Mastodon/Scene/Share/View/TableviewCell/StatusTableViewCellDelegate.swift @@ -38,7 +38,7 @@ protocol StatusTableViewCellDelegate: AnyObject, AutoGenerateProtocolDelegate { func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, statusMetricView: StatusMetricView, reblogButtonDidPressed button: UIButton) func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, statusMetricView: StatusMetricView, favoriteButtonDidPressed button: UIButton) func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, cardControl: StatusCardControl, didTapURL url: URL) - func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, cardControlMenu: StatusCardControl) -> UIMenu? + func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, cardControlMenu: StatusCardControl) -> [LabeledAction]? func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, accessibilityActivate: Void) // sourcery:end } @@ -108,7 +108,7 @@ extension StatusViewDelegate where Self: StatusViewContainerTableViewCell { delegate?.tableViewCell(self, statusView: statusView, cardControl: cardControl, didTapURL: url) } - func statusView(_ statusView: StatusView, cardControlMenu: StatusCardControl) -> UIMenu? { + func statusView(_ statusView: StatusView, cardControlMenu: StatusCardControl) -> [LabeledAction]? { return delegate?.tableViewCell(self, statusView: statusView, cardControlMenu: cardControlMenu) } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift index 9196c340e..9de7b2eb7 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/NotificationView.swift @@ -606,7 +606,7 @@ extension NotificationView: StatusViewDelegate { assertionFailure() } - public func statusView(_ statusView: StatusView, cardControlMenu: StatusCardControl) -> UIMenu? { + public func statusView(_ statusView: StatusView, cardControlMenu: StatusCardControl) -> [LabeledAction]? { assertionFailure() return nil } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift index 1e4acfbf0..dc370811f 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift @@ -16,7 +16,7 @@ import WebKit public protocol StatusCardControlDelegate: AnyObject { func statusCardControl(_ statusCardControl: StatusCardControl, didTapURL url: URL) - func statusCardControlMenu(_ statusCardControl: StatusCardControl) -> UIMenu? + func statusCardControlMenu(_ statusCardControl: StatusCardControl) -> [LabeledAction]? } public final class StatusCardControl: UIControl { @@ -238,6 +238,13 @@ public final class StatusCardControl: UIControl { dividerView.backgroundColor = theme.separator imageView.backgroundColor = UIColor.tertiarySystemFill } + + public override var accessibilityCustomActions: [UIAccessibilityCustomAction]? { + get { + delegate?.statusCardControlMenu(self)?.map(\.accessibilityCustomAction) + } + set {} + } } // MARK: WKWebView delegates @@ -297,8 +304,11 @@ extension StatusCardControl: WKNavigationDelegate, WKUIDelegate { // MARK: UIContextMenuInteractionDelegate extension StatusCardControl { public override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { - return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { elements in - self.delegate?.statusCardControlMenu(self) + return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in + if let elements = self.delegate?.statusCardControlMenu(self)?.map(\.menuElement) { + return UIMenu(children: elements) + } + return nil } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift index 402f1ca42..317f8cddb 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView.swift @@ -34,7 +34,7 @@ public protocol StatusViewDelegate: AnyObject { func statusView(_ statusView: StatusView, statusMetricView: StatusMetricView, reblogButtonDidPressed button: UIButton) func statusView(_ statusView: StatusView, statusMetricView: StatusMetricView, favoriteButtonDidPressed button: UIButton) func statusView(_ statusView: StatusView, cardControl: StatusCardControl, didTapURL url: URL) - func statusView(_ statusView: StatusView, cardControlMenu: StatusCardControl) -> UIMenu? + func statusView(_ statusView: StatusView, cardControlMenu: StatusCardControl) -> [LabeledAction]? // a11y func statusView(_ statusView: StatusView, accessibilityActivate: Void) @@ -758,7 +758,7 @@ extension StatusView: StatusCardControlDelegate { delegate?.statusView(self, cardControl: statusCardControl, didTapURL: url) } - public func statusCardControlMenu(_ statusCardControl: StatusCardControl) -> UIMenu? { + public func statusCardControlMenu(_ statusCardControl: StatusCardControl) -> [LabeledAction]? { delegate?.statusView(self, cardControlMenu: statusCardControl) } }