Sher Sanginov
10/29/2023, 7:13 PMLazyColumn
has stickyHeader
and we call animateScrollToItem
to scroll to given item, the given item doesn't become the first visible item in the screen (See recording).
But without stickyHeader
, it works as expected and my item becomes firstVisibleItem
Is this expected or a bug?@Composable
fun ScrollToItem(paddingValues: PaddingValues) {
val listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()
val items = (0..20).map { "Item $it" }
Box(modifier = Modifier.padding(paddingValues)) {
LazyColumn(modifier = Modifier.fillMaxSize(), state = listState) {
stickyHeader {
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
Button(onClick = {
coroutineScope.launch {
listState.animateScrollToItem(11)
}
}) {
Text("Scroll to item 11")
}
}
}
items(items) {
Row(modifier = Modifier.fillMaxWidth().height(100.dp).background(Color.Yellow)) {
Text(text = "Lazy Column item ${it}")
}
}
}}
efemoney
10/29/2023, 7:24 PMstickyHeader
is an item just like every other item… the only difference is that its sticky 🙂Sher Sanginov
10/29/2023, 7:26 PMefemoney
10/29/2023, 7:48 PManimateScrollToItem(12)
instead of 11Sher Sanginov
10/29/2023, 7:57 PManimateScrollToItem(12, -100)
make sure my item is fully visible; otherwise stickyHeader hides top of it