Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 894b50adaa0b390d339c0935714d71de59d8c51d
Author: Oscar Adame Vázquez <oscarad@google.com>
Date: Mon Jan 29 14:33:36 2024
Fix AnimateContentSize not resetting properly
When the node for AnimateContentSize would get re-used on a LazyList,
stale animation information would ocassionally trigger undesired
animation as soon as the new items (with re-used nodes) got placed on
the List
Bug: 322525716
Test: LazyListTest#animContentSize_resetOnReuse
Change-Id: I070512423d2c358326c50fae32ed0696d6fe9193
M compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt
https://android-review.googlesource.com/2933952
Branch: androidx-main
commit 894b50adaa0b390d339c0935714d71de59d8c51d
Author: Oscar Adame Vázquez <oscarad@google.com>
Date: Mon Jan 29 14:33:36 2024
Fix AnimateContentSize not resetting properly
When the node for AnimateContentSize would get re-used on a LazyList,
stale animation information would ocassionally trigger undesired
animation as soon as the new items (with re-used nodes) got placed on
the List
Bug: 322525716
Test: LazyListTest#animContentSize_resetOnReuse
Change-Id: I070512423d2c358326c50fae32ed0696d6fe9193
M compose/animation/animation/src/commonMain/kotlin/androidx/compose/animation/AnimationModifier.kt
M compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/lazy/list/LazyListTest.kt
Description
Run the snippet below, click on a couple of items and scroll
Observed behavior: When items (that reused the LayoutNode and concequently the modifier node for animateContentSize) are brought into the viewport for the first time, they animate to their initial size.
Expected bahvior: No animation for initial size
```
@Preview
@Composable
fun LazyColumnWithAnimatedContentSize() {
LazyColumn {
repeat(30) {
item { MyText() }
}
}
}
@Composable
private fun MyText() {
val shortText = "Click me"
val longText = "Very long text\nthat spans across\nmultiple lines"
var short by remember { mutableStateOf(true) }
Box(
modifier = Modifier
.background(
Color.Blue,
RoundedCornerShape(15.dp)
)
.clickable { short = !short }
.padding(20.dp)
.wrapContentSize()
.animateContentSize { startSize, endSize -> println("$startSize -> $endSize") }
) {
Text(
if (short) {
shortText
} else {
longText
},
style = LocalTextStyle.current.copy(color = Color.White)
)
}
}
```