{"id":13407094,"url":"https://github.com/kuuuurt/multiplatform-paging","last_synced_at":"2025-03-14T11:31:04.427Z","repository":{"id":40455582,"uuid":"245383196","full_name":"kuuuurt/multiplatform-paging","owner":"kuuuurt","description":"Kotlin Multiplatform library for Pagination","archived":true,"fork":false,"pushed_at":"2023-10-13T04:51:16.000Z","size":938,"stargazers_count":251,"open_issues_count":13,"forks_count":22,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-07-31T20:26:44.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kuuuurt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-03-06T09:48:56.000Z","updated_at":"2024-07-24T08:38:34.000Z","dependencies_parsed_at":"2024-01-16T15:40:49.509Z","dependency_job_id":"df144150-d004-469d-a308-d6aafb0c400d","html_url":"https://github.com/kuuuurt/multiplatform-paging","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuuuurt%2Fmultiplatform-paging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuuuurt%2Fmultiplatform-paging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuuuurt%2Fmultiplatform-paging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuuuurt%2Fmultiplatform-paging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuuuurt","download_url":"https://codeload.github.com/kuuuurt/multiplatform-paging/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243569324,"owners_count":20312402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:00:19.664Z","updated_at":"2025-03-14T11:31:02.800Z","avatar_url":"https://github.com/kuuuurt.png","language":"Kotlin","readme":"# Multiplatform Paging\n\n[ ![Download](https://maven-badges.herokuapp.com/maven-central/io.github.kuuuurt/multiplatform-paging/badge.svg) ](https://search.maven.org/search?q=a:multiplatform-paging)\n\nA Kotlin Multiplatform library for pagination.\n\n## :warning: **Important Notice**\n\nThis repository is no longer actively maintained.\n\nIf you're looking for more features or alternative solutions, check out [Cash App's Multiplatform Paging library](https://github.com/cashapp/multiplatform-paging)\n\n## Setup\n\nThis library is used on Kotlin Multiplatform that targets Android and iOS.\n\nCheck the table below for the compatibility across versions\n\n| Library | Kotlin | Paging        |\n|---------|--------| ------------- |\n| 0.6.2   | 1.8.0  | 3.1.1         |\n| 0.6.1   | 1.8.0  | 3.1.1         |\n| 0.6.0   | 1.7.20 | 3.1.1         |\n| 0.5.0   | 1.7.10 | 3.1.1         |\n| 0.4.7   | 1.6.10 | 3.1.0         |\n| 0.4.6   | 1.6.0  | 3.1.0         |\n| 0.4.5   | 1.5.31 | 3.0.1         |\n| 0.4.4   | 1.5.30 | 3.0.1         |\n| 0.4.3   | 1.5.30 | 3.0.1         |\n| 0.4.2   | 1.5.10 | 3.0.0         |\n| 0.4.1   | 1.5.10 | 3.0.0         |\n| 0.4.0   | 1.5.10 | 3.0.0         |\n| 0.3.11  | 1.4.32 | 3.0.0-beta03  |\n| 0.3.10  | 1.4.32 | 3.0.0-beta03  |\n| 0.3.9   | 1.4.31 | 3.0.0-beta01  |\n| 0.3.8   | 1.4.30 | 3.0.0-beta01  |\n| 0.3.4+  | 1.4.30 | 3.0.0-alpha13 |\n| 0.3.3   | 1.4.30 | 3.0.0-alpha11 |\n| 0.3.2   | 1.4.21 | 3.0.0-alpha11 |\n| 0.3.1   | 1.4.10 | 3.0.0-alpha07 |\n| 0.3.0   | 1.4.0  | 3.0.0-alpha06 |\n| 0.2.0   | 1.3.70 | 3.0.0-alpha01 |\n| 0.1.+   | 1.3.70 | 2.1.1         |\n| 0.1.0   | 1.3.61 | 2.1.1         |\n\nAdd the `mavenCentral` repository on your Project-level gradle\n```kotlin\nallprojects {\n    repositories {\n        ...\n        mavenCentral()\n    }\n}\n```\n\nOn the module, add the library in your dependencies.\n\n```kotlin\nkotlin {\n    ...\n    sourceSets[\"commonMain\"].dependencies {\n        implementation(\"io.github.kuuuurt:multiplatform-paging:{version}\")\n    }\n}\n```\n\nOn Android, make sure to add `androidx.paging:paging-runtime` as a dependency\n\nOn iOS, you have to export it on your targets\n```kotlin\nkotlin {\n    ...\n    cocoapods {\n        ...\n        framework {\n            ...\n            export(\"io.github.kuuuurt:multiplatform-paging:{version}\")\n        }\n    }\n\n    val commonMain by sourceSets.getting {\n        dependencies {\n            api(\"io.github.kuuuurt:multiplatform-paging:{version}\")\n            ...\n        }\n    }\n}\n```\n\n## Usage\n\n### Common\n\nMultiplatform paging exposes paginators which you can use in your multiplatform code to have common pagination on Android and iOS.\n\n```kotlin\nclass MyMultiplatformController {\n    private val pager = Pager\u003cInt, String\u003e(\n        clientScope = coroutineScope,\n        config = PagingConfig(\n            pageSize = 10,\n            enablePlaceholders = false // Ignored on iOS\n        ),\n        initialKey = 1, // Key to use when initialized\n        getItems = { currentKey, size -\u003e\n            val items = ... // How you will get the items (API Call or Local DB)\n            PagingResult(\n                items = items,\n                currentKey = currentKey,\n                prevKey = { _, _ -\u003e null }, // Key for previous page, null means don't load previous pages\n                nextKey = { items, currentKey -\u003e currentKey + 1 } // Key for next page. Use `items` or `currentKey` to get it depending on the pagination strategy\n            )\n        }\n    )\n\n    val pagingData: CommonFlow\u003cPagingData\u003cString\u003e\u003e\n        get() = pager.pagingData\n            .cachedIn(clientScope) // cachedIn from AndroidX Paging. on iOS, this is a no-op\n            .asCommonFlow() // So that iOS can consume the Flow \n}\n```\n\n*`CommonFlow` is a helper we can use to consume `Flow` on iOS. See [`FlowHelpers`](https://github.com/kuuuurt/multiplatform-paging/blob/develop/sample/multiplatform-library/src/commonMain/kotlin/com/kuuurt/paging/sample/multiplatform/library/helpers/FlowHelpers.kt)*\n\n### Android\n\nOn Android, multiplatform paging uses [Android Architecture Component's Paging library](https://developer.android.com/topic/libraries/architecture/paging) and exposes `pagedList` as a `Flow\u003candroidx.paging.PagedList\u003cT\u003e\u003e` which can be observed and submitted onto the `PagedListAdapter`.\n\n```kotlin\nclass MyFragment : Fragment() {\n    val myMultiplatformController = MyMultiplatformController()\n    val myPagingDataAdapter = MyPagingDataAdapter()\n    \n    override fun onViewCreated(...) {\n        super.onViewCreated(...)\n      \n        myMultiplatformController.pagingData\n            .onEach { myPagingDataAdapter.submitData(it) }\n            .launchIn(viewLifecyleOwner.lifecyclerScope)     \n    }\n}\n```\n\n### iOS\n\nOn iOS, it exposes `pagedList` as a `Flow\u003cList\u003cT\u003e\u003e` which can be observed and rendered to a `UITableView`\n\n```swift\nclass MyViewController UIViewController, UITableViewDelegate, UITableViewDataSource {\n    @IBOutlet weak var tableView: UITableView!\n    \n    let myMultiplatformController = MyMultiplatformController()\n    \n    private var data: [T] = []\n    private var count: Int = 0\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        // setup...\n        \n        myMultiplatformController.pagingData.watch { [unowned self] nullableArray in\n            guard let list = nullableArray?.compactMap({ $0 as? T }) else {\n                return\n            }\n      \n            self.data = list\n            self.count = list.count\n            self.tableView.reloadData()\n        }\n    }\n}\n```\n\n*Disclaimer: I'm not an iOS developer and this is what I was able to make of. If someone has a better example, contributions are welcome!*\n\n### Jetpack Compose and SwiftUI\n\nFor samples using Jetpack Compose and SwiftUI, you can refer to [MortyComposeKMM](https://github.com/joreilly/MortyComposeKMM) by [joreilly](https://github.com/joreilly).\n\n## Maintainers\n\n- Kurt Renzo Acosta - [kurt.r.acosta@gmail.com](mailto:kurt.r.acosta@gmail.com)\n\n## Contributing\n\nFeel free to dive in! [Open an issue](https://github.com/kuuuurt/multiplatform-paging/issues/new) or submit PRs.\n\n## License\n\n[Apache-2.0](LICENSE) © Kurt Renzo Acosta\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Utility","🏗 Architecture"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuuuurt%2Fmultiplatform-paging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuuuurt%2Fmultiplatform-paging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuuuurt%2Fmultiplatform-paging/lists"}