Hello there, i’m experiencing disappearing `sticky...
# compose
r
Hello there, i’m experiencing disappearing
stickyHeader
😞 in
LazyColumn
when I use
Paging
is it a bug or am I doing something wrong? Code in 🧵
Copy code
@Composable
fun EventHistoryList(pagingItems: LazyPagingItems<EventHistoryAdapter.Data>) {
    
        LazyColumn(
            modifier = Modifier.fillMaxSize(),
        ) {
            for (index in 0 until pagingItems.itemCount) {
                when (val item = pagingItems.peek(index)) {
                    is EventHistoryAdapter.Data.Header -> stickyHeader {
                        val header = (pagingItems.getAsState(index = index).value as EventHistoryAdapter.Data.Header)
                        EventHistoryHeader(label = header.title)
                    }
                    is EventHistoryAdapter.Data.Item -> item {
                        val data = (pagingItems.getAsState(index = index).value as EventHistoryAdapter.Data.Item)
                       EventHistoryItem(data)
                    }
                }
            }
}
m
why is peek needed here? You will access it anyway. Why not extract to a variable before the when ?
ok. So that’s because
items
block is lazy. If you do as i suggested, it would lose the ‘paging’ ability and load all pages. Do not do this!!
you cant get the item outside
items
also. It would trigger all the page loads!