diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index 865967d..511a888 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -250,6 +250,9 @@ "status.visibility.private.description" = "Visible for followers only"; "status.visibility.direct.description" = "Visible for mentioned users only"; "submit" = "Submit"; +"tag.accessibility-recent-uses-%ld" = "%ld recent uses"; +"tag.accessibility-hint.post" = "View posts associated with trend"; +"tag.accessibility-hint.toot" = "View toots associated with trend"; "timelines.home" = "Home"; "timelines.local" = "Local"; "timelines.federated" = "Federated"; diff --git a/View Controllers/ExploreViewController.swift b/View Controllers/ExploreViewController.swift index 7152f93..0925f36 100644 --- a/View Controllers/ExploreViewController.swift +++ b/View Controllers/ExploreViewController.swift @@ -36,6 +36,8 @@ final class ExploreViewController: UICollectionViewController { collectionView.dataSource = dataSource collectionView.backgroundColor = .systemBackground collectionView.contentInset.bottom = Self.bottomInset + collectionView.isAccessibilityElement = false + collectionView.shouldGroupAccessibilityChildren = true clearsSelectionOnViewWillAppear = true collectionView.refreshControl = UIRefreshControl() diff --git a/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift b/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift index 4a3c32f..ad27a1e 100644 --- a/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/CollectionItemsViewModel.swift @@ -276,7 +276,7 @@ extension CollectionItemsViewModel: CollectionViewModel { return cachedViewModel } - let viewModel = TagViewModel(tag: tag) + let viewModel = TagViewModel(tag: tag, identityContext: identityContext) cache(viewModel: viewModel, forItem: item) diff --git a/ViewModels/Sources/ViewModels/View Models/ExploreViewModel.swift b/ViewModels/Sources/ViewModels/View Models/ExploreViewModel.swift index f61395f..3911192 100644 --- a/ViewModels/Sources/ViewModels/View Models/ExploreViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/ExploreViewModel.swift @@ -70,7 +70,7 @@ public extension ExploreViewModel { } func viewModel(tag: Tag) -> TagViewModel { - .init(tag: tag) + .init(tag: tag, identityContext: identityContext) } func select(item: ExploreViewModel.Item) { diff --git a/ViewModels/Sources/ViewModels/View Models/TagViewModel.swift b/ViewModels/Sources/ViewModels/View Models/TagViewModel.swift index 2eeee8a..9ca6ac3 100644 --- a/ViewModels/Sources/ViewModels/View Models/TagViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/TagViewModel.swift @@ -5,12 +5,14 @@ import Foundation import Mastodon public struct TagViewModel: CollectionItemViewModel { + public let identityContext: IdentityContext public let events: AnyPublisher, Never> private let tag: Tag - init(tag: Tag) { + init(tag: Tag, identityContext: IdentityContext) { self.tag = tag + self.identityContext = identityContext events = Empty().eraseToAnyPublisher() } } diff --git a/Views/UIKit/Content Views/InstanceView.swift b/Views/UIKit/Content Views/InstanceView.swift index c79c919..29c7ed3 100644 --- a/Views/UIKit/Content Views/InstanceView.swift +++ b/Views/UIKit/Content Views/InstanceView.swift @@ -71,6 +71,8 @@ private extension InstanceView { stackView.bottomAnchor.constraint(equalTo: readableContentGuide.bottomAnchor), imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor, multiplier: 16 / 9) ]) + + setupAccessibility() } func applyInstanceConfiguration() { @@ -80,5 +82,11 @@ private extension InstanceView { titleLabel.text = viewModel.instance.title uriLabel.text = viewModel.instance.uri + + accessibilityLabel = viewModel.instance.title.appending("\n").appending(viewModel.instance.uri) + } + + func setupAccessibility() { + isAccessibilityElement = true } } diff --git a/Views/UIKit/Content Views/TagView.swift b/Views/UIKit/Content Views/TagView.swift index 0722a5f..e523bca 100644 --- a/Views/UIKit/Content Views/TagView.swift +++ b/Views/UIKit/Content Views/TagView.swift @@ -84,17 +84,23 @@ private extension TagView { lineChartView.heightAnchor.constraint(equalTo: usesLabel.heightAnchor), lineChartView.widthAnchor.constraint(equalTo: lineChartView.heightAnchor, multiplier: 16 / 9) ]) + + setupAccessibility() } func applyTagConfiguration() { let viewModel = tagConfiguration.viewModel + var accessibilityLabel = viewModel.name nameLabel.text = viewModel.name if let accounts = viewModel.accounts { - accountsLabel.text = String.localizedStringWithFormat( + let accountsText = String.localizedStringWithFormat( NSLocalizedString("tag.people-talking", comment: ""), accounts) + accountsLabel.text = accountsText + accessibilityLabel.append("\n") + accessibilityLabel.append(accountsText) accountsLabel.isHidden = false } else { accountsLabel.isHidden = true @@ -103,11 +109,29 @@ private extension TagView { if let uses = viewModel.uses { usesLabel.text = String(uses) usesLabel.isHidden = false + let accessibilityRecentUses = String.localizedStringWithFormat( + NSLocalizedString("tag.accessibility-recent-uses-%ld", comment: ""), + uses) + accessibilityLabel.append("\n") + accessibilityLabel.append(accessibilityRecentUses) } else { usesLabel.isHidden = true } lineChartView.values = viewModel.usageHistory.reversed() lineChartView.isHidden = viewModel.usageHistory.isEmpty + + self.accessibilityLabel = accessibilityLabel + + switch viewModel.identityContext.appPreferences.statusWord { + case .toot: + accessibilityHint = NSLocalizedString("tag.accessibility-hint.toot", comment: "") + case .post: + accessibilityHint = NSLocalizedString("tag.accessibility-hint.post", comment: "") + } + } + + func setupAccessibility() { + isAccessibilityElement = true } }