Extract subcomposable InitialOrImageAvatar

This commit is contained in:
Benoit Marty 2025-06-23 21:41:15 +02:00
parent 7f60fde9dc
commit db98e3c146
4 changed files with 57 additions and 42 deletions

View file

@ -0,0 +1,39 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
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 InitialOrImageAvatar(
avatarData: AvatarData,
hideAvatarImage: Boolean,
forcedAvatarSize: Dp?,
avatarType: AvatarType,
modifier: Modifier,
contentDescription: String?
) {
when {
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
avatarData = avatarData,
avatarType = avatarType,
forcedAvatarSize = forcedAvatarSize,
modifier = modifier,
contentDescription = contentDescription,
)
else -> ImageAvatar(
avatarData = avatarData,
avatarType = avatarType,
forcedAvatarSize = forcedAvatarSize,
modifier = modifier,
contentDescription = contentDescription,
)
}
}

View file

@ -28,23 +28,14 @@ internal fun RoomAvatar(
) )
} }
avatarData.url != null || avatarType.heroes.isEmpty() -> { avatarData.url != null || avatarType.heroes.isEmpty() -> {
if (avatarData.url.isNullOrBlank() || hideAvatarImage) { InitialOrImageAvatar(
InitialLetterAvatar( avatarData = avatarData,
avatarData = avatarData, hideAvatarImage = hideAvatarImage,
avatarType = avatarType, avatarType = avatarType,
modifier = modifier, forcedAvatarSize = null,
contentDescription = contentDescription, modifier = modifier,
forcedAvatarSize = null, contentDescription = contentDescription,
) )
} else {
ImageAvatar(
avatarData = avatarData,
avatarType = avatarType,
forcedAvatarSize = null,
modifier = modifier,
contentDescription = contentDescription,
)
}
} }
else -> { else -> {
AvatarCluster( AvatarCluster(

View file

@ -33,15 +33,9 @@ internal fun SpaceAvatar(
modifier = modifier, modifier = modifier,
contentDescription = contentDescription, contentDescription = contentDescription,
) )
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar( else -> InitialOrImageAvatar(
avatarData = avatarData,
avatarType = avatarType,
modifier = modifier,
contentDescription = contentDescription,
forcedAvatarSize = null,
)
else -> ImageAvatar(
avatarData = avatarData, avatarData = avatarData,
hideAvatarImage = hideAvatarImage,
avatarType = avatarType, avatarType = avatarType,
forcedAvatarSize = null, forcedAvatarSize = null,
modifier = modifier, modifier = modifier,

View file

@ -19,21 +19,12 @@ internal fun UserAvatar(
forcedAvatarSize: Dp? = null, forcedAvatarSize: Dp? = null,
hideImage: Boolean = false, hideImage: Boolean = false,
) { ) {
if (avatarData.url.isNullOrBlank() || hideImage) { InitialOrImageAvatar(
InitialLetterAvatar( avatarData = avatarData,
avatarData = avatarData, hideAvatarImage = hideImage,
avatarType = AvatarType.User, avatarType = AvatarType.User,
forcedAvatarSize = forcedAvatarSize, modifier = modifier,
modifier = modifier, contentDescription = contentDescription,
contentDescription = contentDescription, forcedAvatarSize = forcedAvatarSize,
) )
} else {
ImageAvatar(
avatarData = avatarData,
avatarType = AvatarType.User,
forcedAvatarSize = forcedAvatarSize,
modifier = modifier,
contentDescription = contentDescription,
)
}
} }