Extract subcomposable InitialOrImageAvatar
This commit is contained in:
parent
7f60fde9dc
commit
db98e3c146
4 changed files with 57 additions and 42 deletions
|
|
@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue