https://kotlinlang.org logo
Title
k

Kyant

04/29/2023, 12:34 PM
I think there is a bug in
contentColorFor()
, when there are two same background colors in a color scheme, it will always return the first content color in both even if we use the second color. I use
contentColorFor(MaterialTheme.colorScheme.surface)
but it gives me
onBackground
.
IMG_20230429_204732_377.jpg
s

Stylianos Gakis

04/29/2023, 2:22 PM
If
background
and
surface
are the exact same color, wouldn’t it make sense that
onBackground
and
onSurface
are also the same color?
k

Kyant

04/29/2023, 2:39 PM
No, in my design system, onBackground has less contrast than onSurface in dark theme.
Like the new text contrast feature in Android 14, they may be different.
s

Stylianos Gakis

04/29/2023, 2:44 PM
That's interesting yeah, I guess it's not that weird of a thing. I'd file a feature request on the issue tracker and link it back here, to see what folks from Google think about this too.
r

romainguy

04/29/2023, 6:15 PM
Considering how this API works I don't see how it could give you the color you want when multiple colors are equal values.
k

Kyant

04/30/2023, 3:38 AM
Well, so do you consider replacing it with other API? I have to add
contentColor
for all
Surface
.
Or I can add a small value to every channel of
background
.