Jetpack Compose:如果动画滚动中断并开始新的滚动,则 LazyColumn 不会渲染某些项目 [英] Jetpack Compose: LazyColumn does not render some items if animated scroll is interrupted and a new one is started
问题描述
我目前正在试用 Android Jetpack Compose,并希望使用 LazyColumn
实现一个类似 RecyclerView
的列表.但是,当在用户滚动期间或在另一个编程滚动(动画)期间以编程方式滚动(动画)到某个项目时,不会呈现列表中的某些项目.这是 Compose 的问题还是我错误地实现了滚动?
I'm currently trying out Android Jetpack Compose and want to implement a RecyclerView
-like list using LazyColumn
. However, when programatically scrolling (animated) to a certain item during a scroll by the user or during another programatic scroll (animated), some items in the list are not rendered. Is this a issue of Compose or did I implement the scrolling incorrectly?
作为一个简单的例子,可以使用以下代码:
As a simple example, the following code can be used:
class MainActivity : ComponentActivity() {
@ExperimentalTime
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val listState = rememberLazyListState()
rememberCoroutineScope().launch {
delay(10.seconds)
listState.animateScrollToItem(1000)
delay(100.milliseconds)
listState.animateScrollToItem(0)
}
LazyColumn(
state = listState,
contentPadding = PaddingValues(1.dp),
) {
items(1000) {
Text(
text = "$it",
modifier = Modifier
.padding(2.dp)
.clip(MaterialTheme.shapes.small)
.background(MaterialTheme.colors.onSurface)
.padding(8.dp)
.fillMaxWidth(),
color = MaterialTheme.colors.surface,
textAlign = TextAlign.Center,
)
}
}
}
}
}
我还录制了该应用的示例视频:https://i.imgur.com/dKFn1VH.mp4.
I also recorded a sample video of the app: https://i.imgur.com/dKFn1VH.mp4.
推荐答案
这是一个错误:
https://issuetracker.google.com/issues/188566058
它在 1.0.0-beta08
中得到修复和预期.
It is fixed and expected in 1.0.0-beta08
.
这篇关于Jetpack Compose:如果动画滚动中断并开始新的滚动,则 LazyColumn 不会渲染某些项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!