Fix quality checks

This commit is contained in:
Benoit Marty 2025-01-02 08:13:05 +01:00
parent 1d34ce8e71
commit 52648d2abf
3 changed files with 35 additions and 32 deletions

View file

@ -29,9 +29,11 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.text.toPx import io.element.android.libraries.designsystem.text.toPx
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
/** /**
* Draw a row of avatars (they must all have the same size), from start to end * Draw a row of avatars (they must all have the same size), from start to end.
* @param avatarDataList the avatars to render. Note: they will all be rendered, the caller may * @param avatarDataList the avatars to render. Note: they will all be rendered, the caller may
* want to limit the list size * want to limit the list size
* @param modifier Jetpack Compose modifier * @param modifier Jetpack Compose modifier
@ -40,7 +42,7 @@ import io.element.android.libraries.designsystem.text.toPx
*/ */
@Composable @Composable
fun AvatarRow( fun AvatarRow(
avatarDataList: List<AvatarData>, avatarDataList: ImmutableList<AvatarData>,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
overlapRatio: Float = 0.5f, overlapRatio: Float = 0.5f,
) { ) {
@ -56,34 +58,34 @@ fun AvatarRow(
.forEachIndexed { index, avatarData -> .forEachIndexed { index, avatarData ->
Avatar( Avatar(
modifier = Modifier modifier = Modifier
.padding(start = avatarSize * (1 - overlapRatio) * (lastItemIndex - index)) .padding(start = avatarSize * (1 - overlapRatio) * (lastItemIndex - index))
.graphicsLayer { .graphicsLayer {
compositingStrategy = CompositingStrategy.Offscreen compositingStrategy = CompositingStrategy.Offscreen
}
.drawWithContent {
// Draw content and clear the pixels for the avatar on the left (right in RTL).
drawContent()
val xOffset = if (isRtl) {
size.width - avatarSizePx * (overlapRatio - 0.5f)
} else {
0f + avatarSizePx * (overlapRatio - 0.5f)
} }
if (index < lastItemIndex) { .drawWithContent {
drawCircle( // Draw content and clear the pixels for the avatar on the left (right in RTL).
color = Color.Black, drawContent()
center = Offset( val xOffset = if (isRtl) {
x = xOffset, size.width - avatarSizePx * (overlapRatio - 0.5f)
y = size.height / 2, } else {
), 0f + avatarSizePx * (overlapRatio - 0.5f)
radius = avatarSizePx / 2, }
blendMode = BlendMode.Clear, if (index < lastItemIndex) {
) drawCircle(
color = Color.Black,
center = Offset(
x = xOffset,
y = size.height / 2,
),
radius = avatarSizePx / 2,
blendMode = BlendMode.Clear,
)
}
} }
} .size(size = avatarSize)
.size(size = avatarSize) // Keep internal padding, it has the advantage to not reduce the size of the Avatar image,
// Keep internal padding, it has the advantage to not reduce the size of the Avatar image, // which is already small in our use case.
// which is already small in our use case. .padding(2.dp),
.padding(2.dp),
avatarData = avatarData, avatarData = avatarData,
) )
} }
@ -113,15 +115,13 @@ internal fun AvatarRowRtlPreview(@PreviewParameter(OverlapRatioProvider::class)
@Composable @Composable
private fun ContentToPreview(overlapRatio: Float) { private fun ContentToPreview(overlapRatio: Float) {
AvatarRow( AvatarRow(
avatarDataList = listOf( avatarDataList = listOf("A", "B", "C").map {
"A", "B", "C"
).map {
AvatarData( AvatarData(
id = it, id = it,
name = it, name = it,
size = AvatarSize.RoomListItem, size = AvatarSize.RoomListItem,
) )
}, }.toImmutableList(),
overlapRatio = overlapRatio, overlapRatio = overlapRatio,
) )
} }

View file

@ -49,6 +49,7 @@ import io.element.android.libraries.designsystem.theme.components.Surface
import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
private const val MAX_AVATAR_COUNT = 3 private const val MAX_AVATAR_COUNT = 3
@ -210,6 +211,7 @@ private fun KnockRequestAvatarListView(
.map { knockRequest -> .map { knockRequest ->
knockRequest.getAvatarData(AvatarSize.KnockRequestBanner) knockRequest.getAvatarData(AvatarSize.KnockRequestBanner)
} }
.toImmutableList()
AvatarRow( AvatarRow(
avatarDataList = avatars, avatarDataList = avatars,
modifier = modifier, modifier = modifier,

View file

@ -50,6 +50,7 @@ class KonsistClassNameTest {
.withAllParentsOf(PreviewParameterProvider::class) .withAllParentsOf(PreviewParameterProvider::class)
.withoutName( .withoutName(
"AspectRatioProvider", "AspectRatioProvider",
"OverlapRatioProvider",
) )
.also { .also {
// Check that classes are actually found // Check that classes are actually found