VoiceOver wip

This commit is contained in:
Justin Mazzocchi 2021-02-02 13:04:11 -08:00
parent 783b88b54a
commit ef80b743da
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
7 changed files with 61 additions and 15 deletions

View File

@ -30,6 +30,19 @@ extension Date {
return Self.abbreviatedDateComponentsFormatter.string(from: self, to: now)
}
var accessibilityTimeAgo: String? {
let calendar = Calendar.autoupdatingCurrent
let now = Date()
if
let oneWeekAgo = calendar.date(byAdding: DateComponents(weekOfMonth: -1), to: now),
oneWeekAgo < self {
return Self.realtiveTimeFormatter.localizedString(for: self, relativeTo: Date())
}
return Self.accessibilityFullDateComponentsFormatter.string(from: self)
}
var fullUnitTimeUntil: String? {
let calendar = Calendar.autoupdatingCurrent
let now = Date()
@ -78,4 +91,20 @@ private extension Date {
return dateFormatter
}()
private static let realtiveTimeFormatter: RelativeDateTimeFormatter = {
let dateFormatter = RelativeDateTimeFormatter()
dateFormatter.unitsStyle = .full
return dateFormatter
}()
private static let accessibilityFullDateComponentsFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
return dateFormatter
}()
}

View File

@ -41,6 +41,10 @@ public extension NotificationViewModel {
var time: String? { notificationService.notification.createdAt.timeAgo }
var accessibilityTime: String? {
notificationService.notification.createdAt.accessibilityTimeAgo
}
func accountSelected() {
eventsSubject.send(
Just(.navigation(

View File

@ -89,11 +89,7 @@ public extension StatusViewModel {
var time: String? { statusService.status.displayStatus.createdAt.timeAgo }
var accessibilityTime: String {
Self.accessiblityTimeFormatter.localizedString(
for: statusService.status.displayStatus.createdAt,
relativeTo: Date())
}
var accessibilityTime: String? { statusService.status.displayStatus.createdAt.accessibilityTimeAgo }
var contextParentTime: String {
Self.contextParentDateFormatter.string(from: statusService.status.displayStatus.createdAt)
@ -345,14 +341,6 @@ public extension StatusViewModel {
}
private extension StatusViewModel {
private static let accessiblityTimeFormatter: RelativeDateTimeFormatter = {
let dateFormatter = RelativeDateTimeFormatter()
dateFormatter.unitsStyle = .full
return dateFormatter
}()
private static let contextParentDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()

View File

@ -159,6 +159,8 @@ private extension NotificationView {
avatarButton.bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor),
avatarButton.trailingAnchor.constraint(equalTo: avatarImageView.trailingAnchor)
])
isAccessibilityElement = true
}
func applyNotificationConfiguration() {
@ -218,10 +220,30 @@ private extension NotificationView {
}
timeLabel.text = viewModel.time
timeLabel.accessibilityLabel = viewModel.accessibilityTime
iconImageView.image = UIImage(
systemName: viewModel.type.systemImageName,
withConfiguration: UIImage.SymbolConfiguration(scale: .medium))
let accessibilityAttributedLabel = NSMutableAttributedString(string: "")
if let typeText = typeLabel.attributedText {
accessibilityAttributedLabel.appendWithSeparator(typeText)
}
if !statusBodyView.isHidden,
let statusBodyAccessibilityAttributedLabel = statusBodyView.accessibilityAttributedLabel {
accessibilityAttributedLabel.appendWithSeparator(statusBodyAccessibilityAttributedLabel)
} else if !accountLabel.isHidden, let accountText = accountLabel.text {
accessibilityAttributedLabel.appendWithSeparator(accountText)
}
if let accessibilityTime = viewModel.accessibilityTime {
accessibilityAttributedLabel.appendWithSeparator(accessibilityTime)
}
self.accessibilityAttributedLabel = accessibilityAttributedLabel
}
// swiftlint:enable function_body_length
}

View File

@ -504,7 +504,9 @@ private extension StatusView {
accessibilityAttributedLabel.appendWithSeparator(bodyAccessibilityAttributedLabel)
}
accessibilityAttributedLabel.appendWithSeparator(viewModel.accessibilityTime)
if let accessibilityTime = viewModel.accessibilityTime {
accessibilityAttributedLabel.appendWithSeparator(accessibilityTime)
}
self.accessibilityAttributedLabel = accessibilityAttributedLabel

View File

@ -90,7 +90,7 @@ final class StatusBodyView: UIView {
accessibilityAttributedLabel.appendWithSeparator(viewAccessibilityLabel)
}
self.accessibilityLabel = accessibilityAttributedLabel.string
self.accessibilityAttributedLabel = accessibilityAttributedLabel
}
}

View File

@ -10,6 +10,7 @@ final class NotificationTableViewCell: UITableViewCell {
guard let viewModel = viewModel else { return }
contentConfiguration = NotificationContentConfiguration(viewModel: viewModel).updated(for: state)
accessibilityElements = [contentView]
}
override func layoutSubviews() {