Skip to content

Commit

Permalink
fix: initials avatar use regex instead and add content description (W…
Browse files Browse the repository at this point in the history
…PB-10896) (#3433)
  • Loading branch information
yamilmedina authored Sep 12, 2024
1 parent b6df664 commit 59fe2d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/main/kotlin/com/wire/android/model/UserAvatarData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class NameBasedAvatar(val fullName: String?, val accentColor: Int) {
val initials: String
get() {
if (fullName.isNullOrEmpty()) return String.EMPTY
val names = fullName.split(" ").map { it.uppercase() }
val names = fullName.split(EMPTY_REGEX).filter { it.isNotEmpty() }.map { it.uppercase() }
return when {
names.size > 1 -> {
val initials = names.map { it.first() }
Expand All @@ -57,3 +57,5 @@ data class NameBasedAvatar(val fullName: String?, val accentColor: Int) {
}
}
}

val EMPTY_REGEX = "\\s".toRegex()
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
Expand Down Expand Up @@ -191,8 +193,10 @@ private fun DefaultInitialsAvatar(
avatarBorderSize: Dp,
size: Dp = MaterialTheme.wireDimensions.avatarDefaultSize
) {
val contentDescription = stringResource(R.string.content_description_user_avatar)
Box(
modifier = Modifier
.semantics { this.contentDescription = contentDescription }
.withAvatarSize(size, avatarBorderSize, dimensions().avatarStatusBorderSize, type)
.let { withAvatarBorders(type, avatarBorderSize, it) }
.clip(CircleShape)
Expand Down

0 comments on commit 59fe2d0

Please sign in to comment.