I'm trying to make a complex `Layout` with custom ...
# compose
d
I'm trying to make a complex
Layout
with custom measurement and placement. I want to animate elements inside it, specifically when a parameter change I want one item to move and scale. I first approached this like this:
Copy code
val dynamicSize = animateFloatAsState(
        targetValue = if (condition) .3f else 1f
    )
    Layout(
        content = {
           Box(
               modifier = Modifier
                   .fillMaxSize(dynamicSize.value)
           )
           // ...
and than I kept the size to full inside my measurement... But now I actually need to decide the scaling in my layout measure logic. Should I remove the
fillMaxSize()
, have an
animateFloatAsState()
outside the
Layout
and use the
0f
-->
1f
inside the measure block to control the size with the constraints? Is this an efficient way of handling animations with
Layout
? I'm worried that i can become very complex in this layout to work with all the possibles options for animations. I'm open to suggestions / code examples / anything that can show me how people handle this kind of things. Thanks.
I did reimplement it with a the animateFloatAsState doing the computation in the measurements, with lerp. But it isn't fluid at all.
d
Can you share the resulting video of your experiment? Sounds like you are trying to scale the content. Without knowing more of the requirements, I'd suggest applying scale using a graphicsLayer instead of
fillMaxSize(friction)
, unless you intend to have the scaled content influence the placement/size of the other content.
d
I'm sorry I had missed your comment @Doris Liu I can't / don't want to use graphic layer. Those boxes I'm moving around are video call tiles using a surface under the hood. So the scaling needs to be done via view size. I'm working towards a deadline now but I'll try to make a video next week about it.