Merge pull request #4923 from element-hq/feature/bma/spaceAvatar2
Iterate on avatar to be able to render Space avatar Part2
This commit is contained in:
commit
5a5195351d
56 changed files with 386 additions and 193 deletions
|
|
@ -27,6 +27,7 @@ import io.element.android.compound.theme.ElementTheme
|
|||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.anAvatarData
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
|
|
@ -72,7 +73,10 @@ fun ComposerAlertMolecule(
|
|||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
if (avatar != null) {
|
||||
Avatar(avatarData = avatar)
|
||||
Avatar(
|
||||
avatarData = avatar,
|
||||
avatarType = AvatarType.User,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = content,
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
|||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
|
|
@ -498,6 +499,7 @@ internal fun BloomPreview() {
|
|||
url = "aURL",
|
||||
size = AvatarSize.CurrentUserTopBar,
|
||||
),
|
||||
avatarType = AvatarType.User,
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.components.avatar.internal.RoomAvatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.internal.SpaceAvatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.internal.UserAvatar
|
||||
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
|
|
@ -24,8 +27,8 @@ import io.element.android.libraries.designsystem.utils.CommonDrawables
|
|||
@Composable
|
||||
fun Avatar(
|
||||
avatarData: AvatarData,
|
||||
avatarType: AvatarType,
|
||||
modifier: Modifier = Modifier,
|
||||
avatarType: AvatarType = AvatarType.User,
|
||||
contentDescription: String? = null,
|
||||
// If not null, will be used instead of the size from avatarData
|
||||
forcedAvatarSize: Dp? = null,
|
||||
|
|
@ -38,6 +41,7 @@ fun Avatar(
|
|||
avatarType = avatarType,
|
||||
modifier = modifier,
|
||||
hideAvatarImage = hideImage,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
AvatarType.User -> UserAvatar(
|
||||
|
|
@ -52,33 +56,7 @@ fun Avatar(
|
|||
avatarType = avatarType,
|
||||
modifier = modifier,
|
||||
hideAvatarImage = hideImage,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun UserAvatar(
|
||||
avatarData: AvatarData,
|
||||
modifier: Modifier = Modifier,
|
||||
contentDescription: String? = null,
|
||||
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,
|
||||
)
|
||||
}
|
||||
|
|
@ -94,7 +72,10 @@ internal fun AvatarPreview(@PreviewParameter(AvatarDataProvider::class) avatarDa
|
|||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
Avatar(avatarData)
|
||||
Avatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = AvatarType.User,
|
||||
)
|
||||
Text(text = avatarData.size.name + " " + avatarData.size.dp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
|||
|
||||
open class AvatarDataProvider : PreviewParameterProvider<AvatarData> {
|
||||
override val values: Sequence<AvatarData>
|
||||
get() = AvatarSize.values()
|
||||
get() = AvatarSize.entries
|
||||
.asSequence()
|
||||
.map {
|
||||
sequenceOf(
|
||||
|
|
|
|||
|
|
@ -11,12 +11,22 @@ import androidx.compose.foundation.shape.CircleShape
|
|||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.unit.Dp
|
||||
|
||||
@Composable
|
||||
fun AvatarType.avatarShape(): Shape {
|
||||
fun AvatarType.User.avatarShape() = CircleShape
|
||||
|
||||
@Composable
|
||||
fun AvatarType.Room.avatarShape() = CircleShape
|
||||
|
||||
@Composable
|
||||
fun AvatarType.Space.avatarShape(avatarSize: Dp) = RoundedCornerShape(avatarSize * 0.25f)
|
||||
|
||||
@Composable
|
||||
fun AvatarType.avatarShape(avatarSize: Dp): Shape {
|
||||
return when (this) {
|
||||
is AvatarType.Space -> RoundedCornerShape(cornerSize)
|
||||
is AvatarType.Room,
|
||||
AvatarType.User -> CircleShape
|
||||
is AvatarType.Space -> avatarShape(avatarSize)
|
||||
is AvatarType.Room -> avatarShape()
|
||||
is AvatarType.User -> avatarShape()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
package io.element.android.libraries.designsystem.components.avatar
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
|
|
@ -22,7 +21,6 @@ sealed interface AvatarType {
|
|||
) : AvatarType
|
||||
|
||||
data class Space(
|
||||
val cornerSize: Dp,
|
||||
val isTombstoned: Boolean = false,
|
||||
) : AvatarType
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ fun DmAvatars(
|
|||
// Draw user avatar and cut top end corner
|
||||
Avatar(
|
||||
avatarData = userAvatarData,
|
||||
avatarType = AvatarType.User,
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomStart)
|
||||
.graphicsLayer {
|
||||
|
|
@ -85,6 +86,7 @@ fun DmAvatars(
|
|||
// Draw other user avatar
|
||||
Avatar(
|
||||
avatarData = otherUserAvatarData,
|
||||
avatarType = AvatarType.User,
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.clip(CircleShape)
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
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
|
||||
|
|
@ -19,6 +20,10 @@ import androidx.compose.ui.semantics.contentDescription
|
|||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.anAvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.avatarShape
|
||||
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
|
@ -33,8 +38,8 @@ private const val MAX_AVATAR_COUNT = 4
|
|||
@Composable
|
||||
internal fun AvatarCluster(
|
||||
avatars: ImmutableList<AvatarData>,
|
||||
avatarType: AvatarType,
|
||||
modifier: Modifier = Modifier,
|
||||
avatarType: AvatarType = AvatarType.User,
|
||||
hideAvatarImages: Boolean = false,
|
||||
contentDescription: String? = null,
|
||||
) {
|
||||
|
|
@ -49,12 +54,13 @@ internal fun AvatarCluster(
|
|||
error("Unsupported number of avatars: 0")
|
||||
}
|
||||
1 -> {
|
||||
Avatar(
|
||||
InitialOrImageAvatar(
|
||||
avatarData = limitedAvatars[0],
|
||||
avatarType = avatarType,
|
||||
hideAvatarImage = hideAvatarImages,
|
||||
avatarShape = avatarType.avatarShape(limitedAvatars[0].size.dp),
|
||||
forcedAvatarSize = null,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
hideImage = hideAvatarImages
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
|
|
@ -97,11 +103,13 @@ internal fun AvatarCluster(
|
|||
y = yOffset,
|
||||
)
|
||||
) {
|
||||
Avatar(
|
||||
InitialOrImageAvatar(
|
||||
avatarData = heroAvatar,
|
||||
hideAvatarImage = hideAvatarImages,
|
||||
avatarShape = avatarType.avatarShape(heroAvatarSize),
|
||||
forcedAvatarSize = heroAvatarSize,
|
||||
avatarType = avatarType,
|
||||
hideImage = hideAvatarImages,
|
||||
modifier = Modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -113,13 +121,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(),
|
||||
)
|
||||
listOf(
|
||||
AvatarType.User,
|
||||
AvatarType.Room(),
|
||||
AvatarType.Space(),
|
||||
).forEach { avatarType ->
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
for (ngOfAvatars in 1..5) {
|
||||
AvatarCluster(
|
||||
avatars = List(ngOfAvatars) { anAvatarData(it) }.toPersistentList(),
|
||||
avatarType = avatarType,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -14,19 +14,21 @@ import androidx.compose.runtime.collectAsState
|
|||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import coil3.compose.AsyncImagePainter
|
||||
import coil3.compose.SubcomposeAsyncImage
|
||||
import coil3.compose.SubcomposeAsyncImageContent
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import timber.log.Timber
|
||||
|
||||
@Composable
|
||||
internal fun ImageAvatar(
|
||||
avatarData: AvatarData,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
forcedAvatarSize: Dp?,
|
||||
modifier: Modifier = Modifier.Companion,
|
||||
modifier: Modifier = Modifier,
|
||||
contentDescription: String? = null,
|
||||
) {
|
||||
val size = forcedAvatarSize ?: avatarData.size.dp
|
||||
|
|
@ -35,8 +37,8 @@ internal fun ImageAvatar(
|
|||
contentDescription = contentDescription,
|
||||
contentScale = ContentScale.Companion.Crop,
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.clip(avatarType.avatarShape())
|
||||
.size(size)
|
||||
.clip(avatarShape)
|
||||
) {
|
||||
val collectedState by painter.state.collectAsState()
|
||||
when (val state = collectedState) {
|
||||
|
|
@ -50,14 +52,14 @@ internal fun ImageAvatar(
|
|||
}
|
||||
InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
else -> InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
|
|
@ -5,26 +5,28 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
|
||||
@Composable
|
||||
internal fun InitialLetterAvatar(
|
||||
avatarData: AvatarData,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
forcedAvatarSize: Dp?,
|
||||
contentDescription: String?,
|
||||
modifier: Modifier = Modifier.Companion,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val avatarColors = AvatarColorsProvider.provide(avatarData.id)
|
||||
TextAvatar(
|
||||
text = avatarData.initialLetter,
|
||||
size = forcedAvatarSize ?: avatarData.size.dp,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
colors = avatarColors,
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.internal
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
|
||||
@Composable
|
||||
internal fun InitialOrImageAvatar(
|
||||
avatarData: AvatarData,
|
||||
hideAvatarImage: Boolean,
|
||||
forcedAvatarSize: Dp?,
|
||||
avatarShape: Shape,
|
||||
contentDescription: String?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
when {
|
||||
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarShape = avatarShape,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
else -> ImageAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarShape = avatarShape,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,14 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.avatarShape
|
||||
|
||||
@Composable
|
||||
internal fun RoomAvatar(
|
||||
|
|
@ -16,39 +20,33 @@ 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,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarType.avatarShape(),
|
||||
contentDescription = contentDescription
|
||||
)
|
||||
}
|
||||
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,
|
||||
avatarShape = avatarType.avatarShape(),
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
AvatarCluster(
|
||||
avatars = avatarType.heroes,
|
||||
// Note: even for a room avatar, we use UserAvatarType here to display the avatar of heroes
|
||||
avatarType = AvatarType.User,
|
||||
modifier = modifier,
|
||||
hideAvatarImages = hideAvatarImage,
|
||||
contentDescription = contentDescription
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
|
|
@ -13,37 +13,38 @@ 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.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.anAvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.avatarShape
|
||||
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
import io.element.android.libraries.designsystem.utils.CommonDrawables
|
||||
|
||||
@Composable
|
||||
fun SpaceAvatar(
|
||||
internal fun SpaceAvatar(
|
||||
avatarData: AvatarData,
|
||||
avatarType: AvatarType.Space,
|
||||
modifier: Modifier = Modifier,
|
||||
forcedAvatarSize: Dp? = null,
|
||||
hideAvatarImage: Boolean = false,
|
||||
contentDescription: String? = null,
|
||||
) {
|
||||
val size = forcedAvatarSize ?: avatarData.size.dp
|
||||
when {
|
||||
avatarType.isTombstoned -> TombstonedRoomAvatar(
|
||||
size = avatarData.size,
|
||||
avatarType = avatarType,
|
||||
size = size,
|
||||
avatarShape = avatarType.avatarShape(size),
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
||||
else -> InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
forcedAvatarSize = null,
|
||||
)
|
||||
else -> ImageAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
forcedAvatarSize = null,
|
||||
hideAvatarImage = hideAvatarImage,
|
||||
avatarShape = avatarType.avatarShape(size),
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
|
|
@ -62,12 +63,11 @@ internal fun SpaceAvatarPreview() =
|
|||
) {
|
||||
SpaceAvatar(
|
||||
avatarData = anAvatarData(),
|
||||
avatarType = AvatarType.Space(cornerSize = 16.dp),
|
||||
avatarType = AvatarType.Space(),
|
||||
)
|
||||
SpaceAvatar(
|
||||
avatarData = anAvatarData(),
|
||||
avatarType = AvatarType.Space(
|
||||
cornerSize = 16.dp,
|
||||
isTombstoned = true,
|
||||
),
|
||||
)
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
|
|
@ -17,6 +17,7 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
|
@ -25,6 +26,8 @@ import androidx.compose.ui.unit.dp
|
|||
import androidx.compose.ui.unit.sp
|
||||
import io.element.android.compound.theme.AvatarColors
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.avatarShape
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
import io.element.android.libraries.designsystem.text.toSp
|
||||
|
|
@ -36,13 +39,13 @@ internal fun TextAvatar(
|
|||
size: Dp,
|
||||
colors: AvatarColors,
|
||||
contentDescription: String?,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
Box(
|
||||
modifier
|
||||
.size(size)
|
||||
.clip(avatarType.avatarShape())
|
||||
.clip(avatarShape)
|
||||
.background(color = colors.background)
|
||||
) {
|
||||
val fontSize = size.toSp() / 2
|
||||
|
|
@ -74,7 +77,7 @@ internal fun TextAvatarPreview() = ElementPreview {
|
|||
listOf(
|
||||
AvatarType.User,
|
||||
AvatarType.Room(),
|
||||
AvatarType.Space(8.dp),
|
||||
AvatarType.Space(),
|
||||
).forEach { avatarType ->
|
||||
TextAvatar(
|
||||
text = "AB",
|
||||
|
|
@ -83,7 +86,7 @@ internal fun TextAvatarPreview() = ElementPreview {
|
|||
background = ElementTheme.colors.bgSubtlePrimary,
|
||||
foreground = ElementTheme.colors.iconPrimary,
|
||||
),
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarType.avatarShape(40.dp),
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
|
@ -5,11 +5,15 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
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
|
||||
|
|
@ -17,20 +21,20 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
|
|||
|
||||
@Composable
|
||||
internal fun TombstonedRoomAvatar(
|
||||
size: AvatarSize,
|
||||
avatarType: AvatarType,
|
||||
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
|
||||
),
|
||||
modifier = modifier,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
|
|
@ -39,8 +43,8 @@ internal fun TombstonedRoomAvatar(
|
|||
@Composable
|
||||
internal fun TombstonedRoomAvatarPreview() = ElementPreview {
|
||||
TombstonedRoomAvatar(
|
||||
size = AvatarSize.RoomListItem,
|
||||
avatarType = AvatarType.Room(),
|
||||
size = 52.dp,
|
||||
avatarShape = CircleShape,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.internal
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.avatarShape
|
||||
|
||||
@Composable
|
||||
internal fun UserAvatar(
|
||||
avatarData: AvatarData,
|
||||
modifier: Modifier = Modifier,
|
||||
contentDescription: String? = null,
|
||||
forcedAvatarSize: Dp? = null,
|
||||
hideImage: Boolean = false,
|
||||
) {
|
||||
InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideImage,
|
||||
avatarShape = AvatarType.User.avatarShape(),
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
)
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
package io.element.android.libraries.designsystem.components.avatar.internal
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -16,6 +16,9 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.theme.avatarColors
|
||||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarType
|
||||
import io.element.android.libraries.designsystem.components.avatar.anAvatarData
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
|
|
@ -33,7 +36,10 @@ internal fun UserAvatarColorsPreview() = ElementPreview {
|
|||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
// Note: it's OK, since the hash of "0" is 0, the hash of "1" is 1, etc.
|
||||
Avatar(anAvatarData(id = "$it"))
|
||||
Avatar(
|
||||
avatarData = anAvatarData(id = "$it"),
|
||||
avatarType = AvatarType.User,
|
||||
)
|
||||
Text(text = "Color index $it")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue