Provide avatarShape: Shape instead of AvatarType to sub composable functions
This commit is contained in:
@@ -14,6 +14,7 @@ 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
|
||||
@@ -24,7 +25,7 @@ import timber.log.Timber
|
||||
@Composable
|
||||
internal fun ImageAvatar(
|
||||
avatarData: AvatarData,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
forcedAvatarSize: Dp?,
|
||||
modifier: Modifier = Modifier,
|
||||
contentDescription: String? = null,
|
||||
@@ -35,8 +36,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 +51,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,
|
||||
)
|
||||
|
||||
@@ -9,13 +9,14 @@ package io.element.android.libraries.designsystem.components.avatar
|
||||
|
||||
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
|
||||
|
||||
@Composable
|
||||
internal fun InitialLetterAvatar(
|
||||
avatarData: AvatarData,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
forcedAvatarSize: Dp?,
|
||||
contentDescription: String?,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -24,7 +25,7 @@ internal fun InitialLetterAvatar(
|
||||
TextAvatar(
|
||||
text = avatarData.initialLetter,
|
||||
size = forcedAvatarSize ?: avatarData.size.dp,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
colors = avatarColors,
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier
|
||||
|
||||
@@ -9,6 +9,7 @@ package io.element.android.libraries.designsystem.components.avatar
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.unit.Dp
|
||||
|
||||
@Composable
|
||||
@@ -16,21 +17,21 @@ internal fun InitialOrImageAvatar(
|
||||
avatarData: AvatarData,
|
||||
hideAvatarImage: Boolean,
|
||||
forcedAvatarSize: Dp?,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
modifier: Modifier,
|
||||
contentDescription: String?
|
||||
) {
|
||||
when {
|
||||
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
else -> ImageAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
|
||||
@@ -23,7 +23,7 @@ internal fun RoomAvatar(
|
||||
TombstonedRoomAvatar(
|
||||
size = avatarData.size,
|
||||
modifier = modifier,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarType.avatarShape(),
|
||||
contentDescription = contentDescription
|
||||
)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ internal fun RoomAvatar(
|
||||
InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideAvatarImage,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarType.avatarShape(),
|
||||
forcedAvatarSize = null,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
|
||||
@@ -29,14 +29,14 @@ internal fun SpaceAvatar(
|
||||
when {
|
||||
avatarType.isTombstoned -> TombstonedRoomAvatar(
|
||||
size = avatarData.size,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarType.avatarShape(),
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
else -> InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideAvatarImage,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarType.avatarShape(),
|
||||
forcedAvatarSize = null,
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
|
||||
@@ -13,10 +13,12 @@ import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
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
|
||||
@@ -36,13 +38,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
|
||||
@@ -83,7 +85,7 @@ internal fun TextAvatarPreview() = ElementPreview {
|
||||
background = ElementTheme.colors.bgSubtlePrimary,
|
||||
foreground = ElementTheme.colors.iconPrimary,
|
||||
),
|
||||
avatarType = avatarType,
|
||||
avatarShape = CircleShape,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
|
||||
package io.element.android.libraries.designsystem.components.avatar
|
||||
|
||||
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 io.element.android.compound.theme.AvatarColors
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
@@ -18,7 +20,7 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
@Composable
|
||||
internal fun TombstonedRoomAvatar(
|
||||
size: AvatarSize,
|
||||
avatarType: AvatarType,
|
||||
avatarShape: Shape,
|
||||
modifier: Modifier = Modifier,
|
||||
contentDescription: String? = null,
|
||||
) {
|
||||
@@ -30,7 +32,7 @@ internal fun TombstonedRoomAvatar(
|
||||
foreground = ElementTheme.colors.iconTertiary
|
||||
),
|
||||
modifier = modifier,
|
||||
avatarType = avatarType,
|
||||
avatarShape = avatarShape,
|
||||
contentDescription = contentDescription,
|
||||
)
|
||||
}
|
||||
@@ -40,7 +42,7 @@ internal fun TombstonedRoomAvatar(
|
||||
internal fun TombstonedRoomAvatarPreview() = ElementPreview {
|
||||
TombstonedRoomAvatar(
|
||||
size = AvatarSize.RoomListItem,
|
||||
avatarType = AvatarType.Room(),
|
||||
avatarShape = CircleShape,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ internal fun UserAvatar(
|
||||
InitialOrImageAvatar(
|
||||
avatarData = avatarData,
|
||||
hideAvatarImage = hideImage,
|
||||
avatarType = AvatarType.User,
|
||||
avatarShape = AvatarType.User.avatarShape(),
|
||||
modifier = modifier,
|
||||
contentDescription = contentDescription,
|
||||
forcedAvatarSize = forcedAvatarSize,
|
||||
|
||||
Reference in New Issue
Block a user