Set a11y-label for notification-screen (IOS-192)

This commit is contained in:
Nathan Mattes 2024-01-24 11:58:08 +01:00
parent 304eb8b7ff
commit 96c4fbfbdb
2 changed files with 17 additions and 28 deletions

View File

@ -176,10 +176,23 @@ extension NotificationView {
.prepend(Date())
.eraseToAnyPublisher()
.sink { [weak self] now in
guard let self else { return }
guard let self, let type = MastodonNotificationType(rawValue: notification.entity.type.rawValue) else { return }
let formattedTimestamp = now.localizedTimeAgo(since: notification.entity.createdAt)
dateLabel.configure(content: PlaintextMetaContent(string: formattedTimestamp))
self.accessibilityLabel = [
"\(author.displayNameWithFallback) \(type)",
author.acct,
formattedTimestamp
].joined(separator: ", ")
if self.statusView.isHidden == false {
self.accessibilityLabel! += ", " + (self.statusView.accessibilityLabel ?? "")
}
if self.quoteStatusViewContainerView.isHidden == false {
self.accessibilityLabel! += ", " + (self.quoteStatusView.accessibilityLabel ?? "")
}
let timestamp = now.localizedTimeAgo(since: notification.entity.createdAt)
dateLabel.configure(content: PlaintextMetaContent(string: timestamp))
}
.store(in: &disposeBag)
}

View File

@ -47,31 +47,7 @@ extension NotificationView.ViewModel {
}
private func bindAuthor(notificationView: NotificationView) {
// timestamp
Publishers.CombineLatest4(
$authorName,
$authorUsername,
$notificationIndicatorText,
$timestamp
)
.sink { name, username, type, timestamp in
let formattedTimestamp = timestamp?.localizedSlowedTimeAgoSinceNow ?? ""
notificationView.accessibilityLabel = [
"\(name?.string ?? "") \(type?.string ?? "")",
username.map { "@\($0)" } ?? "",
formattedTimestamp
].joined(separator: ", ")
if !notificationView.statusView.isHidden {
notificationView.accessibilityLabel! += ", " + (notificationView.statusView.accessibilityLabel ?? "")
}
if !notificationView.quoteStatusViewContainerView.isHidden {
notificationView.accessibilityLabel! += ", " + (notificationView.quoteStatusView.accessibilityLabel ?? "")
}
}
.store(in: &disposeBag)
$type
$type
.sink { type in
var actions = [UIAccessibilityCustomAction]()