Provide avatarShape: Shape instead of AvatarType to sub composable functions
This commit is contained in:
parent
db98e3c146
commit
ddca92a353
8 changed files with 28 additions and 21 deletions
|
|
@ -14,6 +14,7 @@ import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import coil3.compose.AsyncImagePainter
|
import coil3.compose.AsyncImagePainter
|
||||||
|
|
@ -24,7 +25,7 @@ import timber.log.Timber
|
||||||
@Composable
|
@Composable
|
||||||
internal fun ImageAvatar(
|
internal fun ImageAvatar(
|
||||||
avatarData: AvatarData,
|
avatarData: AvatarData,
|
||||||
avatarType: AvatarType,
|
avatarShape: Shape,
|
||||||
forcedAvatarSize: Dp?,
|
forcedAvatarSize: Dp?,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentDescription: String? = null,
|
contentDescription: String? = null,
|
||||||
|
|
@ -35,8 +36,8 @@ internal fun ImageAvatar(
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
contentScale = ContentScale.Companion.Crop,
|
contentScale = ContentScale.Companion.Crop,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.size(size)
|
.size(size)
|
||||||
.clip(avatarType.avatarShape())
|
.clip(avatarShape)
|
||||||
) {
|
) {
|
||||||
val collectedState by painter.state.collectAsState()
|
val collectedState by painter.state.collectAsState()
|
||||||
when (val state = collectedState) {
|
when (val state = collectedState) {
|
||||||
|
|
@ -50,14 +51,14 @@ internal fun ImageAvatar(
|
||||||
}
|
}
|
||||||
InitialLetterAvatar(
|
InitialLetterAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarShape,
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else -> InitialLetterAvatar(
|
else -> InitialLetterAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarShape,
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,14 @@ package io.element.android.libraries.designsystem.components.avatar
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
internal fun InitialLetterAvatar(
|
internal fun InitialLetterAvatar(
|
||||||
avatarData: AvatarData,
|
avatarData: AvatarData,
|
||||||
avatarType: AvatarType,
|
avatarShape: Shape,
|
||||||
forcedAvatarSize: Dp?,
|
forcedAvatarSize: Dp?,
|
||||||
contentDescription: String?,
|
contentDescription: String?,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
|
@ -24,7 +25,7 @@ internal fun InitialLetterAvatar(
|
||||||
TextAvatar(
|
TextAvatar(
|
||||||
text = avatarData.initialLetter,
|
text = avatarData.initialLetter,
|
||||||
size = forcedAvatarSize ?: avatarData.size.dp,
|
size = forcedAvatarSize ?: avatarData.size.dp,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarShape,
|
||||||
colors = avatarColors,
|
colors = avatarColors,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ package io.element.android.libraries.designsystem.components.avatar
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -16,21 +17,21 @@ internal fun InitialOrImageAvatar(
|
||||||
avatarData: AvatarData,
|
avatarData: AvatarData,
|
||||||
hideAvatarImage: Boolean,
|
hideAvatarImage: Boolean,
|
||||||
forcedAvatarSize: Dp?,
|
forcedAvatarSize: Dp?,
|
||||||
avatarType: AvatarType,
|
avatarShape: Shape,
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
contentDescription: String?
|
contentDescription: String?
|
||||||
) {
|
) {
|
||||||
when {
|
when {
|
||||||
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
avatarData.url.isNullOrBlank() || hideAvatarImage -> InitialLetterAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarShape,
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
else -> ImageAvatar(
|
else -> ImageAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarShape,
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ internal fun RoomAvatar(
|
||||||
TombstonedRoomAvatar(
|
TombstonedRoomAvatar(
|
||||||
size = avatarData.size,
|
size = avatarData.size,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarType.avatarShape(),
|
||||||
contentDescription = contentDescription
|
contentDescription = contentDescription
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ internal fun RoomAvatar(
|
||||||
InitialOrImageAvatar(
|
InitialOrImageAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
hideAvatarImage = hideAvatarImage,
|
hideAvatarImage = hideAvatarImage,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarType.avatarShape(),
|
||||||
forcedAvatarSize = null,
|
forcedAvatarSize = null,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ internal fun SpaceAvatar(
|
||||||
when {
|
when {
|
||||||
avatarType.isTombstoned -> TombstonedRoomAvatar(
|
avatarType.isTombstoned -> TombstonedRoomAvatar(
|
||||||
size = avatarData.size,
|
size = avatarData.size,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarType.avatarShape(),
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
else -> InitialOrImageAvatar(
|
else -> InitialOrImageAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
hideAvatarImage = hideAvatarImage,
|
hideAvatarImage = hideAvatarImage,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarType.avatarShape(),
|
||||||
forcedAvatarSize = null,
|
forcedAvatarSize = null,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||||
import androidx.compose.ui.semantics.contentDescription
|
import androidx.compose.ui.semantics.contentDescription
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
|
@ -36,13 +38,13 @@ internal fun TextAvatar(
|
||||||
size: Dp,
|
size: Dp,
|
||||||
colors: AvatarColors,
|
colors: AvatarColors,
|
||||||
contentDescription: String?,
|
contentDescription: String?,
|
||||||
avatarType: AvatarType,
|
avatarShape: Shape,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier
|
modifier
|
||||||
.size(size)
|
.size(size)
|
||||||
.clip(avatarType.avatarShape())
|
.clip(avatarShape)
|
||||||
.background(color = colors.background)
|
.background(color = colors.background)
|
||||||
) {
|
) {
|
||||||
val fontSize = size.toSp() / 2
|
val fontSize = size.toSp() / 2
|
||||||
|
|
@ -83,7 +85,7 @@ internal fun TextAvatarPreview() = ElementPreview {
|
||||||
background = ElementTheme.colors.bgSubtlePrimary,
|
background = ElementTheme.colors.bgSubtlePrimary,
|
||||||
foreground = ElementTheme.colors.iconPrimary,
|
foreground = ElementTheme.colors.iconPrimary,
|
||||||
),
|
),
|
||||||
avatarType = avatarType,
|
avatarShape = CircleShape,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,10 @@
|
||||||
|
|
||||||
package io.element.android.libraries.designsystem.components.avatar
|
package io.element.android.libraries.designsystem.components.avatar
|
||||||
|
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import io.element.android.compound.theme.AvatarColors
|
import io.element.android.compound.theme.AvatarColors
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
|
|
@ -18,7 +20,7 @@ import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||||
@Composable
|
@Composable
|
||||||
internal fun TombstonedRoomAvatar(
|
internal fun TombstonedRoomAvatar(
|
||||||
size: AvatarSize,
|
size: AvatarSize,
|
||||||
avatarType: AvatarType,
|
avatarShape: Shape,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentDescription: String? = null,
|
contentDescription: String? = null,
|
||||||
) {
|
) {
|
||||||
|
|
@ -30,7 +32,7 @@ internal fun TombstonedRoomAvatar(
|
||||||
foreground = ElementTheme.colors.iconTertiary
|
foreground = ElementTheme.colors.iconTertiary
|
||||||
),
|
),
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
avatarType = avatarType,
|
avatarShape = avatarShape,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +42,7 @@ internal fun TombstonedRoomAvatar(
|
||||||
internal fun TombstonedRoomAvatarPreview() = ElementPreview {
|
internal fun TombstonedRoomAvatarPreview() = ElementPreview {
|
||||||
TombstonedRoomAvatar(
|
TombstonedRoomAvatar(
|
||||||
size = AvatarSize.RoomListItem,
|
size = AvatarSize.RoomListItem,
|
||||||
avatarType = AvatarType.Room(),
|
avatarShape = CircleShape,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ internal fun UserAvatar(
|
||||||
InitialOrImageAvatar(
|
InitialOrImageAvatar(
|
||||||
avatarData = avatarData,
|
avatarData = avatarData,
|
||||||
hideAvatarImage = hideImage,
|
hideAvatarImage = hideImage,
|
||||||
avatarType = AvatarType.User,
|
avatarShape = AvatarType.User.avatarShape(),
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
forcedAvatarSize = forcedAvatarSize,
|
forcedAvatarSize = forcedAvatarSize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue