Is it more efficient to use `Arrangement.spacedBy(...
# compose
j
Is it more efficient to use
Arrangement.spacedBy(NUMBER.dp)
or a
Spacer(…)
in `Column`/`Row` or performance indistinguishable.
g
performance wise dont know, but spacedBy is quite convenient, if you apply the padding on the items yourself, you're gonna have to check their index (first and last ones) so definitly go for spacedBy, it's meant for that!
b
I think both should be comparable, as they're only impacting the layout phase. There may be a small difference if there are a lot of Spacer, as
spacedBy
will do the computation globally. Other than that, agree with @Guillaume B that it's more clear imho
v
My approach is to always go for
spacedBy
up until the point where you need visibility animations (disappearing items, e.g. using
AnimatedVisibility
). As that makes a very glitchy animation, as when one of the items disappears, the additional
spacedBy
padding for said item disappears in a glitchy manner (0 duration) when the full animation of
AnimatedVisibility
ends.
j
I prefer using spacing using `horizontalArrangement`/`verticalArrangement` opposed to
Spacer()
, I think placement, should be the job of the parent layout. If I custom spacing for a given child, I opt for using
Modifier.padding(...)
. A project I’m working on using
Spacers
and I wanted to know if there were any performance differences.
v
My unfounded guess would be that
arrangement
is more performant, as adding a
Spacer
adds a
Layout()
composable. So basically +1 node. And in the case of
arrangement
it's just additional math in the measruement/layout calls in an already present composable. So, presuming a little bit more math > a new basic composable