feat: Implement dynamic icon and text colors based on background luminance for improved accessibility

This commit is contained in:
2026-01-25 19:00:35 +05:00
parent ff900846d1
commit 89746c5bbd
4 changed files with 33 additions and 15 deletions

View File

@@ -898,7 +898,7 @@ fun ChatDetailScreen(
contentDescription =
"Call",
tint =
Color.White
if (isDarkTheme) Color.White else Color(0xFF007AFF)
)
}
}
@@ -931,7 +931,7 @@ fun ChatDetailScreen(
contentDescription =
"More",
tint =
Color.White,
if (isDarkTheme) Color.White else Color(0xFF007AFF),
modifier =
Modifier.size(
26.dp

View File

@@ -94,6 +94,15 @@ data class AvatarColors(val textColor: Color, val backgroundColor: Color)
private val avatarColorCache = mutableMapOf<String, AvatarColors>()
/**
* Определяет, является ли цвет светлым (true) или темным (false)
* Использует формулу relative luminance из WCAG
*/
fun isColorLight(color: Color): Boolean {
val luminance = 0.299f * color.red + 0.587f * color.green + 0.114f * color.blue
return luminance > 0.5f
}
fun getAvatarColor(name: String, isDarkTheme: Boolean): AvatarColors {
val cacheKey = "${name}_${if (isDarkTheme) "dark" else "light"}"
return avatarColorCache.getOrPut(cacheKey) {
@@ -453,7 +462,7 @@ fun ChatsListScreen(
text = accountName,
fontSize = 16.sp,
fontWeight = FontWeight.SemiBold,
color = Color.White
color = if (isColorLight(headerColor)) Color.Black else Color.White
)
}
@@ -465,11 +474,7 @@ fun ChatsListScreen(
"@$accountUsername",
fontSize = 13.sp,
color =
Color.White
.copy(
alpha =
0.7f
)
if (isColorLight(headerColor)) Color.Black.copy(alpha = 0.7f) else Color.White.copy(alpha = 0.7f)
)
}
}