Let AvatarType be the receiver of avatarShape()

This commit is contained in:
Benoit Marty 2025-06-23 18:34:52 +02:00
parent 0f6dd82b97
commit 688fbdd1bd
4 changed files with 6 additions and 8 deletions

View file

@ -13,11 +13,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.Shape
@Composable @Composable
fun avatarShape( fun AvatarType.avatarShape(): Shape {
avatarType: AvatarType, return when (this) {
): Shape { is AvatarType.Space -> RoundedCornerShape(cornerSize)
return when (avatarType) {
is AvatarType.Space -> RoundedCornerShape(avatarType.cornerSize)
is AvatarType.Room, is AvatarType.Room,
AvatarType.User -> CircleShape AvatarType.User -> CircleShape
} }

View file

@ -36,7 +36,7 @@ internal fun ImageAvatar(
contentScale = ContentScale.Companion.Crop, contentScale = ContentScale.Companion.Crop,
modifier = modifier modifier = modifier
.size(size) .size(size)
.clip(avatarShape(avatarType)) .clip(avatarType.avatarShape())
) { ) {
val collectedState by painter.state.collectAsState() val collectedState by painter.state.collectAsState()
when (val state = collectedState) { when (val state = collectedState) {

View file

@ -42,7 +42,7 @@ internal fun TextAvatar(
Box( Box(
modifier modifier
.size(size) .size(size)
.clip(avatarShape(avatarType)) .clip(avatarType.avatarShape())
.background(color = colors.background) .background(color = colors.background)
) { ) {
val fontSize = size.toSp() / 2 val fontSize = size.toSp() / 2

View file

@ -48,7 +48,7 @@ fun UnsavedAvatar(
) { ) {
val commonModifier = modifier val commonModifier = modifier
.size(70.dp) .size(70.dp)
.clip(avatarShape(avatarType)) .clip(avatarType.avatarShape())
if (avatarUri != null) { if (avatarUri != null) {
val context = LocalContext.current val context = LocalContext.current