Hi! We are working on a project where we have a R...
# compose
t
Hi! We are working on a project where we have a Row that has 2 Cards. Each card has by default the same width (weight = 1f for both), but in certain state changes we must animate the it so that it becomes a 1f to 3f distribution. The problem being is that when you animate your weight it is very laggy (in debug mode). Probably because each time it updates the weight (which is on average 50 times in the duration of the animation) it must recalculate its sizes, draw it again, etc... Does anyone know of a way to animate the weight of a Composable without it recomposing that much? Side note: we use Animatable (not animateFloatAsState) since we have an unknown amount of "Cards" so have created a list of data objects that each has their animatable
Copy code
Row(
    modifier = Modifier.fillMaxSize()
) {
    cards.forEach { card ->
        Card(
            modifier = Modifier.weight(card.animationWeight.value) // 1f by default, could become 3f if in an "expanded" state
         ) {
              // Other content
         }
     }
}
d
Could you file a feature request for this please?
t
This isn't a feature request, it is more of a question on how to handle it, since it is possible but just laggy right now
z
You can write a custom layout that does gets recomposition out of the animation.
d
What I was getting at is that there's no easy way to achieve it right now. In addition to custom layout that Zach suggested, you could also try
animateBounds
modifier. It's something that we are currently building, here's a simplified version of it: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mpose/animation/demos/lookahead/AnimateBoundsModifier.kt;l=46 You could do
Modifier.animateBounds(Modifier.weight(if... 1f else 3f))
t
Ow okay, I will look into that, thank you