Hopefully something simple that I'm missing. I'm t...
# compose
l
Hopefully something simple that I'm missing. I'm trying to change the display when a collection of paged items is empty. While this works when the UI is initially composed with no items, once items appear and disappear, the display remains empty.
Copy code
val lazyItems = posts.collectAsLazyPagingItems()

    if(lazyItems.itemCount == 0) {
        NoItemsLeft()
    } else {
        LazyColumn(modifier = modifier) {
            items(lazyItems) {
I'm an idiot, needed to move the condition inside the
LazyColumn
instead.
j
There's also a couple of other properties you can check. I wanted to display a "No items at all" composable if the data source was empty and there were no more pages, and ended up with this condition:
Copy code
lazyItems.loadState.refresh is LoadState.NotLoading && lazyItems.loadState.refresh.endOfPaginationReached && lazyItems.itemCount == 0
I would have thought that this was a common use case that would have have some kind of API, but I couldn't find it.
l
Thanks, that seems more robust - I was already handling the various
LoadState
but didn't think to use
NotLoading
!