Group preview for clarity and to limit the number of screenshots.

This commit is contained in:
Benoit Marty
2026-08-24 16:37:36 +02:00
parent 0a0eebd804
commit 7d6aa9eb76
2 changed files with 58 additions and 46 deletions
@@ -9,12 +9,15 @@
package io.element.android.libraries.matrix.ui.messages.sender
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
@@ -136,9 +139,27 @@ private fun RowScope.SecondaryText(
internal fun SenderNamePreview(
@PreviewParameter(SenderNameDataPreviewParam::class) senderNameData: SenderNameData,
) = ElementPreview {
SenderName(
senderId = senderNameData.userId,
senderProfile = senderNameData.profileDetails,
senderNameMode = senderNameData.senderNameMode,
)
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
sequenceOf(
SenderNameMode.Timeline(mainColor = Color.Red),
SenderNameMode.Reply,
SenderNameMode.ActionList,
).forEach { mode ->
Column {
Text(
"Rendering in mode ${mode::class.simpleName}:",
style = ElementTheme.typography.fontBodyXsRegular,
color = ElementTheme.colors.textSecondary,
)
SenderName(
senderId = senderNameData.userId,
senderProfile = senderNameData.profileDetails,
senderNameMode = mode,
)
}
}
}
}
@@ -8,7 +8,6 @@
package io.element.android.libraries.matrix.ui.messages.sender
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import io.element.android.libraries.matrix.api.core.UserId
import io.element.android.libraries.matrix.api.timeline.item.event.ProfileDetails
@@ -19,54 +18,47 @@ import io.element.android.libraries.matrix.ui.messages.reply.aProfileDetailsRead
data class SenderNameData(
val userId: UserId,
val profileDetails: ProfileDetails,
val senderNameMode: SenderNameMode,
)
open class SenderNameDataPreviewParam : PreviewParameterProvider<SenderNameData> {
override val values: Sequence<SenderNameData>
get() = sequenceOf(
SenderNameMode.Timeline(mainColor = Color.Red),
SenderNameMode.Reply,
SenderNameMode.ActionList,
aSenderNameData(),
aSenderNameData(
displayNameAmbiguous = true,
),
aSenderNameData(
profileDetails = ProfileDetails.Unavailable,
),
aSenderNameData(
displayName = null,
),
aSenderNameData(
displayedStatus = DisplayedStatus.UserSet(
status = UserStatus(
emoji = "😀",
text = "Should not be rendered",
),
),
),
aSenderNameData(
displayedStatus = DisplayedStatus.InCall(0L),
),
aSenderNameData(
displayNameAmbiguous = true,
displayedStatus = DisplayedStatus.UserSet(
status = UserStatus(
emoji = "😀",
text = "Should not be rendered",
),
),
),
)
.flatMap { senderNameMode ->
sequenceOf(
aSenderNameData(
senderNameMode = senderNameMode,
),
aSenderNameData(
senderNameMode = senderNameMode,
displayNameAmbiguous = true,
),
aSenderNameData(
senderNameMode = senderNameMode,
profileDetails = ProfileDetails.Unavailable,
),
aSenderNameData(
senderNameMode = senderNameMode,
displayName = null,
),
aSenderNameData(
senderNameMode = senderNameMode,
displayedStatus = DisplayedStatus.UserSet(
status = UserStatus(
emoji = "😀",
text = "Should not be rendered",
),
),
),
aSenderNameData(
senderNameMode = senderNameMode,
displayedStatus = DisplayedStatus.InCall(0L),
)
)
}
}
private fun aSenderNameData(
senderNameMode: SenderNameMode,
userId: UserId = UserId("@alice:${senderNameMode.javaClass.simpleName.lowercase()}"),
displayName: String? = "Alice ${senderNameMode.javaClass.simpleName}",
userId: UserId = UserId("@alice:example.com"),
displayName: String? = "Alice",
displayNameAmbiguous: Boolean = false,
displayedStatus: DisplayedStatus? = null,
profileDetails: ProfileDetails = aProfileDetailsReady(
@@ -77,5 +69,4 @@ private fun aSenderNameData(
) = SenderNameData(
userId = userId,
profileDetails = profileDetails,
senderNameMode = senderNameMode,
)