Hey, is there a way to animate between row/column ...
# compose
t
Hey, is there a way to animate between row/column with the items moving, instead of disappearing/appearing?
For example, i have a screen, like this:
Copy code
@Composable
fun Test() {
    var isColumn by remember { mutableStateOf(false) }
    Column() {
        Button({ isColumn = !isColumn }) {
            Text("switch")
        }
        AnimatedContent(
            targetState = isColumn,
            label = "label",
        ) {
            if (it) {
                Column(
                    verticalArrangement = Arrangement.SpaceEvenly,
                    horizontalAlignment = Alignment.CenterHorizontally,
                    modifier = Modifier.fillMaxSize()
                ) {
                    Box(Modifier
                        .size(40.dp)
                        .clip(CircleShape)
                        .background(Color.Red)
                    )
                    Box(Modifier
                        .size(40.dp)
                        .clip(CircleShape)
                        .background(Color.Green)
                    )
                    Box(Modifier
                        .size(40.dp)
                        .clip(CircleShape)
                        .background(Color.Blue)
                    )
                }
            } else {
                Row(
                    horizontalArrangement = Arrangement.SpaceEvenly,
                    modifier = Modifier.fillMaxSize()
                ) {
                    Box(Modifier
                        .size(40.dp)
                        .clip(CircleShape)
                        .background(Color.Red)
                    )
                    Box(Modifier
                        .size(40.dp)
                        .clip(CircleShape)
                        .background(Color.Green)
                    )
                    Box(Modifier
                        .size(40.dp)
                        .clip(CircleShape)
                        .background(Color.Blue)
                    )
                }
            }
        }
    }
}
Since, the items all stay the same, I want them to move from their origin positions in the Row to their destination positions in the Column, vice versa.
a
See
movableContentOf
. I remember seeing official docs on this but I'm unable to find it now.
t
How do I animate using this though? As far as I can see, this is primarily about preserving the internal state of a composition.
b
Take a look at LookAheadLayout. Here is a sample that animates items between a row and a column
thank you color 1
a
thank you color 1