Hey folks, I have a question around this modifiers...
# compose
a
Hey folks, I have a question around this modifiers. I am looking at this documentation from here and specifically this part. I am trying to understand this better, does this mean something like this where parent passing the modifier to the child? If so, but then parent modifier is being passed to the child, so essentially parent modifier is being used by child. Any help understanding this would be really appreciated.
Copy code
@Composable
fun parent(modifier: Modifier = Modifier) {
  Child1(modifier)
  Child2(modifier)
}

@Composable
fun Child1(modifier: Modifier = Modifier) {
  // Some code to use modifier
}

@Composable
fun Child2(modifier: Modifier = Modifier) {
  // Some code to use modifier
}
s
Notice how it says "first" child and not all children? I would advise against reusing a modifier passed in as a parameter more than once, it is more or less always a mistake. Just like it is a mistake to have two composables that emit UI just top level like that and not wrapped in a box, column or some other such layout composable. Check this out too https://chrisbanes.me/posts/always-provide-a-modifier/ you will definitely find it interesting
👍 1
z
@zsmb's talk about Compose is really good and covers this: https://www.droidcon.com/2024/10/17/composing-an-api-the-right-way-3/
kodee loving 2
a
thanks folks. This is super helpful.