add view avatar a11y label

This commit is contained in:
Mauro Romito
2025-06-26 11:45:34 +02:00
committed by Mauro
parent bfd97cd560
commit e075c90bee
4 changed files with 28 additions and 2 deletions
@@ -152,6 +152,18 @@ struct AvatarHeaderView<Footer: View>: View {
}
}
private var avatarAccessibilityLabel: String {
guard onAvatarTap != nil else {
return L10n.a11yAvatar
}
switch avatarInfo {
case .room(let roomAvatar):
return roomAvatar.hasURL ? L10n.a11yViewAvatar : L10n.a11yAvatar
case .user(let userProfileProxy):
return userProfileProxy.avatarURL != nil ? L10n.a11yViewAvatar : L10n.a11yAvatar
}
}
@ViewBuilder
private var avatar: some View {
switch avatarInfo {
@@ -160,7 +172,7 @@ struct AvatarHeaderView<Footer: View>: View {
avatarSize: avatarSize,
mediaProvider: mediaProvider,
onAvatarTap: onAvatarTap)
.accessibilityLabel(L10n.a11yAvatar)
.accessibilityLabel(avatarAccessibilityLabel)
case .user(let userProfile):
LoadableAvatarImage(url: userProfile.avatarURL,
@@ -169,7 +181,7 @@ struct AvatarHeaderView<Footer: View>: View {
avatarSize: avatarSize,
mediaProvider: mediaProvider,
onTap: onAvatarTap)
.accessibilityLabel(L10n.a11yAvatar)
.accessibilityLabel(avatarAccessibilityLabel)
}
}
@@ -26,6 +26,17 @@ enum RoomAvatar: Equatable {
.tombstoned
}
}
var hasURL: Bool {
switch self {
case let .room(_, _, url):
return url != nil
case let .heroes(heroes):
return heroes.first?.avatarURL != nil
case .tombstoned:
return false
}
}
}
/// A view that shows the avatar for a room, or a cluster of heroes if provided.