Make timeline status cells single accessibility elements

This commit is contained in:
Shadowfacts 2021-06-06 22:12:50 -04:00
parent 2c4d2ce551
commit fbc5d6eed9
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 29 additions and 3 deletions

View File

@ -15,7 +15,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
static let relativeDateFormatter: RelativeDateTimeFormatter = { static let relativeDateFormatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter() let formatter = RelativeDateTimeFormatter()
formatter.dateTimeStyle = .numeric formatter.dateTimeStyle = .numeric
formatter.unitsStyle = .short formatter.unitsStyle = .full
return formatter return formatter
}() }()
@ -44,7 +44,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
reblogLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reblogLabelPressed))) reblogLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reblogLabelPressed)))
accessibilityElements!.insert(reblogLabel!, at: 0) isAccessibilityElement = true
// todo: double check this on RTL layouts // todo: double check this on RTL layouts
replyButton.imageView!.leadingAnchor.constraint(equalTo: contentTextView.leadingAnchor).isActive = true replyButton.imageView!.leadingAnchor.constraint(equalTo: contentTextView.leadingAnchor).isActive = true
@ -134,7 +134,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
private func doUpdateTimestamp(status: StatusMO) { private func doUpdateTimestamp(status: StatusMO) {
timestampLabel.text = status.createdAt.timeAgoString() timestampLabel.text = status.createdAt.timeAgoString()
timestampLabel.accessibilityLabel = TimelineStatusTableViewCell.relativeDateFormatter.localizedString(for: status.createdAt, relativeTo: Date())
let delay: DispatchTimeInterval? let delay: DispatchTimeInterval?
switch status.createdAt.timeAgo().1 { switch status.createdAt.timeAgo().1 {
@ -194,6 +193,33 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
) )
} }
// MARK: - Accessibility
override var accessibilityLabel: String? {
get {
guard let status = mastodonController.persistentContainer.status(for: statusID) else {
return nil
}
var str = "\(status.account.displayName), \(contentTextView.text ?? "")"
if status.attachments.count > 0 {
// todo: localize me
str += ", \(status.attachments.count) attachments"
}
if status.poll != nil {
str += ", poll"
}
str += ", \(TimelineStatusTableViewCell.relativeDateFormatter.localizedString(for: status.createdAt, relativeTo: Date()))"
if let rebloggerID = rebloggerID,
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
str += ", reblogged by \(reblogger.displayName)"
}
return str
}
set {}
}
} }
extension TimelineStatusTableViewCell: SelectableTableViewCell { extension TimelineStatusTableViewCell: SelectableTableViewCell {