Improve accessibility labels for reply/reblog posts

This commit is contained in:
Jed Fox 2022-11-09 16:59:02 -05:00
parent 393e4632da
commit c2232a596d
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
3 changed files with 47 additions and 23 deletions

View File

@ -96,7 +96,6 @@ extension StatusThreadRootTableViewCell {
override var accessibilityElements: [Any]? {
get {
var elements = [
statusView.headerContainerView,
statusView.authorView,
statusView.viewModel.isContentReveal
? statusView.contentMetaText.textView

View File

@ -238,12 +238,11 @@ extension StatusView.ViewModel {
}
.store(in: &disposeBag)
// username
let usernamePublisher = $authorUsername
$authorUsername
.map { text -> String in
guard let text = text else { return "" }
return "@\(text)"
}
usernamePublisher
.sink { username in
let metaContent = PlaintextMetaContent(string: username)
authorView.authorUsernameLabel.configure(content: metaContent)
@ -270,18 +269,6 @@ extension StatusView.ViewModel {
authorView.dateLabel.configure(content: PlaintextMetaContent(string: text))
}
.store(in: &disposeBag)
// accessibility label
Publishers.CombineLatest4($authorName, usernamePublisher, $timestampText, $timestamp)
.map { name, username, timestampText, timestamp in
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
let longTimestamp = timestamp.map { formatter.string(from: $0) } ?? ""
return "\(name?.string ?? "") \(username), \(timestampText). \(longTimestamp)"
}
.assign(to: \.accessibilityLabel, on: authorView)
.store(in: &disposeBag)
}
private func bindContent(statusView: StatusView) {
@ -634,7 +621,7 @@ extension StatusView.ViewModel {
}
private func bindAccessibility(statusView: StatusView) {
let authorAccessibilityLabel = Publishers.CombineLatest3(
let shortAuthorAccessibilityLabel = Publishers.CombineLatest3(
$header,
$authorName,
$timestampText
@ -644,19 +631,56 @@ extension StatusView.ViewModel {
switch header {
case .none:
break
strings.append(authorName?.string)
case .reply(let info):
strings.append(authorName?.string)
strings.append(info.header.string)
case .repost(let info):
strings.append(info.header.string)
strings.append(authorName?.string)
}
strings.append(authorName?.string)
strings.append(timestamp)
return strings.compactMap { $0 }.joined(separator: ", ")
}
let longTimestampFormatter = DateFormatter()
longTimestampFormatter.dateStyle = .medium
longTimestampFormatter.timeStyle = .short
let longTimestampLabel = Publishers.CombineLatest(
$timestampText,
$timestamp.map { timestamp in
if let timestamp {
return longTimestampFormatter.string(from: timestamp)
}
return ""
}
)
.map { timestampText, longTimestamp in
"\(timestampText). \(longTimestamp)"
}
Publishers.CombineLatest4(
$header,
$authorName,
$authorUsername,
longTimestampLabel
)
.map { header, name, username, timestamp in
let nameAndUsername = "\(name?.string ?? "") @\(username ?? "")"
switch header {
case .none:
return "\(nameAndUsername), \(timestamp)"
case .repost(info: let info):
return "\(info.header.string) \(nameAndUsername), \(timestamp)"
case .reply(info: let info):
return "\(nameAndUsername) \(info.header.string), \(timestamp)"
}
}
.assign(to: \.accessibilityLabel, on: statusView.authorView)
.store(in: &disposeBag)
let contentAccessibilityLabel = Publishers.CombineLatest3(
$isContentReveal,
$spoilerContent,
@ -694,8 +718,8 @@ extension StatusView.ViewModel {
statusView.spoilerOverlayView.accessibilityLabel = contentAccessibilityLabel
}
.store(in: &disposeBag)
let meidaAccessibilityLabel = $mediaViewConfigurations
let mediaAccessibilityLabel = $mediaViewConfigurations
.map { configurations -> String? in
let count = configurations.count
return L10n.Plural.Count.media(count)
@ -704,9 +728,9 @@ extension StatusView.ViewModel {
// TODO: Toolbar
Publishers.CombineLatest3(
authorAccessibilityLabel,
shortAuthorAccessibilityLabel,
contentAccessibilityLabel,
meidaAccessibilityLabel
mediaAccessibilityLabel
)
.map { author, content, media in
var labels: [String?] = [content, media]

View File

@ -246,6 +246,7 @@ extension StatusView {
// header
headerIconImageView.isUserInteractionEnabled = false
headerInfoLabel.isUserInteractionEnabled = false
headerInfoLabel.isAccessibilityElement = false
let headerTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
headerTapGestureRecognizer.addTarget(self, action: #selector(StatusView.headerDidPressed(_:)))
headerContainerView.addGestureRecognizer(headerTapGestureRecognizer)