If I have a Container composable that takes a list...
# compose
c
If I have a Container composable that takes a list of other composables to display, and can display that list in a Row, is there any way to add a modifier to each composable, even though I don't know what each composable is?
Copy code
fun SomeContainer(
    content: List<@Composable () -> Unit>)
  Row(
         Modifier.horizontalScroll(rememberScrollState()).height(IntrinsicSize.Min),
        ) {
            content.forEach {
                it(Modifier.fillMaxHeight()) <----- Anyway to get something like this
            }
        }
Wrapping it in a box for example doesn't help me, because although the box will get the modifier, the composable inside the box will not draw to fill max height.
c
In terms of syntax I think all you would need for this to work would be to add the Modifier as a parameter to your composable list items.
List<@Composable (Modifier) -> Unit>
apart from that I'm not sure if the modifier just isn't working or you were having a problem getting the modifier to your composable
z
Do you need to use
propagateMinConstraints=true
in the
Box
?
If that’s the only issue with the Box approach then
propagateMinConstraints
should fix it.
c
Could you also post a picture of what you're trying to accomplish? I'm curious now 😄
c
Basically my SomeContainer, is a Carousel that can take in any item and make a carousel out of it. My design team has 8 different "card" types that they want the freedom of putting into a "carousel" Hence that's what I'm trying to do. Going to play around with the suggestion from Zach although I think I mightve gotten it working...
c
although the box will get the modifier, the composable inside the box will not draw to fill max height.
At least for this, I think what could help is to make sure you can pass modifiers down to the first item container in the Row, then to the content composable itself in that container. And then also “hoist” the content composable declaration to the SomeContainer level?
c
so i played around with this a lot yesterday, and my solution was to basically add fillMaxHiehgt on the 8 cards themselves. What I was originally worried about would be that if I put this card on the screen by itself it would take up the parent height, but it does not. So it ended up working for me to just go that route.
👍 2
z
Did the
propagateMinConstraints
thing not work? From what you’ve described that sounds like the exact issue that parameter is for.
c
I didn't give it a try because my first step (even if I used propagateMinConstraints) seemed like it was going to be "well my composable only draws itself to be as tall as it requires, and so I went in and added fillMaxHeight on each of the 8 card types I have and then I also added a Spacer in each card (each card is a column) and the spacer has a weight of 1f and it just worked. For the sake of completion though, I will revert that change and just try your suggestion. Interested to see if that could work without the changes to my 8 cards themselves.
Oh hey. propagateMinConstraints did in fact work. what an awfully helpful argument that was available. I still had to add a spacer(weigh(1f)) to my cards so that the middle section of the card is what grew. But yeah. it works exactly as what I wanted. I guess at this point, I have two working solutions. 1. add fillMaxHeight to every card type and a spacer with weight of 1f 2. just add propagateMinConstraints = true, and every card needs a spacer of 1f so that it "grows" in the right spot Is there any other benefit between 1 and 2? I would have thought 1 would also break instances where the item is located alone (not in a carousel) but that didn't work. So yeah. just curious on your thoughts.
z
2 is a more accurate expression of your intent, and is more DRY since it doesn’t require repeating the annotation on every child
👍 1
c
i can dig it. what a fun arg that i dont think i would have ever stumbled upon myself. cheers