Add accessibility actions to the card

This commit is contained in:
Jed Fox 2023-02-09 21:04:51 -05:00
parent 5ac5392107
commit 8d7d1e1ebb
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
5 changed files with 29 additions and 19 deletions

View File

@ -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
)
}
}
])
]
}
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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)
}
}