is this Compose idiomatic? to convert this: ```@Co...
# compose
m
is this Compose idiomatic? to convert this:
Copy code
@Composable
fun Example() {
    Row(modifier = Modifier.fillMaxWidth()) {
        Text(
            text = "Left",
            modifier = Modifier.weight(1f),
        )
        Text(
            text = "Right",
            modifier = Modifier.weight(1f),
        )
    }
}
to:
Copy code
@Composable
fun Example(
    left: @Composable (Modifier) -> Unit,
    right: @Composable (Modifier) -> Unit,
    modifier: Modifier = Modifier,
) {
    Row(modifier = modifier.fillMaxWidth()) {
        left(Modifier.weight(1f))
        right(Modifier.weight(1f))
    }
}
am asking because of passing
Modifier
to parameter `@Composable`s. I want to hide
Modifier.weight(1f)
and I want everything using
Example
to have exactly 2 elements that occupy 50%/50% of space, without wrapping
left
and
right
into
Box
, for example, and applying
Modifier.weight(1f)
to
Box
container
f
TLDR: Consider creating custom layout
m
I did but I want to avoid that too 😄, there is more to it than what I posted. what I posted is just a gist of it and it’s actually more complex which why I want to avoid writing custom layout
f
This is my subjective opinion but this feels wrong and because you are asking this question, it probably feels wrong to you too. You have no guarantees that your child will use the passed modifier so the other logical argument "_I want everything using
Example
to have exactly 2 elements"_ does not feel like good enough reason and it basically becomes just a
Row
wrapper I would be interested in more information about why you want to avoid a custom layout?
In your example the composable just divides two content lambdas into equal space but that does not seem like is worth the effort of having function for that. (subjectively) Maybe describe your usecase more so someone can give you better answer than mine
(sorry for editing my messages constantly. I am still thinking about it 😄 )
a
without wrapping
left
and
right
into
Box
Also curious for the reason for wanting to avoid that as well?
m
@Filip Wiesner yes it feels wrong 😕.
left
and
right
should support layouts like
Column
, for example, and than (depending on what
left
and
right
are) alignment changes. it should support top and center vertical alignment etc. maybe it’s just too late and am overly complicating this in my head 😄
@Alex Vanyo I was worried about performance and I was lazy to go through docs and remind myself how Compose handles it 🙂. and it felt wrong, not as wrong as passing
Modifier
back to parameter `@Composable`s but still wrong
now that I typed it out I see how stupid it is, I won’t delete it for context sake
f
Rubber-ducking is the best way to prototype. You are welcome 😁
m
yeah 😄 thank you 😁