To dip or not to dp, that is the compose question

To dip or not to dp, that is the compose question

I know what you are thinking, why wasn’t this feature shipped with the compose 1.0, a travesty! Well don’t worry because now it’s here, by un-popular demand. No longer do you have to pine for the good old days, no longer do you have to think “I don’t like change”. Now, you can once again use dips in your layouts and paddings!

Introducing compose-deeply-dippy, this is a tongue-in-cheek library that allows you to reference Device Independent Pixels with the .dip extension instead of the obvious choice of .dp. That’s right n.dip is now available instead of being stuck with n.dp.

TLDR?! Keep reading, so you can do this:

Text(
  modifier = Modifier.padding(16.dip),
  text = "Hello World",
)

I tried to find some official documentation to quote (i.e. here) in case you are a whipper snapper and just think I am crazy, but the docs have been updated and Android have erased history! (Or am I actually crazy, and this never was?).

I managed to find someone who had quoted the docs, at this stackoverflow question here. So luckily I can quote the quote and the history of the Android docs lives on:

  1. dp or dip
    Density-independent Pixels – an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both “dip” and “dp”, though “dp” is more consistent with “sp”.

The compiler accepts both, how kind! Well now compose can accept both, just use compose-deeply-dippy!

To get started, add the maven central dependency like so:

implementation 'io.github.blundell:compose-deeply-dippy:1.0.0'

Sync you’re project and you are good to go! Look at this, glorious:

Text(
  modifier = Modifier.padding(16.dip),
  text = "Hello World",
)

That’s it, good luck have fun!

You can find the open source repository here on GitHub.

I’m just deeply dippy bout the way you code. Please enjoy this serious/not so serious library. Pull requests welcome, and tweet it to the world!

Deeply dippy bout the code you’ve got
Deeply hot
Hot for the code you’ve got
Deeply dippy bout the modifier
Deeply mad
Mad for the modifier

Oh… my compose
I can’t make head nor tail of passion
Oh…my compose
Lets set sail for the seas of Android now

Right Said Fred (or thereabouts)

Not got the reference and still reading? Here you go..