Hi Guys, I got an interesting question about jetpack compose margin.
As we can implement margin using padding or Spacer;
Is it better to use padding instead?
I said that because I now each composable is passed through compose, layout, drawing steps and I thought setting padding is just done on layout phase of that composable but Spacer will be passed in 3 phases separately. And Spacer creates extra Layout.
Am I right?!
a
Alexander Maryanovsky
03/06/2022, 11:06 AM
It's very unlikely that there is a significant performance penalty for using Spacer. It's not an Android View, and is very lightweight
☝🏻 1
c
Colton Idle
03/06/2022, 9:59 PM
Spacer does typically make for better reusability in components. There were some good convos about this a while back (like a year ago+)
if you search this url in the chat history you'll get some details, but then again this blog post pretty much nails it.
https://mxstbr.com/thoughts/margin/
➕ 1
t
Tash
03/07/2022, 1:47 AM
+1 ^ also
Spacer
is very deliberate; if you want to add space between something, then do it explicitly with a component that's made for it, rather than exploiting the padding/margin of something else.