From 96c4fbfbdb3fadb1144145591599c168d77c063b Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Wed, 24 Jan 2024 11:58:08 +0100 Subject: [PATCH] Set a11y-label for notification-screen (IOS-192) --- .../NotificationView+Configuration.swift | 19 +++++++++++--- .../NotificationView+ViewModel.swift | 26 +------------------ 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift b/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift index e1c4b6d6d..afa4dda20 100644 --- a/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift +++ b/Mastodon/Scene/Notification/NotificationView/NotificationView+Configuration.swift @@ -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) } diff --git a/Mastodon/Scene/Notification/NotificationView/NotificationView+ViewModel.swift b/Mastodon/Scene/Notification/NotificationView/NotificationView+ViewModel.swift index 7c64d217e..f4c3379e1 100644 --- a/Mastodon/Scene/Notification/NotificationView/NotificationView+ViewModel.swift +++ b/Mastodon/Scene/Notification/NotificationView/NotificationView+ViewModel.swift @@ -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]()