VoiceOver improvement

This commit is contained in:
Justin Mazzocchi 2021-02-24 16:58:50 -08:00
parent d2750ccc4d
commit ab2ad57d6f
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 76 additions and 65 deletions

View file

@ -66,8 +66,7 @@ final class StatusView: UIView {
override func accessibilityActivate() -> Bool { override func accessibilityActivate() -> Bool {
if !statusConfiguration.viewModel.shouldShowContent { if !statusConfiguration.viewModel.shouldShowContent {
statusConfiguration.viewModel.toggleShowContent() statusConfiguration.viewModel.toggleShowContent()
accessibilityAttributedLabel = accessibilityAttributedLabel(forceShowContent: true)
UIAccessibility.post(notification: .screenChanged, argument: self)
return true return true
} else { } else {
@ -409,7 +408,6 @@ private extension StatusView {
.store(in: &cancellables) .store(in: &cancellables)
} }
// swiftlint:disable:next cyclomatic_complexity
func applyStatusConfiguration() { func applyStatusConfiguration() {
let viewModel = statusConfiguration.viewModel let viewModel = statusConfiguration.viewModel
let isContextParent = viewModel.configuration.isContextParent let isContextParent = viewModel.configuration.isContextParent
@ -588,50 +586,7 @@ private extension StatusView {
isAccessibilityElement = !viewModel.configuration.isContextParent isAccessibilityElement = !viewModel.configuration.isContextParent
let accessibilityAttributedLabel = NSMutableAttributedString(string: "") accessibilityAttributedLabel = accessibilityAttributedLabel(forceShowContent: false)
if !infoLabel.isHidden, let infoText = infoLabel.attributedText {
accessibilityAttributedLabel.appendWithSeparator(infoText)
}
if accessibilityAttributedLabel.string.isEmpty {
accessibilityAttributedLabel.append(mutableDisplayName)
} else {
accessibilityAttributedLabel.appendWithSeparator(mutableDisplayName)
}
if let bodyAccessibilityAttributedLabel = bodyView.accessibilityAttributedLabel {
accessibilityAttributedLabel.appendWithSeparator(bodyAccessibilityAttributedLabel)
}
if let accessibilityTime = viewModel.accessibilityTime {
accessibilityAttributedLabel.appendWithSeparator(accessibilityTime)
}
if viewModel.repliesCount > 0 {
accessibilityAttributedLabel.appendWithSeparator(
String.localizedStringWithFormat(
NSLocalizedString("status.replies-count", comment: ""),
viewModel.repliesCount))
}
if viewModel.identityContext.appPreferences.showReblogAndFavoriteCounts {
if viewModel.reblogsCount > 0 {
accessibilityAttributedLabel.appendWithSeparator(
String.localizedStringWithFormat(
NSLocalizedString("status.reblogs-count", comment: ""),
viewModel.reblogsCount))
}
if viewModel.favoritesCount > 0 {
accessibilityAttributedLabel.appendWithSeparator(
String.localizedStringWithFormat(
NSLocalizedString("status.favorites-count", comment: ""),
viewModel.favoritesCount))
}
}
self.accessibilityAttributedLabel = accessibilityAttributedLabel
configureUserInteractionEnabledForAccessibility() configureUserInteractionEnabledForAccessibility()
@ -764,6 +719,54 @@ private extension StatusView {
} }
// swiftlint:enable function_body_length // swiftlint:enable function_body_length
func accessibilityAttributedLabel(forceShowContent: Bool) -> NSAttributedString {
let accessibilityAttributedLabel = NSMutableAttributedString(string: "")
if !infoLabel.isHidden, let infoText = infoLabel.attributedText {
accessibilityAttributedLabel.appendWithSeparator(infoText)
}
if let displayName = displayNameLabel.attributedText {
if accessibilityAttributedLabel.string.isEmpty {
accessibilityAttributedLabel.append(displayName)
} else {
accessibilityAttributedLabel.appendWithSeparator(displayName)
}
}
accessibilityAttributedLabel.appendWithSeparator(
bodyView.accessibilityAttributedLabel(forceShowContent: forceShowContent))
if let accessibilityTime = statusConfiguration.viewModel.accessibilityTime {
accessibilityAttributedLabel.appendWithSeparator(accessibilityTime)
}
if statusConfiguration.viewModel.repliesCount > 0 {
accessibilityAttributedLabel.appendWithSeparator(
String.localizedStringWithFormat(
NSLocalizedString("status.replies-count", comment: ""),
statusConfiguration.viewModel.repliesCount))
}
if statusConfiguration.viewModel.identityContext.appPreferences.showReblogAndFavoriteCounts {
if statusConfiguration.viewModel.reblogsCount > 0 {
accessibilityAttributedLabel.appendWithSeparator(
String.localizedStringWithFormat(
NSLocalizedString("status.reblogs-count", comment: ""),
statusConfiguration.viewModel.reblogsCount))
}
if statusConfiguration.viewModel.favoritesCount > 0 {
accessibilityAttributedLabel.appendWithSeparator(
String.localizedStringWithFormat(
NSLocalizedString("status.favorites-count", comment: ""),
statusConfiguration.viewModel.favoritesCount))
}
}
return accessibilityAttributedLabel
}
func setButtonImages(scale: UIImage.SymbolScale) { func setButtonImages(scale: UIImage.SymbolScale) {
let visibility = statusConfiguration.viewModel.visibility let visibility = statusConfiguration.viewModel.visibility
let reblogSystemImageName: String let reblogSystemImageName: String

View file

@ -61,24 +61,7 @@ final class StatusBodyView: UIView {
cardView.viewModel = viewModel.cardViewModel cardView.viewModel = viewModel.cardViewModel
cardView.isHidden = viewModel.cardViewModel == nil cardView.isHidden = viewModel.cardViewModel == nil
let accessibilityAttributedLabel = NSMutableAttributedString(string: "") accessibilityAttributedLabel = accessibilityAttributedLabel(forceShowContent: false)
if !spoilerTextLabel.isHidden, !viewModel.shouldShowContent {
accessibilityAttributedLabel.appendWithSeparator(
NSLocalizedString("status.content-warning.accessibility", comment: ""))
accessibilityAttributedLabel.appendWithSeparator(mutableSpoilerText)
} else if !contentTextView.isHidden {
accessibilityAttributedLabel.append(mutableContent)
}
for view in [attachmentsView, pollView, cardView] where !view.isHidden {
guard let viewAccessibilityLabel = view.accessibilityLabel else { continue }
accessibilityAttributedLabel.appendWithSeparator(viewAccessibilityLabel)
}
self.accessibilityAttributedLabel = accessibilityAttributedLabel
var accessibilityCustomActions = [UIAccessibilityCustomAction]() var accessibilityCustomActions = [UIAccessibilityCustomAction]()
@ -177,6 +160,31 @@ extension StatusBodyView {
return height return height
} }
func accessibilityAttributedLabel(forceShowContent: Bool) -> NSAttributedString {
let accessibilityAttributedLabel = NSMutableAttributedString(string: "")
if !spoilerTextLabel.isHidden,
let spoilerText = spoilerTextLabel.attributedText,
let viewModel = viewModel,
!viewModel.shouldShowContent,
!forceShowContent {
accessibilityAttributedLabel.appendWithSeparator(
NSLocalizedString("status.content-warning.accessibility", comment: ""))
accessibilityAttributedLabel.appendWithSeparator(spoilerText)
} else if (!contentTextView.isHidden || forceShowContent), let content = contentTextView.attributedText {
accessibilityAttributedLabel.append(content)
}
for view in [attachmentsView, pollView, cardView] where !view.isHidden {
guard let viewAccessibilityLabel = view.accessibilityLabel else { continue }
accessibilityAttributedLabel.appendWithSeparator(viewAccessibilityLabel)
}
return accessibilityAttributedLabel
}
} }
extension StatusBodyView: UITextViewDelegate { extension StatusBodyView: UITextViewDelegate {