Kind of hard to describe but in Compose is it poss...
# compose
d
Kind of hard to describe but in Compose is it possible to detect the background color. So on a surface you can for example set the color to MaterialTheme.colors.surface or MaterialTheme.colors.primary. So I have a custom composable function wrapper for Button. I want it to be certain colors onSurface and another color onPrimary.
m
If the code for the background updates the
LocalContentColor
then that will provide the correct color for the background.
Surface
takes it's color and looks up to see if it matches colors in the
MaterialTheme
if it does it sets the
LocaleContentColor
to match the
on
version for that. See
Colors.contentColorFor
But the general rule is that you don't look up the tree to see what to do, but let the parent view tell you what you should be doing.
c
You might consider getting the value of a known color key, e.g. MaterialTheme.colors.surface (or whatever key you know is being used for the background), in a composition, and then do a calculation to figure out what color to use. It sounds like you are making color choices based on contrast of the button with a background it sits on, versus the previous comment above is more mapping keys together semantically (<x> with on<x>).
d
Thanks both of you. I got it working and understand what both of you are saying. Helped me learn how compose works more with colors. Thanks again
👍 1
c
Happy to help!