-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Android Jetpack Compose #478
Comments
I think having a Kotlin support would be awesome! Totally agree that having a more idiomatic integration would be great. The power of design tokens is that developers consuming them on different platforms should interact with them as if they were native to the platform. If you have the time, you can open a PR to add transforms and formats to support Kotlin/Jetpack Compose. A good example PR is this one adding Flutter support: #320. |
My team is using the style dictionary and is also interested in first-class Jetpack Compose support. Bumping this thread in case anyone is able to prioritize it. |
I noticed that @dbanksdesign's comment was posted in October before his recent contribution to Style Dictionary v3.0 which adds support for an android resources format. #509 (Thanks!) When this Jetpack Compose feature is implemented, it would be great to offer similar functionality that creates Kotlin files based on a custom Filter. This allows developers to specify the type (String, Int, Color) and units (dp, sp, none) for their Style Dictionary setup. Currently, the production version of the Style Dictionary is a bit lacking because the Android transformGroup requires your project to use color, size, etc as your top-level token category names. (I'm not sure if that is the case for other platforms). As the PR and related Issue notes, if your design system had a different naming convention, the result was that no tokens were generated in the output. I think it's still a nice feature to have for those who use it, but we should also continue to support the same functionality as #509 here, too. |
@dbanksdesign I've been starting to look at this again, particularly with respect to colors and light/dark modes. I've also poked around at #399 and #307 . I'm interested in hearing your thoughts on how to make light/dark mode work for Compose. Adding support for light/dark mode in the Android resource system should be fairly straightforward, since we can easily create separate colors.xml resource files in the Compose is a bit of a different beast- in a perfect Compose world we wouldn't be touching resources at all and all our colors would be defined in Kotlin files. The way Material approaches colors in Compose is to have a class Colors(
val primary: Color
) You would then configure light and dark mode variants by creating instances of this class: object Palette {
val orange = Color(0xffff781f)
val orangeDark = Color(0xffff9d5c)
}
val lightColors = Colors(
primary = Palette.orange
)
val darkColors = Colors(
primary = Palette.orangeDark
) Ideally what I want from Style Dictionary is a structure that looks like this for the themed colors, with:
|
The other side of the equation is what this should look like in a Style Dictionary JSON style properties file- Maybe something like this? {
"color": {
"palette": {
"orange": { "value": "#ff781f" },
"orangeDark": { "value": "#ff781f" },
},
"theme": {
"primary": {
"themeable": true,
"light": { "value": "{color.palette.orange}" },
"dark": { "value": "{color.palette.orangeDark}" }
}
}
}
} |
I took a swing at what a format that supports dark mode in Compose might look like based on your work-in-progress dark mode repo: https://gist.github.com/bherbst/1b8c9a66953f25044631db68dd773429 There's a bit of awkward juggling to get the references to the |
Jetpack Compose is the future of Android UI development, and I'd love to see first-class support for Compose in style dictionary.
While Jetpack Compose has an interop layer with style resources, I would love to see a more idiomatic integration.
For example, today with Compose + Style Dictionary we could do:
But I would much rather have Style Dictionary generate a Kotlin file containing the colors so we can have something like this:
The text was updated successfully, but these errors were encountered: