Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #33 from ilmooo/fix/jvm-always-create-new-source
Browse files Browse the repository at this point in the history
Always create new PagingSource on Android.
  • Loading branch information
kuuuurt committed Jan 31, 2023
2 parents 0983fbf + 0ab06cb commit 7e3c1f6
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ actual class Pager<K : Any, V : Any> actual constructor(
initialKey: K,
getItems: suspend (K, Int) -> PagingResult<K, V>
) {
private val source = PagingSource(
initialKey,
getItems
)
private var source: PagingSource<K, V>? = null

actual val pagingData: Flow<PagingData<V>> = AndroidXPager(
config = config,
pagingSourceFactory = { source }
pagingSourceFactory = {
PagingSource(
initialKey,
getItems
).also { source = it }
}
).flow

class PagingSource<K : Any, V : Any>(
Expand Down Expand Up @@ -69,6 +72,6 @@ actual class Pager<K : Any, V : Any> actual constructor(
}

actual fun refresh() {
source.invalidate()
source?.invalidate()
}
}

0 comments on commit 7e3c1f6

Please sign in to comment.