kuuuurt / multiplatform-paging

Kotlin Multiplatform library for Pagination
Apache License 2.0
251 stars 22 forks source link

Pager tries to mutate a frozen list on iOS #18

Closed rickclephas closed 3 years ago

rickclephas commented 3 years ago

During my investigation of https://github.com/rickclephas/KMP-NativeCoroutines/issues/10 I noticed the Pager is updating the PagingData which fails when the pager is frozen.

Since there is already a StateFlow I think this could be easily fixed with something like the following:

clientScope.launch {
    val newPagingResult = getItems(key, config.pageSize)

    hasNextPage = newPagingResult.items.size >= config.pageSize
    _pagingData.value = PagingData<V>().apply { 
        addAll(_pagingData.value)
        addAll(newPagingResult.items)
    }

    currentPagingResult = newPagingResult
}
kuuuurt commented 3 years ago

Thanks for the report! I have to admit, I haven't been able to check iOS that much. Let me try this out as soon as I free up or since you have a solution already, PRs are also welcome!

rickclephas commented 3 years ago

Just tried to apply the changes I proposed but it isn't as easy as I thought. currentPagingResult and hasNextPage can't be updated either if the Pager is frozen.

kuuuurt commented 3 years ago

@rickclephas should be out on v0.4.4