From 92ff900bc0045fa718a3bab23255125a354e2c36 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 5 Feb 2023 13:56:48 -0500 Subject: [PATCH] Improve VoiceOver labels for notifications Closes #350 --- .../NotificationsTableViewController.swift | 1 + ...ActionNotificationGroupTableViewCell.swift | 25 +++++++++++++++++++ ...FollowNotificationGroupTableViewCell.swift | 16 ++++++++++++ ...llowRequestNotificationTableViewCell.swift | 23 +++++++++++++++++ .../PollFinishedTableViewCell.swift | 19 ++++++++++++++ ...atusUpdatedNotificationTableViewCell.swift | 16 ++++++++++++ 6 files changed, 100 insertions(+) diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index 7e114f25..b6b0672c 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -296,6 +296,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController< completion(true) } } + dismissAction.accessibilityLabel = "Dismiss Notification" dismissAction.image = UIImage(systemName: "clear.fill") let cellConfiguration = (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration() diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift index f8f0e1b2..53d29537 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift @@ -221,6 +221,31 @@ class ActionNotificationGroupTableViewCell: UITableViewCell { updateTimestampWorkItem?.cancel() updateTimestampWorkItem = nil } + + // MARK: Accessibility + + override var accessibilityLabel: String? { + get { + let first = group.notifications.first! + var str = "" + switch group.kind { + case .favourite: + str += "Favorited by " + case .reblog: + str += "Reblogged by " + default: + return nil + } + str += first.account.displayNameWithoutCustomEmoji + if group.notifications.count > 1 { + str += " and \(group.notifications.count - 1) more" + } + str += ", \(first.createdAt.formatted(.relative(presentation: .numeric))), " + str += statusContentLabel.text ?? "" + return str + } + set {} + } } diff --git a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift index c7fc1f63..f7fe1518 100644 --- a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift @@ -185,6 +185,22 @@ class FollowNotificationGroupTableViewCell: UITableViewCell { updateTimestampWorkItem?.cancel() updateTimestampWorkItem = nil } + + // MARK: Accessibility + + override var accessibilityLabel: String? { + get { + let first = group.notifications.first! + var str = "Followed by " + str += first.account.displayNameWithoutCustomEmoji + if group.notifications.count > 1 { + str += " and \(group.notifications.count - 1) more" + } + str += ", \(first.createdAt.formatted(.relative(presentation: .numeric)))" + return str + } + set {} + } } diff --git a/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift b/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift index aa7877c4..e5632e1b 100644 --- a/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift @@ -135,6 +135,29 @@ class FollowRequestNotificationTableViewCell: UITableViewCell { self.stackView.addArrangedSubview(label) } + // MARK: Accessibility + + override var accessibilityLabel: String? { + get { + guard let notification else { return nil } + var str = "Follow requested by " + str += notification.account.displayNameWithoutCustomEmoji + str += ", \(notification.createdAt.formatted(.relative(presentation: .numeric)))" + return str + } + set {} + } + + override var accessibilityCustomActions: [UIAccessibilityCustomAction]? { + get { + return [ + UIAccessibilityCustomAction(name: "Accept Request", target: self, selector: #selector(acceptButtonPressed)), + UIAccessibilityCustomAction(name: "Reject Request", target: self, selector: #selector(acceptButtonPressed)), + ] + } + set {} + } + // MARK: - Interaction @IBAction func rejectButtonPressed() { diff --git a/Tusker/Views/Notifications/PollFinishedTableViewCell.swift b/Tusker/Views/Notifications/PollFinishedTableViewCell.swift index cc5747f9..9d1d8ff7 100644 --- a/Tusker/Views/Notifications/PollFinishedTableViewCell.swift +++ b/Tusker/Views/Notifications/PollFinishedTableViewCell.swift @@ -93,6 +93,25 @@ class PollFinishedTableViewCell: UITableViewCell { updateTimestampWorkItem = nil } + // MARK: Accessibility + + override var accessibilityLabel: String? { + get { + guard let notification else { return nil } + var str = "Poll from " + str += notification.account.displayNameWithoutCustomEmoji + str += " finished " + str += notification.createdAt.formatted(.relative(presentation: .numeric)) + if let poll = notification.status?.poll, + poll.options.contains(where: { ($0.votesCount ?? 0) > 0 }) { + let winner = poll.options.max(by: { ($0.votesCount ?? 0) < ($1.votesCount ?? 0) })! + str += ", winning option: \(winner.title)" + } + return str + } + set {} + } + } extension PollFinishedTableViewCell: SelectableTableViewCell { diff --git a/Tusker/Views/Notifications/StatusUpdatedNotificationTableViewCell.swift b/Tusker/Views/Notifications/StatusUpdatedNotificationTableViewCell.swift index 32a70ec4..48d90f00 100644 --- a/Tusker/Views/Notifications/StatusUpdatedNotificationTableViewCell.swift +++ b/Tusker/Views/Notifications/StatusUpdatedNotificationTableViewCell.swift @@ -85,6 +85,22 @@ class StatusUpdatedNotificationTableViewCell: UITableViewCell { updateTimestampWorkItem = nil } + // MARK: Accessibility + + override var accessibilityLabel: String? { + get { + guard let notification else { return nil } + var str = "Post from " + str += notification.account.displayNameWithoutCustomEmoji + str += " edited " + str += notification.createdAt.formatted(.relative(presentation: .numeric)) + str += ", " + str += contentLabel.text ?? "" + return str + } + set {} + } + } extension StatusUpdatedNotificationTableViewCell: SelectableTableViewCell {