Open colintheshots opened 1 year ago
Sorry for getting back to this late. The reason here is that for Android when you refresh, it's going to come from the adapter so we can't access it in the common code. Do you have any suggestions on how to make this possible in common code?
I need to think this one over. I haven't had a chance to investigate what it might take yet.
@kuuuurt using PageSource.invalidate method might work.
That's a comment from PagingDataAdapter:
/** * Refresh the data presented by this [PagingDataAdapter]. * * [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 [LoadType] [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. * Invalidation due repository-layer signals, such as DB-updates, should instead use * [PagingSource.invalidate]. */ fun refresh()
A comment from Pager:
/** * A cold [Flow] of [PagingData], which emits new instances of [PagingData] once they become * invalidated by [PagingSource.invalidate] or calls to [AsyncPagingDataDiffer.refresh] or * [PagingDataAdapter.refresh]. */ @OptIn(androidx.paging.ExperimentalPagingApi::class) public val flow: Flow<PagingData<Value>>
Hi @colintheshots. I added a refresh function on 0.6.0. Haven't really tested but just added it based on your comment above and used PagingSource.invalidate()
Both Android and iOS have the capability to refresh the pages. However, it isn't clear from common code how to explicitly refresh the list. It would be great to have the ability to trigger a refresh from common code in the repository layer.