https://kotlinlang.org logo
#compose
Title
# compose
m

myanmarking

04/02/2022, 6:53 PM
How to show an emptyView with no items in compose paging. It seems impossible. We have to skip the condition for initial load (which the itemCount == 0). Also we cannot rely on endOfPaginationReached because the page can load from any position. Why is this api so hard ?
f

FunkyMuse

04/03/2022, 12:17 PM
Just write your own paging, it's one list, one lambda function and one page variable, paging library is a nightmare to manage, even paging3 has some quirks you need to work around them, like multiple if clauses if pagination is impossible anymore because you reached the end, checking if initial load didn't return content etc... Manually you'd have only one boolean value isLoading and less frustrations
m

myanmarking

04/03/2022, 12:36 PM
Indeed. All that extra boilerplate no1 asked. The combinedLoadState mess with 500k diferent states. So anoyibg
i

Ian Lake

04/03/2022, 2:23 PM
Is your problem just with the initial load? There's an open bug on that where it defaults to NotLoading vs what it should be starting at (Loading)
The details of combinedLoadState are way more useful when you are looking at adding a loading spinner as the first or last item of your endless list: loading each new set of data isn't instantaneous
m

myanmarking

04/03/2022, 3:28 PM
Ya i get that. But the basic thing, showing an empty view if no items are present is kinda hard to achieve.
a

Andrey Kulikov

04/04/2022, 5:39 PM
Hey. Have you tried writing something like this?
Copy code
if (lazyPagingItems.itemCount == 0) {
    EmptyUI()
} else {
    LazyColumn(…)
}
i

Ian Lake

04/04/2022, 5:55 PM
yep, or if you want to take loading into consideration:
Copy code
val loadState = lazyPagingItems.loadState
val finishedLoading =
  loadState.refresh !is LoadState.Loading &&
  loadState.prepend !is LoadState.Loading &&
  loadState.append  !is LoadState.Loading
if (lazyPagingItems.itemCount == 0 && finishedLoading) {
  EmptyUI()
} else {
  LazyColumn(...)
}
m

myanmarking

04/04/2022, 5:56 PM
first one doesnt work. Paging always start with itemCount == 0, i dont want to show the emptyView for a split second
second also doesn’t work - for room only paging (without removeMediator), there is no Loading. always notLoading
i

Ian Lake

04/04/2022, 6:01 PM
like I said, there's a bug where Paging starts at
NotLoading
, when it really should be
Loading
until the first set of data comes back: https://issuetracker.google.com/224855902
but you'll get
Loading
every time you scroll down enough to load more data - specifically
loadState.append
will change. Of course, if your data loads faster than it takes to do a single composition...
a

Ahmed Shehata

04/20/2022, 7:24 AM
I have the same problem too, Did you find any solution for this?
723 Views