Now that we use a cache, there is no need to provide AvatarColors to the Avatar composable.
This commit is contained in:
committed by
Benoit Marty
parent
5a85efc458
commit
fad442760d
@@ -42,8 +42,6 @@ import io.element.android.features.ftue.impl.R
|
||||
import io.element.android.libraries.designsystem.atomic.molecules.ButtonColumnMolecule
|
||||
import io.element.android.libraries.designsystem.atomic.molecules.IconTitleSubtitleMolecule
|
||||
import io.element.android.libraries.designsystem.atomic.pages.HeaderFooterPage
|
||||
import io.element.android.libraries.designsystem.colors.AvatarColors
|
||||
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
|
||||
@@ -67,7 +65,7 @@ fun NotificationsOptInView(
|
||||
modifier = modifier
|
||||
.systemBarsPadding()
|
||||
.fillMaxSize(),
|
||||
header = { NotificationsOptInHeader(modifier = Modifier.padding(top = 60.dp, bottom = 12.dp),) },
|
||||
header = { NotificationsOptInHeader(modifier = Modifier.padding(top = 60.dp, bottom = 12.dp)) },
|
||||
footer = { NotificationsOptInFooter(state) },
|
||||
) {
|
||||
NotificationsOptInContent(modifier = Modifier.fillMaxWidth())
|
||||
@@ -119,21 +117,21 @@ private fun NotificationsOptInContent(
|
||||
) {
|
||||
NotificationRow(
|
||||
avatarLetter = "M",
|
||||
avatarColors = AvatarColorsProvider.provide("5", ElementTheme.isLightTheme),
|
||||
avatarColorsId = "5",
|
||||
firstRowPercent = 1f,
|
||||
secondRowPercent = 0.4f
|
||||
)
|
||||
|
||||
NotificationRow(
|
||||
avatarLetter = "A",
|
||||
avatarColors = AvatarColorsProvider.provide("1", ElementTheme.isLightTheme),
|
||||
avatarColorsId = "1",
|
||||
firstRowPercent = 1f,
|
||||
secondRowPercent = 1f
|
||||
)
|
||||
|
||||
NotificationRow(
|
||||
avatarLetter = "T",
|
||||
avatarColors = AvatarColorsProvider.provide("4", ElementTheme.isLightTheme),
|
||||
avatarColorsId = "4",
|
||||
firstRowPercent = 0.65f,
|
||||
secondRowPercent = 0f
|
||||
)
|
||||
@@ -144,7 +142,7 @@ private fun NotificationsOptInContent(
|
||||
@Composable
|
||||
private fun NotificationRow(
|
||||
avatarLetter: String,
|
||||
avatarColors: AvatarColors,
|
||||
avatarColorsId: String,
|
||||
firstRowPercent: Float,
|
||||
secondRowPercent: Float,
|
||||
modifier: Modifier = Modifier
|
||||
@@ -161,8 +159,7 @@ private fun NotificationRow(
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Avatar(
|
||||
avatarData = AvatarData(id = "", name = avatarLetter, size = AvatarSize.NotificationsOptIn),
|
||||
initialAvatarColors = avatarColors,
|
||||
avatarData = AvatarData(id = avatarColorsId, name = avatarLetter, size = AvatarSize.NotificationsOptIn),
|
||||
)
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Box(
|
||||
@@ -174,7 +171,8 @@ private fun NotificationRow(
|
||||
)
|
||||
if (secondRowPercent > 0f) {
|
||||
Box(
|
||||
modifier = Modifier.clip(CircleShape)
|
||||
modifier = Modifier
|
||||
.clip(CircleShape)
|
||||
.fillMaxWidth(secondRowPercent)
|
||||
.height(10.dp)
|
||||
.background(ElementTheme.colors.borderInteractiveSecondary)
|
||||
|
||||
@@ -346,7 +346,7 @@ private fun MessageSenderInformation(
|
||||
}
|
||||
// Content
|
||||
Row {
|
||||
Avatar(senderAvatar, initialAvatarColors = avatarColors)
|
||||
Avatar(senderAvatar)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
Text(
|
||||
text = sender,
|
||||
|
||||
@@ -32,7 +32,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import io.element.android.libraries.designsystem.colors.AvatarColors
|
||||
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
||||
import io.element.android.libraries.designsystem.preview.ElementThemedPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewGroup
|
||||
@@ -46,17 +45,14 @@ import timber.log.Timber
|
||||
fun Avatar(
|
||||
avatarData: AvatarData,
|
||||
modifier: Modifier = Modifier,
|
||||
initialAvatarColors: AvatarColors? = null,
|
||||
contentDescription: String? = null,
|
||||
) {
|
||||
val commonModifier = modifier
|
||||
.size(avatarData.size.dp)
|
||||
.clip(CircleShape)
|
||||
if (avatarData.url.isNullOrBlank()) {
|
||||
val avatarColors = initialAvatarColors ?: AvatarColorsProvider.provide(avatarData.id, ElementTheme.isLightTheme)
|
||||
InitialsAvatar(
|
||||
avatarData = avatarData,
|
||||
avatarColors = avatarColors,
|
||||
modifier = commonModifier,
|
||||
)
|
||||
} else {
|
||||
@@ -89,9 +85,9 @@ private fun ImageAvatar(
|
||||
@Composable
|
||||
private fun InitialsAvatar(
|
||||
avatarData: AvatarData,
|
||||
avatarColors: AvatarColors,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val avatarColors = AvatarColorsProvider.provide(avatarData.id, ElementTheme.isLightTheme)
|
||||
Box(
|
||||
modifier.background(color = avatarColors.background)
|
||||
) {
|
||||
|
||||
@@ -24,11 +24,9 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.colors.AvatarColorsProvider
|
||||
import io.element.android.libraries.designsystem.preview.DayNightPreviews
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.theme.ElementTheme
|
||||
import io.element.android.libraries.theme.colors.avatarColorsLight
|
||||
|
||||
@DayNightPreviews
|
||||
@@ -44,7 +42,7 @@ internal fun UserAvatarPreview() = ElementPreview {
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
// Note: it's OK, since the hash of "0" is 0, the hash of "1" is 1, etc.
|
||||
Avatar(anAvatarData(), initialAvatarColors = AvatarColorsProvider.provide("$it", ElementTheme.isLightTheme))
|
||||
Avatar(anAvatarData(id = "$it"))
|
||||
Text(text = "Color index $it")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user