3

I'm trying out jetpack compose library how to create separate compose functions based on screen density, screen orientation, locale in an organized way

class Success(private val body: String) : MyViewState() {
    @Composable
    override fun buildUI() {
        Padding(padding = 16.dp) {
            Text(text = body, style = +themeTextStyle { body1 })
        }
    }
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Arunachalam k
  • 734
  • 1
  • 7
  • 20

1 Answers1

4

I think you can just use something like this:

val resources = LocalContext.current.resources
val density = resources.displayMetrics.density
val densityDpi = resources.displayMetrics.densityDpi
Log.d(TAG, "density: $density - $densityDpi")

And do your logic... You can also compare densityDpi with DisplayMetrics.DENSITY_*. Check this answer here.

nglauber
  • 18,674
  • 6
  • 70
  • 75