Improve preview of AvatarCluster to show all types.

This commit is contained in:
Benoit Marty
2025-06-23 22:00:25 +02:00
parent e1bde435f5
commit 341dff7f03
5 changed files with 45 additions and 17 deletions

View File

@@ -38,6 +38,7 @@ fun Avatar(
avatarType = avatarType,
modifier = modifier,
hideAvatarImage = hideImage,
forcedAvatarSize = forcedAvatarSize,
contentDescription = contentDescription,
)
AvatarType.User -> UserAvatar(
@@ -52,6 +53,7 @@ fun Avatar(
avatarType = avatarType,
modifier = modifier,
hideAvatarImage = hideImage,
forcedAvatarSize = forcedAvatarSize,
contentDescription = contentDescription,
)
}

View File

@@ -9,6 +9,7 @@ package io.element.android.libraries.designsystem.components.avatar
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
@@ -98,11 +99,20 @@ internal fun AvatarCluster(
y = yOffset,
)
) {
Avatar(
InitialOrImageAvatar(
avatarData = heroAvatar,
hideAvatarImage = hideAvatarImages,
avatarShape = avatarType.let { avatarType ->
if (avatarType is AvatarType.Space) {
// Reduce corner size for small Space avatars
avatarType.copy(cornerSize = avatarType.cornerSize / 2f)
} else {
avatarType
}
}.avatarShape(),
forcedAvatarSize = heroAvatarSize,
avatarType = avatarType,
hideImage = hideAvatarImages,
modifier = Modifier,
contentDescription = contentDescription,
)
}
}
@@ -114,14 +124,24 @@ internal fun AvatarCluster(
@Preview(group = PreviewGroup.Avatars)
@Composable
internal fun AvatarClusterPreview() = ElementThemedPreview {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp)
Column(
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
for (ngOfAvatars in 1..5) {
AvatarCluster(
avatars = List(ngOfAvatars) { anAvatarData(it) }.toPersistentList(),
avatarType = AvatarType.User,
)
listOf(
AvatarType.User,
AvatarType.Room(),
AvatarType.Space(8.dp),
).forEach { avatarType ->
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
for (ngOfAvatars in 1..5) {
AvatarCluster(
avatars = List(ngOfAvatars) { anAvatarData(it) }.toPersistentList(),
avatarType = avatarType,
)
}
}
}
}
}

View File

@@ -9,6 +9,7 @@ package io.element.android.libraries.designsystem.components.avatar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
@Composable
internal fun RoomAvatar(
@@ -16,12 +17,13 @@ internal fun RoomAvatar(
avatarType: AvatarType.Room,
modifier: Modifier = Modifier,
hideAvatarImage: Boolean = false,
forcedAvatarSize: Dp? = null,
contentDescription: String? = null,
) {
when {
avatarType.isTombstoned -> {
TombstonedRoomAvatar(
size = avatarData.size,
size = forcedAvatarSize ?: avatarData.size.dp,
modifier = modifier,
avatarShape = avatarType.avatarShape(),
contentDescription = contentDescription
@@ -32,7 +34,7 @@ internal fun RoomAvatar(
avatarData = avatarData,
hideAvatarImage = hideAvatarImage,
avatarShape = avatarType.avatarShape(),
forcedAvatarSize = null,
forcedAvatarSize = forcedAvatarSize,
modifier = modifier,
contentDescription = contentDescription,
)

View File

@@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
import io.element.android.libraries.designsystem.preview.PreviewGroup
@@ -23,12 +24,13 @@ internal fun SpaceAvatar(
avatarData: AvatarData,
avatarType: AvatarType.Space,
modifier: Modifier = Modifier,
forcedAvatarSize: Dp? = null,
hideAvatarImage: Boolean = false,
contentDescription: String? = null,
) {
when {
avatarType.isTombstoned -> TombstonedRoomAvatar(
size = avatarData.size,
size = forcedAvatarSize ?: avatarData.size.dp,
avatarShape = avatarType.avatarShape(),
modifier = modifier,
contentDescription = contentDescription,
@@ -37,7 +39,7 @@ internal fun SpaceAvatar(
avatarData = avatarData,
hideAvatarImage = hideAvatarImage,
avatarShape = avatarType.avatarShape(),
forcedAvatarSize = null,
forcedAvatarSize = forcedAvatarSize,
modifier = modifier,
contentDescription = contentDescription,
)

View File

@@ -12,6 +12,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.AvatarColors
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.designsystem.preview.ElementPreview
@@ -19,14 +21,14 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
@Composable
internal fun TombstonedRoomAvatar(
size: AvatarSize,
size: Dp,
avatarShape: Shape,
modifier: Modifier = Modifier,
contentDescription: String? = null,
) {
TextAvatar(
text = "!",
size = size.dp,
size = size,
colors = AvatarColors(
background = ElementTheme.colors.bgSubtlePrimary,
foreground = ElementTheme.colors.iconTertiary
@@ -41,7 +43,7 @@ internal fun TombstonedRoomAvatar(
@Composable
internal fun TombstonedRoomAvatarPreview() = ElementPreview {
TombstonedRoomAvatar(
size = AvatarSize.RoomListItem,
size = 52.dp,
avatarShape = CircleShape,
contentDescription = null,
)