Does ```collectAsLazyPagingItems()``` respect some...
# compose
f
Does
Copy code
collectAsLazyPagingItems()
respect something like
Copy code
flow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
or the data is updated even when the UI isn't in started mode?
a
yes, I believe that should be respected
for future reference, the usual recommended way to pause work in Compose between stop and start is to put the workload inside
withFrameNanos
in an Effect, but you can't do that here since the Effect lives in private code you can't modify. so using
flowWithLifecycle
seems right
f
Thanks Alexandre, my question was since the Provided function doesn't respect that, are we gonna get something in the future that does this or we have to build it for ourselves?
a
my understanding of how it works right now is:
pagingDataFlow.collectAsLazyPagingItems()
waits for create lifecycle event, but is unaffected by stop and start events. whereas
pagingDataFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED).collectAsLazyPagingItems()
is additionally paused between stop and start events.
I can imagine different developers preferring one or the other and the current way has flexibility to choose, so I'm not sure yet whether Compose-side API will provide anything additional in the future. it's an interesting question we might discuss further though, especially if we hear the question repeatedly
please file a bug if you have observed that in fact, ``pagingDataFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED).collectAsLazyPagingItems()`` does not work as desired for some reason. then we are more likely to make a change in Compose
f
Thanks Alexandre will try that tomorrow and file a bug if it doesn't work, i was just curious how this were for the future and whether i need to build this myself
Copy code
pagingData.flowWithLifecycle(LocalLifecycleOwner.current.lifecycle).collectAsLazyPagingItems()
it doesn't seem to display the data 😕
a
a
If that call recomposes it'll start anew since
flowWithLifecycle
will return a new flow instance, I think what you may want is this:
Copy code
val lifecycle = LocalLifecycleOwner.current.lifecycle
val lazyPagingItems = remember(pagingData, lifecycle) {
  pagingData.flowWithLifecycle(lifecycle)
}.collectAsLazyPagingItems()
the
remember
will make sure it doesn't reassemble a new flow chain on recomposition unless you truly have a different
pagingData
source or
lifecycle
for that recomposition
101 Views