Extract subcomposable InitialOrImageAvatar
This commit is contained in:
parent
52ad634504
commit
9e65b7fa63
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() -> {
|
||||
if (avatarData.url.isNullOrBlank() || hideAvatarImage) {
|
||||
InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
forcedAvatarSize = null,
|
||||
)
|
||||
} else {
|
||||
ImageAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
forcedAvatarSize = null,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideAvatarImage,
|
||||
avatarType = avatarType,
|
||||
forcedAvatarSize = null,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
AvatarCluster(
|
||||
|
|
|
|||
|
|
@ -33,15 +33,9 @@ internal fun SpaceAvatar(
|
|||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
forcedAvatarSize = null,
|
||||
)
|
||||
else -> ImageAvatar(
|
||||
else -> InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideAvatarImage,
|
||||
avatarType = avatarType,
|
||||
forcedAvatarSize = null,
|
||||
modifier = modifier,
|
||||
|
|
|
|||
|
|
@ -19,21 +19,12 @@ internal fun UserAvatar(
|
|||
forcedAvatarSize: Dp? = null,
|
||||
hideImage: Boolean = false,
|
||||
) {
|
||||
if (avatarData.url.isNullOrBlank() || hideImage) {
|
||||
InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = AvatarType.User,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
} else {
|
||||
ImageAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = AvatarType.User,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideImage,
|
||||
avatarType = AvatarType.User,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue