From 5bfe75c778fb2f8522d735070ebb5269fc4aebac Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Tue, 2 Feb 2021 13:32:39 -0800 Subject: [PATCH] VoiceOver wip --- Localizations/Localizable.strings | 2 ++ View Controllers/TableViewController.swift | 6 +++++- .../View Models/LoadMoreViewModel.swift | 2 +- .../Content Views/ConversationView.swift | 16 +++++++++++++++ Views/UIKit/Content Views/LoadMoreView.swift | 20 +++++++++++++++++++ .../ConversationTableViewCell.swift | 1 + .../LoadMoreTableViewCell.swift | 1 + 7 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index 4e73da6..dc719cc 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -134,6 +134,8 @@ "identities.pending" = "Pending"; "lists.new-list-title" = "New List Title"; "load-more" = "Load More"; +"load-more.newer.accessibility-label" = "Load newer items"; +"load-more.older.accessibility-label" = "Load older items"; "main-navigation.timelines" = "Timelines"; "main-navigation.explore" = "Explore"; "main-navigation.notifications" = "Notifications"; diff --git a/View Controllers/TableViewController.swift b/View Controllers/TableViewController.swift index 0fc9ca6..58ea2dd 100644 --- a/View Controllers/TableViewController.swift +++ b/View Controllers/TableViewController.swift @@ -137,7 +137,11 @@ class TableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { - viewModel.canSelect(indexPath: indexPath) + if case .loadMore = dataSource.itemIdentifier(for: indexPath), UIAccessibility.isVoiceOverRunning { + return false + } + + return viewModel.canSelect(indexPath: indexPath) } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { diff --git a/ViewModels/Sources/ViewModels/View Models/LoadMoreViewModel.swift b/ViewModels/Sources/ViewModels/View Models/LoadMoreViewModel.swift index d4e3dee..d654bc7 100644 --- a/ViewModels/Sources/ViewModels/View Models/LoadMoreViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/LoadMoreViewModel.swift @@ -17,7 +17,7 @@ public final class LoadMoreViewModel: ObservableObject, CollectionItemViewModel } } -extension LoadMoreViewModel { +public extension LoadMoreViewModel { func loadMore() { eventsSubject.send( loadMoreService.request(direction: direction) diff --git a/Views/UIKit/Content Views/ConversationView.swift b/Views/UIKit/Content Views/ConversationView.swift index db6fefb..9bdbb96 100644 --- a/Views/UIKit/Content Views/ConversationView.swift +++ b/Views/UIKit/Content Views/ConversationView.swift @@ -59,6 +59,7 @@ extension ConversationView: UIContentView { } private extension ConversationView { + // swiftlint:disable:next function_body_length func initialSetup() { let containerStackView = UIStackView() let sideStackView = UIStackView() @@ -111,6 +112,8 @@ private extension ConversationView { avatarsHeightConstraint, sideStackView.widthAnchor.constraint(equalToConstant: .avatarDimension) ]) + + isAccessibilityElement = true } func applyConversationConfiguration() { @@ -125,7 +128,20 @@ private extension ConversationView { displayNamesLabel.attributedText = mutableDisplayNames timeLabel.text = viewModel.statusViewModel?.time + timeLabel.accessibilityLabel = viewModel.statusViewModel?.accessibilityTime statusBodyView.viewModel = viewModel.statusViewModel avatarsView.viewModel = viewModel + + let accessibilityAttributedLabel = NSMutableAttributedString(attributedString: mutableDisplayNames) + + if let statusBodyAccessibilityAttributedLabel = statusBodyView.accessibilityAttributedLabel { + accessibilityAttributedLabel.appendWithSeparator(statusBodyAccessibilityAttributedLabel) + } + + if let accessibilityTime = viewModel.statusViewModel?.accessibilityTime { + accessibilityAttributedLabel.appendWithSeparator(accessibilityTime) + } + + self.accessibilityAttributedLabel = accessibilityAttributedLabel } } diff --git a/Views/UIKit/Content Views/LoadMoreView.swift b/Views/UIKit/Content Views/LoadMoreView.swift index 7574369..3c8b114 100644 --- a/Views/UIKit/Content Views/LoadMoreView.swift +++ b/Views/UIKit/Content Views/LoadMoreView.swift @@ -68,6 +68,7 @@ private extension LoadMoreView { static let directionChangeMax = CGFloat.pi static let directionChangeIncrement = CGFloat.pi / 10 + // swiftlint:disable:next function_body_length func initialSetup() { for arrowImageView in [leadingArrowImageView, trailingArrowImageView] { addSubview(arrowImageView) @@ -106,6 +107,25 @@ private extension LoadMoreView { activityIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor), activityIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor) ]) + + isAccessibilityElement = true + accessibilityLabel = NSLocalizedString("load-more", comment: "") + accessibilityCustomActions = [ + UIAccessibilityCustomAction( + name: NSLocalizedString("load-more.older.accessibility-label", comment: "")) { [weak self] _ in + self?.loadMoreConfiguration.viewModel.direction = .down + self?.loadMoreConfiguration.viewModel.loadMore() + + return true + }, + UIAccessibilityCustomAction( + name: NSLocalizedString("load-more.newer.accessibility-label", comment: "")) { [weak self] _ in + self?.loadMoreConfiguration.viewModel.direction = .up + self?.loadMoreConfiguration.viewModel.loadMore() + + return true + } + ] } func applyLoadMoreConfiguration() { diff --git a/Views/UIKit/Table View Cells/ConversationTableViewCell.swift b/Views/UIKit/Table View Cells/ConversationTableViewCell.swift index 1d7a0f2..e0d463d 100644 --- a/Views/UIKit/Table View Cells/ConversationTableViewCell.swift +++ b/Views/UIKit/Table View Cells/ConversationTableViewCell.swift @@ -10,6 +10,7 @@ final class ConversationTableViewCell: UITableViewCell { guard let viewModel = viewModel else { return } contentConfiguration = ConversationContentConfiguration(viewModel: viewModel).updated(for: state) + accessibilityElements = [contentView] } override func layoutSubviews() { diff --git a/Views/UIKit/Table View Cells/LoadMoreTableViewCell.swift b/Views/UIKit/Table View Cells/LoadMoreTableViewCell.swift index 87183ea..7325edb 100644 --- a/Views/UIKit/Table View Cells/LoadMoreTableViewCell.swift +++ b/Views/UIKit/Table View Cells/LoadMoreTableViewCell.swift @@ -10,6 +10,7 @@ final class LoadMoreTableViewCell: UITableViewCell { guard let viewModel = viewModel else { return } contentConfiguration = LoadMoreContentConfiguration(viewModel: viewModel) + accessibilityElements = [contentView] } override func layoutSubviews() {