appmattus
10/21/2021, 6:48 PMText
) in the list the animation becomes jerky. In comparison, having only the button in the list the animation is relatively smooth. (Videos attached)
(Code and videos in thread)appmattus
10/21/2021, 6:50 PM@Composable
fun MotionLayoutScreen() {
val animateToEnd = remember {
mutableStateOf(false)
}
val startSet = ConstraintSet {
val header = createRefFor("header")
val list = createRefFor("list")
constrain(header) {
start.linkTo(parent.start)
end.linkTo(parent.end)
top.linkTo(<http://parent.top|parent.top>)
bottom.linkTo(<http://list.top|list.top>)
height = Dimension.value(300.dp)
width = Dimension.fillToConstraints
}
constrain(list) {
start.linkTo(parent.start)
end.linkTo(parent.end)
top.linkTo(header.bottom)
bottom.linkTo(parent.bottom)
height = Dimension.fillToConstraints
width = Dimension.fillToConstraints
}
}
val endSet = ConstraintSet {
val header = createRefFor("header")
val list = createRefFor("list")
constrain(header) {
start.linkTo(parent.start)
end.linkTo(parent.end)
top.linkTo(<http://parent.top|parent.top>)
bottom.linkTo(<http://list.top|list.top>)
height = Dimension.value(40.dp)
width = Dimension.fillToConstraints
}
constrain(list) {
start.linkTo(parent.start)
end.linkTo(parent.end)
top.linkTo(header.bottom)
bottom.linkTo(parent.bottom)
height = Dimension.fillToConstraints
width = Dimension.fillToConstraints
}
}
val progress = animateFloatAsState(
targetValue = if (animateToEnd.value) 1f else 0f,
animationSpec = tween(2500)
)
MotionLayout(
start = startSet, end = endSet, progress = progress.value,
modifier = Modifier.fillMaxSize()
) {
Box(
modifier = Modifier
.background(Color.Gray)
.layoutId("header")
)
LazyColumn(modifier = Modifier.layoutId("list")) {
item {
Button(
onClick = { animateToEnd.value = animateToEnd.value.not() },
) {
Text("Animate")
}
}
items((1..30).toList()) {
Text(it.toString())
}
}
}
}
appmattus
10/21/2021, 6:50 PMappmattus
10/21/2021, 6:50 PMappmattus
10/21/2021, 10:03 PMitems(items = (1..30).toList(), key = { it }) {
Text(it.toString())
}