Question: given a LazyColumn with many items, how can I collect the indexes of items that user has scrolled through without using a Composable (e.g. storing them to Database)? I tried the side effects:
Copy code
// Use the index as key to be notified when it is changed.
LaunchedEffect(key1 = listState.firstVisibleItemIndex) {
// Store the listState.firstVisibleItemIndex to DB
}
But it slows down the scroll performance significantly.
val listState = rememberLazyListState()
LaunchedEffect(listState) {
snapshotFlow { listState.firstVisibleItemIndex }.collect { index ->
// Save to DB
}
}
e
eneim
08/24/2021, 9:09 AM
Thanks a lot @Albert Chang, somehow I manage to do the same. Do you know any link to the document that mention the
snapshotFlow
? I want to make sure it is noted somewhere that I just happen to not read yet.