Improve VoiceOver labels for notifications

Closes #350
This commit is contained in:
Shadowfacts 2023-02-05 13:56:48 -05:00
parent 2a1deb8d7d
commit 92ff900bc0
6 changed files with 100 additions and 0 deletions

View File

@ -296,6 +296,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
completion(true) completion(true)
} }
} }
dismissAction.accessibilityLabel = "Dismiss Notification"
dismissAction.image = UIImage(systemName: "clear.fill") dismissAction.image = UIImage(systemName: "clear.fill")
let cellConfiguration = (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration() let cellConfiguration = (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration()

View File

@ -221,6 +221,31 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
updateTimestampWorkItem?.cancel() updateTimestampWorkItem?.cancel()
updateTimestampWorkItem = nil 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 {}
}
} }

View File

@ -185,6 +185,22 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
updateTimestampWorkItem?.cancel() updateTimestampWorkItem?.cancel()
updateTimestampWorkItem = nil 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 {}
}
} }

View File

@ -135,6 +135,29 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
self.stackView.addArrangedSubview(label) 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 // MARK: - Interaction
@IBAction func rejectButtonPressed() { @IBAction func rejectButtonPressed() {

View File

@ -93,6 +93,25 @@ class PollFinishedTableViewCell: UITableViewCell {
updateTimestampWorkItem = nil 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 { extension PollFinishedTableViewCell: SelectableTableViewCell {

View File

@ -85,6 +85,22 @@ class StatusUpdatedNotificationTableViewCell: UITableViewCell {
updateTimestampWorkItem = nil 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 { extension StatusUpdatedNotificationTableViewCell: SelectableTableViewCell {