Annon
Annon

Reputation: 843

Manually refresh paging data in jetpack compose

I'm using paging-compose library to load paginated data from server using remote mediator (backed by local room database). Is there any way to manually refresh mediator data in case of swipe to refresh?

Upvotes: 4

Views: 8189

Answers (1)

Om Kumar
Om Kumar

Reputation: 1664

Calling refresh() method on LazyPagingItems should work for swipe to refresh (UI driven event) as mention in documentation LazyPagingItems.refresh()

Refresh the data presented by this LazyPagingItems.

refresh triggers the creation of a new PagingData with a new instance of PagingSource to represent an updated snapshot of the backing dataset. If a RemoteMediator is set, calling refresh will also trigger a call to RemoteMediator.load with REFRESH to allow RemoteMediator to check for updates to the dataset backing PagingSource.

Note: This API is intended for UI-driven refresh signals, such as swipe-to-refresh

Upvotes: 9

Related Questions