Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
824 views
in Technique[技术] by (71.8m points)

android - Jetpack Compose: LazyColumn does not render some items if animated scroll is interrupted and a new one is started

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,
                    )
                }
            }
        }
    }
}

I also recorded a sample video of the app: https://i.imgur.com/dKFn1VH.mp4.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is a bug:

https://issuetracker.google.com/issues/188566058

It is fixed and expected in 1.0.0-beta08.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...