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

YASAN

03/25/2022, 9:18 PM
I am trying to add pagination to my
LazyColumn
using Paging3 (with its compose library). I now show the paginated list by converting the
PagingData
into a
LazyPagigItems
object. My issue is that I cannot find a way to show any state other than the success state like showing the loading indicator or showing an error when the loading of a page fails. I have done this outside Compose using RecyclerViews but I cant find anything useful for it in Compose.
Am I missing something?
m

myanmarking

03/26/2022, 1:07 AM
What do you mean you cannot find a way. Have you tried observing the states,?
p

Patrick Kellison

03/26/2022, 2:58 PM
Your composable's lazy paging state object has a
loadState
with properties like
append, prepend,
refresh
that can be observed to be in Loading, Error, Refreshing, etc. Not sure on the syntax, replying here on mobile, but that's the gist of it
y

YASAN

03/26/2022, 4:10 PM
@Patrick Kellison @myanmarking Like this? 🤔
Copy code
val prependLoading = trendingGifs.loadState.prepend == LoadState.Loading
    val appendLoading = trendingGifs.loadState.append == LoadState.Loading
So if these == loading it means data is being loaded on that side? I have to just handle how to properly show it in the composables?
But what about error states
m

myanmarking

03/26/2022, 4:30 PM
Not like that. Something like: if(loadstate is LoadState.Loading) ... else ...
y

YASAN

03/26/2022, 4:31 PM
Oh right
That also fixes the issue for the error thing
🤔 thanks im going to look into it now
11 Views