android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
17.38k stars 3.17k forks source link

Defining dimensions in dimens.xml - is this obsolete in Jetpack Compose? #188

Closed alvindizon closed 2 years ago

alvindizon commented 2 years ago

Looking in this repo, there is no use of dimens.xml and dimensionResource and sizes are used directly such as 18.dp. Is this the recommended way of using sizes now?

StylianosGakis commented 2 years ago

If you're pure compose this could simply be a Kotlin class somewhere like in core-designsystem module. What else would you expect to gain from a dimens.xml file in compose? I'm curious myself too tbh.

alvindizon commented 2 years ago

@StylianosGakis I was thinking you can have different dimens.xml for different densities, but you could technically do the same in Compose I imagine, you can do something similar to the method in this post

It would be cool to see how the Android team would handle font and spacing units for different densities

marlonlom commented 2 years ago

@StylianosGakis @alvindizon mmm, i undestand that you can use the similar approach for shapes or colors using kotlin objects for dimensions, in that sense, you could define the dimentions that are used in a common way (for example, a attribute in the Dimensions object with value of {n}.dp for textSize of a TitleTextComposable). @alvindizon theres a library, accompanish, that could sove something related to reuse xml in themes and styles for jetpack compose apps. you can check it out.

alexvanyo commented 2 years ago

I'm going to close this issue as not directly being related to the project, and more of a guidance and recommendation request.

dimensionResource will work, and would definitely make sense if you're sharing dimensions with non-Compose code as well. If you're fully Compose (like this app) than either approach will work and at that point, it's a matter of preference.