Why when you pass modifier to a Button() and pass ...
# compose
n
Why when you pass modifier to a Button() and pass the same to inside element of the button like Column() the modifier was modified by the button and not be the same ? For Example :
Copy code
val modifier = Modifier.fillMaxSize()
Button(....,
modifier= modifier) {
   Column(modifier = modifier) {
      Text(...., modifier = modifier)
   }
}
The text was not just with fillMaxSize it has the padding the button add on modifier too.
c
I guess modifier instances are mutable; it definitely isn't typical to be passing one modifier instance into multiple composables though
though it should be said, even without a modifier, a button does introduce some padding to anything you place inside it
s
What great timing to watch this video

https://youtu.be/BjGX2RftXsU?t=324

where Leland explains why each composable like that despite coming from the same val results in different instances of the Modifier. A perfect example with a modifier having a clickable and being applied to multiple composables doesn’t mean that the ripple will be synced across the two modifiers. So no it’s not that the modifier is mutated, but maybe you’re experiencing the button adding paddings and such that you did not explicitly make yourself.
r
You should also only reuse modifiers on the same scoped, direct level children, check the tips here for reusing modifiers: https://developer.android.com/jetpack/compose/modifiers#extracting_and_reusing_scoped_modifiers