paging

Guidance for implementing paged lists with Paging 3 in Android or Compose. Describes configuring PagingSource, Pager and PagingConfig; using RemoteMediator for offline-first lists; integrating LazyPagingItems in LazyColumn and setting itemKey; implementing dynamic filtering via flatMapLatest; and writing unit tests with TestPager and asSnapshot. Trigger keywords include Paging 3, infinite list, infinite scroll, paged list, LazyPagingItems, collectAsLazyPagingItems, and cachedIn.

Last repository push
GitHub Stars
183
Forks
22
Issues / PRs
0

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "paging" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-ec99ceb15429708ad2b687edf0af407f743824cc30acdb088eb9153c9db9266d. Verify the upstream source and version against https://github.com/rcosteira79/android-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Guidance for implementing paged lists with Paging 3 in Android or Compose. Describes configuring PagingSource, Pager and PagingConfig; using RemoteMediator for offline-first lists; integrating LazyPagingItems in LazyColumn and setting itemKey; implementing dynamic filtering via flatMapLatest; and writing unit tests with TestPager and asSnapshot. Trigger keywords include Paging 3, infinite list, infinite scroll, paged list, LazyPagingItems, collectAsLazyPagingItems, and cachedIn.

0 Downloads

Introduction source: third_party · rcosteira79 · 0.0.1 Reference

SkillPi interpretation

Tasks
Use when implementing paginated lists in Android or Compose with Paging 3 — PagingSource, Pager and PagingConfig setup, RemoteMediator for offline-first lists, LazyPagingItems and itemKey integration in LazyColumn, dynamic filters via flatMapLatest, and unit tests with TestPager and asSnapshot. Triggers include Paging 3, infinite list, infinite scroll, paginated list, LazyPagingItems, collectAsLazyPagingItems, and cachedIn.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: paging
description: Use when implementing paginated lists in Android or Compose with Paging 3 — PagingSource, Pager and PagingConfig setup, RemoteMediator for offline-first lists, LazyPagingItems and itemKey integration in LazyColumn, dynamic filters via flatMapLatest, and unit tests with TestPager and asSnapshot. Triggers include Paging 3, infinite list, infinite scroll, paginated list, LazyPagingItems, collectAsLazyPagingItems, and cachedIn.

Paging 3 for Android and Compose

Adapted from Meet-Miyani/compose-skill's Paging references. MIT licensed. Related: android-skills:android-data-layer (non-paged repository), android-skills:android-retrofit / android-skills:kmp-ktor (network feeding PagingSource), android-skills:compose (LazyColumn).

This reference covers the current-version fact, the placement and identity rules that are easy to get wrong, and the RemoteMediator offline-first timing — not the basics of PagingSource / Pager / collectAsLazyPagingItems.

Version (current fact)

As of androidx.paging 3.5.0, paging-common, paging-compose, and paging-testing are Kotlin Multiplatform (Android, JVM, iOS, Native, JS/Wasm); only paging-runtime (and -guava/-rxjava) stay Android-only. So in a clean-architecture domain module, depend only on androidx.paging:paging-common — it ships PagingSource / PagingData / LoadResult with no Android dependency, so PagingSource interfaces and use cases can live in domain. (Verify the current version and KMP support at the releases page.)

Dual-flow rule — PagingData is its own Flow, never a field in UiState

Expose uiState: StateFlow<UiState> AND pagingItems: Flow<PagingData<T>> as separate properties.

val uiState: StateFlow<UiState> = _uiState.asStateFlow()
val pagingItems: Flow<PagingData<RepoUi>> =
    Pager(PagingConfig(pageSize = 20, prefetchDistance = 5, enablePlaceholders = false)) { repo.repoPagingSource() }
        .flow
        .map { data -> data.map { it.toUi() } }   // transforms BEFORE cachedIn
        .cachedIn(viewModelScope)

If PagingData rides inside UiState, every non-paging state change (selection, filter chip, snackbar) re-emits UiState and hands collectAsLazyPagingItems() a brand-new Flow<PagingData> — it drops its cache, restarts loads, and resets scroll to top.

cachedIn placement

cachedIn(viewModelScope) sits at the bottom of the chain: after any flatMapLatest (filters/search), and after every map / filter / insertSeparators. Anything chained after cachedIn re-runs in each collector's scope (re-transforming cached data, desyncing separators); a cachedIn placed inside a flatMapLatest lambda leaks a fresh cache on every filter change.

val pagingItems = combine(_query.debounce(300).distinctUntilChanged(), _status.distinctUntilChanged(), ::Pair)
    .flatMapLatest { (q, s) -> Pager(PagingConfig(20)) { repo.repoPagingSource(q, s) }.flow.map { it.map(RepoDto::toUi) } }
    .cachedIn(viewModelScope)

itemKey is mandatory in LazyColumn

items(
    count = pagingItems.itemCount,
    key = pagingItems.itemKey { it.id },              // stable domain id
    contentType = pagingItems.itemContentType { "repo" },
) { idx -> pagingItems[idx]?.let { RepoRow(it) } }

Without itemKey, LazyColumn reuses slots by index — a prepended page shifts every existing item's identity, so row state / rememberSaveable / animations target the wrong slot and scroll visibly jumps. (pagingItems[i] reads and triggers a load near the edge; peek(i) reads without loading. Call retry() / refresh() from event handlers or a LaunchedEffect, never a composable body.)

RemoteMediator (offline-first)

With offline-first paging the Room DAO is the PagingSource and a RemoteMediator drives network refresh + DB writes. Wrap those writes in db.withTransaction { }, and clear local state on LoadType.REFRESH. Gate the full-screen loader on loadState.source.refresh + itemCount == 0 — not the combined loadState.refresh, which flips to NotLoading before Room finishes writing and drops the spinner a frame early.

Testing — TestPager / asSnapshot, never .first()

A paging flow is hot and never completes, so .first() / .toList() on it hangs. Use paging-testing:

@Test fun `source returns first page`() = runTest {
    val pager = TestPager(PagingConfig(10), RepoPagingSource(FakeGitHubService(repo1, repo2), "kotlin"))
    val page = pager.refresh() as PagingSource.LoadResult.Page
    assertEquals(2, page.data.size); assertNull(page.prevKey); assertEquals(2, page.nextKey)
}

@Test fun `viewmodel paging flow exposes first pages`() = runTest {
    val items = RepoListViewModel(FakeRepoRepository()).pagingItems.asSnapshot { scrollTo(index = 30) }
    assertTrue(items.size >= 30)
}

Version history

  1. v5.2.0 GitHub ↗
    Original release notes

    First tagged release of the **5.x** line — capturing everything merged since `v3.0.0` (89 commits, 12 PRs). The through-line: repeated roster audits that grew the collection to 21 skills and then trimmed each one to the content that actually earns its place against a strong base model. ## Highlights ### New skills - **`pdf-annotations`** — platform PDF annotation & page-object editing (API 36.1 / SDK-extension-18 surface) (#29) - **`koin`**, **`kmp-boundaries`**, **`modularization`**, **`datastore`**, **`paging`** — added across the roster audits (#4, #6) - **`android-testing`** — renamed and reorganised from `android-tdd`, with the compose reference reorg (#10) ### Roster audits & quality passes - **Sonnet 4.6 baseline audit** — trimmed every skill to its earned core; fixed stale claims across the roster (#13) - **Roster audit v1 / v2** — new skills plus multi-source depth passes across references (#4 → 4.1.0, #6 → 5.0.0) - **JetBrains skills audit** — README link + AGP 9 additions across three skills (#7 → 4.2.0) - **Verified micro-lifts** — debug-log hygiene, perf baseline, pass-through red flag (#12) ### Integrations & maintenance - Integrated findings from **skydoves/android-testing-skills**, with a documented cherry-pick subset (#5, #9) - **Upstream drift watcher** for credited skill repos (#8) - Re-baselined the upstream-audit ledger (#11) - Lint hygiene: stale frontmatter/link fixes (#30) ### This release - Restructured **README** with a centered badge header; the version badge tracks the plugin manifest via a dynamic JSON badge, so it never drifts - Trimmed `pdf-annotations` provenance asides while keeping every API contract and the version gate --- ## What's Changed * Roster audit: 2 new skills, 4 contradiction fixes, depth pass across 8 references (4.1.0) by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/4 * JetBrains skills audit: README link + AGP 9 additions across 3 skills (4.2.0) by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/7 * Integrate findings from skydoves/android-testing-skills by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/5 * Add upstream drift watcher for credited skill repos by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/8 * Document skydoves cherry-pick subset and breadcrumb it to android-tdd by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/9 * Roster audit v2: 3 new skills + multi-source depth pass across 13 files (5.0.0) by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/6 * Rename android-tdd → android-testing + compose reference reorg by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/10 * chore: re-baseline upstream-audit-ledger (2026-06-01) by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/11 * Verified micro-lifts: debug-log hygiene, perf baseline, pass-through red flag by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/12 * Audit the android-skills roster against the Sonnet 4.6 baseline — trim to the earned core by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/13 * Add pdf-annotations skill: platform PDF annotation & page-object editing by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/29 * Fix stale skill frontmatter/link (lint hygiene) by @rcosteira79 in https://github.com/rcosteira79/android-skills/pull/30 **Full Changelog**: https://github.com/rcosteira79/android-skills/compare/v3.0.0...v5.2.0

  2. v3.0.0 GitHub ↗
    Original release notes

    ## Highlights The 3.0.0 cycle adds a new networking skill for KMP, sharper guidance across existing skills via paired RIGHT/WRONG examples, and integration with Google's `android` CLI for runtime UI inspection and authoritative documentation lookup. ## New skill - **`kmp-ktor`** — Ktor client setup for Kotlin Multiplatform and Android: per-platform engine selection (OkHttp/Darwin/CIO), `kotlinx.serialization` with the `encodeDefaults` guard, bearer token auth with refresh via the `Auth` plugin and `markAsRefreshTokenRequest()`, `MockEngine` testing, and `DataError` mapping at the repository boundary. ## Skill improvements - RIGHT vs WRONG sections added to four skills: `kotlin-flows`, `android-retrofit`, `coil-compose`, `android-data-layer` - `compose` skill: Authoritative Docs section using `android docs search` - `android-debugging` skill: Runtime UI Inspection via `android layout` - `compose/references/performance.md`: `android layout --diff` as a CLI alternative to Android Studio's Layout Inspector ## Tooling and documentation - Google's `android` CLI documented as a recommended companion tool - `android-source-explorer-mcp` promoted from optional to recommended - README restructured: agent install steps first, companion tools last - Related Projects expanded with `compose-skill` (Meet-Miyani), `compose_skill` (hamen), and `android-reverse-engineering-skill` ## Inspiration credits The `kmp-ktor` skill draws on the Ktor reference structure from [Meet-Miyani/compose-skill](https://github.com/Meet-Miyani/compose-skill).

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value88/100

Highlights

  • 提供 Paging 3 高级实现细节与最佳实践
  • 覆盖离线优先、动态过滤、单元测试等关键场景
  • 解决常见陷阱如缓存丢失和 itemKey 缺失
Trigger Precision92/100

Highlights

  • 触发词覆盖全面且边界清晰
  • 包含核心 API 名称和使用场景关键词
Structure and Standards90/100

Highlights

  • 结构清晰,从版本事实到测试完整闭环
  • 代码示例丰富且位置恰当
  • frontmatter 完整规范
Execution Reliability88/100

Highlights

  • 依赖库版本信息准确
  • 异常处理建议合理(如 TestPager 替代 .first())
  • 关键操作有明确警告说明
Evidence Verifiability (mean of the first four)90/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • developer.android.com
  • github.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.