Thread
#compose
    Chris Johnson

    Chris Johnson

    1 year ago
    :android-wave: Is there a way to measure a child before placing it and then fill the screen with the available amount of those children? Currently I'm creating a
    Layout
    for measurement of the child and then another
    Layout
    that will place X amount of those children based on screen height. The problem I ran into was each child I'm placing needs to be unique/not being currently laid out for the system to not give me
    "Place was called on a node which was placed already"
    .
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    I think
    SubcomposeLayout
    might be your best bet here. You basically described how the lazy lists work.
    You can use it to subcompose+measure the first child, then subcompose+etc as many other children as you need.
    Chris Johnson

    Chris Johnson

    1 year ago
    I thought about a
    SubcomposeLayout
    . Was sure that I would run into the same issue of not being able to place the same placeable. But now that I'm looking at it more calling
    subcompose
    would allow me to create a new placeable to place which should solve that. I'll try that next! Zach to the rescue again. 🦸
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    yep exactly, you can just call
    subcompose
    multiple times with the same content function
    Chris Johnson

    Chris Johnson

    1 year ago
    Sweet. That composable is so powerful
    Now for the harder question of... which is better for performance? Having a
    Layout
    that gets the measure and is then removed from composition via a
    mutableStateOf(Boolean)
    + a
    Layout
    to place. Or using
    Subcomposelayout
    Time to get out the profiler... 😱
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    Before even considering performance, those will do different things. The former will not show the content until the second frame, which will most likely look noticeably bad.
    Chris Johnson

    Chris Johnson

    1 year ago
    You don't really notice it, but yes you're right it would have to go through re-composition to show. Subcomposelayout seems to do the trick beautifully 🙂
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    There can be other negative effects of skipping that first frame (e.g. it breaks the IDE preview)