From fbc5d6eed969dac2cb03c88e3813d9b48eacd18f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 6 Jun 2021 22:12:50 -0400 Subject: [PATCH] Make timeline status cells single accessibility elements --- .../Status/TimelineStatusTableViewCell.swift | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 92d826df63..407cd84b0b 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -15,7 +15,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { static let relativeDateFormatter: RelativeDateTimeFormatter = { let formatter = RelativeDateTimeFormatter() formatter.dateTimeStyle = .numeric - formatter.unitsStyle = .short + formatter.unitsStyle = .full return formatter }() @@ -44,7 +44,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { reblogLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reblogLabelPressed))) - accessibilityElements!.insert(reblogLabel!, at: 0) + isAccessibilityElement = true // todo: double check this on RTL layouts replyButton.imageView!.leadingAnchor.constraint(equalTo: contentTextView.leadingAnchor).isActive = true @@ -134,7 +134,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { private func doUpdateTimestamp(status: StatusMO) { timestampLabel.text = status.createdAt.timeAgoString() - timestampLabel.accessibilityLabel = TimelineStatusTableViewCell.relativeDateFormatter.localizedString(for: status.createdAt, relativeTo: Date()) let delay: DispatchTimeInterval? switch status.createdAt.timeAgo().1 { @@ -193,6 +192,33 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { actions: { self.actionsForStatus(status, sourceView: self) } ) } + + // 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 {} + } }