kmp-paging

Implements Paging 3 in Kotlin Multiplatform with PagingSource, Pager, and LazyPagingItems.

2|Updated Jun 6, 2026
One-click install
npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-paging-ronjunevaldoz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kmp-paging
Source: https://github.com/ronjunevaldoz/kmp-agent-skills/tree/main/skills/kmp-paging
Command: npx skills add https://github.com/ronjunevaldoz/kmp-agent-skills --skill kmp-paging-ronjunevaldoz

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Loading large lists page-by-page in a Kotlin Multiplatform app is error-prone: developers often misplace the Pager in the UI layer, put PagingData inside UiState, forget cachedIn, or mishandle load states, causing re-fetching, blank screens, and broken MVI state diffing. ## Core Features & Use Cases - Cursor and offset PagingSource templates: Complete implementations for token-based and page-number-based APIs, including getRefreshKey handling. - Correct layer placement: PagingSource in :data, Pager with .cachedIn(viewModelScope) in :presenter, and collectAsLazyPagingItems with refresh/append LoadState handling in :ui. - RemoteMediator for network + SQLDelight cache: Serves pages from the local database while refreshing from the network in the background. - Use Case: A shopping app needs an infinitely scrolling product list backed by a cursor-paginated API; the skill scaffolds the PagingSource, repository wiring, ViewModel Pager, Compose UI with retry states, and unit tests. ## Quick Start Ask the agent to add cursor-based Paging 3 infinite scroll to a KMP feature screen backed by your existing API and repository.

Frequently Asked Questions about kmp-paging

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement infinite scroll in Kotlin Multiplatform with Paging 3?▼

Create a PagingSource in the :data module, expose it via a repository pagingSource() factory, build a Pager with .cachedIn(viewModelScope) in the ViewModel, and collect it in Compose with collectAsLazyPagingItems. Handle LoadState.refresh and LoadState.append for loading and error UI.

Cursor-based vs offset-based pagination: which should I use?▼

Use cursor-based pagination when the API returns a next-page token, since offset requests can return duplicates or miss items when the server list changes between pages. Offset pagination with page numbers is acceptable only when the API provides no cursor.

Does AndroidX Paging 3 work on Kotlin Multiplatform non-Android targets?▼

Yes, androidx.paging:paging-common became multiplatform in version 3.3.x, so verify the version in libs.versions.toml before using it on non-Android targets. Note that paging-compose typically lags one version behind paging-common, so keep them in sync.

Why does my Pager re-fetch from page 1 on every recomposition?▼

This happens when .cachedIn(viewModelScope) is missing or the Pager is created inside a composable. Create the Pager once in the ViewModel and always chain .cachedIn(viewModelScope) so the paged flow survives recomposition and configuration changes.

Can I put PagingData inside a UiState data class?▼

No. PagingData is not a plain value and cannot be copied, compared, or serialized, so placing it in a data class State breaks MVI state diffing. Keep it as a separate Flow<PagingData<T>> property on the ViewModel alongside StateFlow<UiState>.

How do I test a PagingSource in Kotlin Multiplatform?▼

Call PagingSource.load() directly with LoadParams.Refresh inside runTest and assert the returned LoadResult. Cover the first page, the last page where nextKey is null, and the error case where the API throws and LoadResult.Error is returned.