https://kotlinlang.org logo
#compose
Title
# compose
j

jordond

07/15/2023, 4:41 PM
I’m building an app that lets the user select any arbitrary color. I then want to take that color and theme some components off of it. Is there a way in Compose to take a color and generate a theme? Or even some lighter/darker versions of it?
s

Stylianos Gakis

07/15/2023, 5:24 PM
Also maybe this? https://github.com/Kyant0/m3color I think there must be something else too which I can't find atm
j

jordond

07/15/2023, 5:39 PM
Thanks! I’ll give them a look 👍
In case anyone else comes across this thread, and wants to generate dynamic color schemes. I’ve turned material-color-utilites (which the above m3color is based on) into a Compose Multiplatform library: https://github.com/jordond/materialkolor
s

Stylianos Gakis

07/17/2023, 8:36 PM
That’s pretty cool! Does this just generate a m3 colorScheme directly, or are the parts that just generate a palette exposed too? We use a mix of material3 colorScheme + some of our own tokens, so getting access to the underlying palette would be necessary to be able to adapt something like this fully. And I assume other people are doing the same too
j

jordond

07/17/2023, 8:53 PM
It just uses this class from material-color-utilities to generate the color from the token which uses that libraries
DynamicColor.fromPalette()
. But I suppose there is nothing stopping you from using
DynamicColor.fromPalette()
yourself. If you had an example of the functionality you wanted, I could look into implementing it.