improved reactions a11y

This commit is contained in:
Mauro Romito
2025-06-17 19:54:08 +02:00
committed by Mauro
parent 28038adc0d
commit 12e55d6c28
5 changed files with 53 additions and 10 deletions
@@ -162,15 +162,19 @@ struct TimelineItemMenu: View {
.foregroundColor(reactionBackgroundColor(for: emoji)))
.frame(maxWidth: .infinity, alignment: .leading)
}
.accessibilityLabel(hasReacted(to: emoji) ? L10n.a11yRemoveReaction(emoji) : L10n.a11yAddReaction(emoji))
}
private func hasReacted(to emoji: String) -> Bool {
if let reaction = item.properties.reactions.first(where: { $0.key == emoji }),
reaction.isHighlighted {
return true
}
return false
}
private func reactionBackgroundColor(for emoji: String) -> Color {
if let reaction = item.properties.reactions.first(where: { $0.key == emoji }),
reaction.isHighlighted {
return .compound.bgActionPrimaryRest
} else {
return .clear
}
hasReacted(to: emoji) ? .compound.bgActionPrimaryRest : .clear
}
private func viewsForActions(_ actions: [TimelineItemMenuAction]) -> some View {
@@ -138,11 +138,24 @@ struct TimelineCollapseButtonLabel: View {
}
struct TimelineReactionButton: View {
@Environment(\.accessibilityVoiceOverEnabled) private var voiceOverEnabled
let reaction: AggregatedReaction
let toggleReaction: (String) -> Void
let showReactionSummary: (String) -> Void
@ScaledMetric(relativeTo: .subheadline) private var lineHeight = 20
private var accessibilityLabel: String {
if reaction.isHighlighted {
return reaction.count > 1 ? L10n.tr("Localizable", "screen_room_timeline_reaction_including_you_a11y", reaction.count - 1, reaction.displayKey) : L10n.screenRoomTimelineReactionYouA11y(reaction.displayKey)
}
return L10n.tr("Localizable", "screen_room_timeline_reaction_a11y", reaction.count, reaction.displayKey)
}
private var toggleReactionAccessibilityActionName: String {
reaction.isHighlighted ? L10n.a11yRemoveReaction(reaction.displayKey) : L10n.a11yAddReaction(reaction.displayKey)
}
var body: some View {
label
.onTapGesture {
@@ -151,8 +164,12 @@ struct TimelineReactionButton: View {
.longPressWithFeedback {
showReactionSummary(reaction.key)
}
.accessibilityHint(L10n.commonReaction)
.accessibilityAddTraits(reaction.isHighlighted ? .isSelected : [])
.accessibilityAddTraits(.isButton)
.accessibilityLabel(accessibilityLabel)
.accessibilityHint(toggleReactionAccessibilityActionName)
.accessibilityAction(named: L10n.screenRoomTimelineReactionsShowReactionsSummary) {
showReactionSummary(reaction.key)
}
}
var label: some View {