Accessibility wip

This commit is contained in:
Justin Mazzocchi 2021-02-01 19:39:32 -08:00
parent c6d644feaf
commit 783a44a67e
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
7 changed files with 43 additions and 4 deletions

View file

@ -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";

View file

@ -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()

View file

@ -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)

View file

@ -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) {

View file

@ -5,12 +5,14 @@ import Foundation
import Mastodon
public struct TagViewModel: CollectionItemViewModel {
public let identityContext: IdentityContext
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
private let tag: Tag
init(tag: Tag) {
init(tag: Tag, identityContext: IdentityContext) {
self.tag = tag
self.identityContext = identityContext
events = Empty().eraseToAnyPublisher()
}
}

View file

@ -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
}
}

View file

@ -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
}
}