Jetpack Compose animate scroll LazyList

Viewed 1259

I'm using the latest version of Jetpack Compose - 1.1.0-beta04

I tried to scroll list with animateScrollToItem(0) for case when firstVisibleItemIndex == 0 the scrolling works good with spring animation. But if I scroll from the second item, my LazyList jumps without animations:

Compose LazyList Jump

Reproduced with simple example:

    val state = rememberLazyListState()

    val scope = rememberCoroutineScope()

    Box(modifier = Modifier.fillMaxSize()) {
        LazyColumn(
            state = state,
            reverseLayout = true
        ) {
            items(1000) {
                Card(
                    modifier = Modifier
                        .padding(horizontal = 12.dp)
                        .fillMaxWidth()
                        .padding(12.dp)
                ) {
                    Text(
                        text = "Message: $it",
                        fontSize = 20.sp,
                        modifier = Modifier.padding(12.dp)
                    )
                }
            }
        }

        Button(
            text = "Scroll",
            modifier = Modifier
                .align(Alignment.BottomEnd)
                .padding(16.dp)
        ) {
            scope.launch {
                state.animateScrollToItem(0)
            }
        }
    }
0 Answers
Related