1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-22 14:24:16 +01:00

Remove the status metric view from the accessibility hierarchy

This commit is contained in:
Jed Fox 2022-10-31 12:40:18 -04:00
parent 3876855bc9
commit 8f3caba089
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
4 changed files with 40 additions and 7 deletions

View File

@ -100,6 +100,8 @@ extension StatusMetricView {
reblogButton.addTarget(self, action: #selector(StatusMetricView.reblogButtonDidPressed(_:)), for: .touchUpInside)
favoriteButton.addTarget(self, action: #selector(StatusMetricView.favoriteButtonDidPressed(_:)), for: .touchUpInside)
accessibilityElementsHidden = true
}
}

View File

@ -258,8 +258,7 @@ extension StatusView.ViewModel {
return text
}
.removeDuplicates()
timestampPublisher.assign(to: &$timestampText)
.assign(to: &$timestampText)
$timestampText
.sink { [weak self] text in
@ -269,9 +268,13 @@ extension StatusView.ViewModel {
.store(in: &disposeBag)
// accessibility label
Publishers.CombineLatest3($authorName, usernamePublisher, timestampPublisher)
.map { name, username, timestamp in
"\(name?.string ?? "") \(username), \(timestamp)"
Publishers.CombineLatest4($authorName, usernamePublisher, $timestampText, $timestamp)
.map { name, username, timestampText, timestamp in
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
let longTimestamp = timestamp.map { formatter.string(from: $0) } ?? ""
return "\(name?.string ?? "") \(username), \(timestampText). \(longTimestamp)"
}
.assign(to: \.accessibilityLabel, on: authorView)
.store(in: &disposeBag)

View File

@ -623,6 +623,14 @@ extension StatusView: ActionToolbarContainerDelegate {
public func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, buttonDidPressed button: UIButton, action: ActionToolbarContainer.Action) {
delegate?.statusView(self, actionToolbarContainer: actionToolbarContainer, buttonDidPressed: button, action: action)
}
public func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, showReblogs action: UIAccessibilityCustomAction) {
delegate?.statusView(self, statusMetricView: statusMetricView, reblogButtonDidPressed: statusMetricView.reblogButton)
}
public func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, showFavorites action: UIAccessibilityCustomAction) {
delegate?.statusView(self, statusMetricView: statusMetricView, favoriteButtonDidPressed: statusMetricView.favoriteButton)
}
}
// MARK: - StatusMetricViewDelegate

View File

@ -12,6 +12,8 @@ import MastodonLocalization
public protocol ActionToolbarContainerDelegate: AnyObject {
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, buttonDidPressed button: UIButton, action: ActionToolbarContainer.Action)
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, showReblogs action: UIAccessibilityCustomAction)
func actionToolbarContainer(_ actionToolbarContainer: ActionToolbarContainer, showFavorites action: UIAccessibilityCustomAction)
}
public final class ActionToolbarContainer: UIView {
@ -222,6 +224,7 @@ extension ActionToolbarContainer {
public func configureReblog(count: Int, isEnabled: Bool, isHighlighted: Bool) {
let title = ActionToolbarContainer.title(from: count)
reblogButton.setTitle(title, for: .normal)
reblogButton.accessibilityValue = L10n.Plural.Count.reblog(count)
reblogButton.isEnabled = isEnabled
reblogButton.setImage(ActionToolbarContainer.reblogImage, for: .normal)
let tintColor = isHighlighted ? Asset.Colors.successGreen.color : Asset.Colors.Button.actionToolbar.color
@ -231,15 +234,24 @@ extension ActionToolbarContainer {
if isHighlighted {
reblogButton.accessibilityTraits.insert(.selected)
reblogButton.accessibilityLabel = L10n.Common.Controls.Status.Actions.unreblog
} else {
reblogButton.accessibilityTraits.remove(.selected)
reblogButton.accessibilityLabel = L10n.Common.Controls.Status.Actions.reblog
}
reblogButton.accessibilityLabel = L10n.Plural.Count.reblog(count)
reblogButton.accessibilityCustomActions = [
UIAccessibilityCustomAction(name: "Show All Reblogs") { [weak self] action in
guard let self = self else { return false }
self.delegate?.actionToolbarContainer(self, showReblogs: action)
return true
}
]
}
public func configureFavorite(count: Int, isEnabled: Bool, isHighlighted: Bool) {
let title = ActionToolbarContainer.title(from: count)
favoriteButton.setTitle(title, for: .normal)
favoriteButton.accessibilityValue = L10n.Plural.Count.favorite(count)
favoriteButton.isEnabled = isEnabled
let image = isHighlighted ? ActionToolbarContainer.starFillImage : ActionToolbarContainer.starImage
favoriteButton.setImage(image, for: .normal)
@ -250,10 +262,18 @@ extension ActionToolbarContainer {
if isHighlighted {
favoriteButton.accessibilityTraits.insert(.selected)
favoriteButton.accessibilityLabel = L10n.Common.Controls.Status.Actions.unfavorite
} else {
favoriteButton.accessibilityTraits.remove(.selected)
favoriteButton.accessibilityLabel = L10n.Common.Controls.Status.Actions.favorite
}
favoriteButton.accessibilityLabel = L10n.Plural.Count.favorite(count)
favoriteButton.accessibilityCustomActions = [
UIAccessibilityCustomAction(name: "Show All Favorites") { [weak self] action in
guard let self = self else { return false }
self.delegate?.actionToolbarContainer(self, showFavorites: action)
return true
}
]
}
}