{"id":18458298,"url":"https://github.com/kaustubhpatange/composition-adapter","last_synced_at":"2025-07-17T05:39:40.459Z","repository":{"id":180626726,"uuid":"558746244","full_name":"KaustubhPatange/composition-adapter","owner":"KaustubhPatange","description":"A way of writing RecyclerView adapter through Kotlin's DSL","archived":false,"fork":false,"pushed_at":"2023-09-20T15:46:19.000Z","size":15317,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T05:34:05.932Z","etag":null,"topics":["kotlin","lifecycle","paging3","recyclerview","recyclerview-adapter"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KaustubhPatange.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-28T07:48:16.000Z","updated_at":"2024-06-17T09:22:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"e61edc02-35d1-406d-94cf-ca70b9b7ed4e","html_url":"https://github.com/KaustubhPatange/composition-adapter","commit_stats":null,"previous_names":["kaustubhpatange/composition-adapter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KaustubhPatange/composition-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaustubhPatange%2Fcomposition-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaustubhPatange%2Fcomposition-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaustubhPatange%2Fcomposition-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaustubhPatange%2Fcomposition-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KaustubhPatange","download_url":"https://codeload.github.com/KaustubhPatange/composition-adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KaustubhPatange%2Fcomposition-adapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262884682,"owners_count":23379428,"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":["kotlin","lifecycle","paging3","recyclerview","recyclerview-adapter"],"created_at":"2024-11-06T08:17:46.350Z","updated_at":"2025-07-01T02:37:40.237Z","avatar_url":"https://github.com/KaustubhPatange.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# composition-adapter\n\nA simplified way of writing RecyclerView Adapter through Kotlin DSL promoting composition over\ninheritance. It internally creates a [Paging3 Adapter](#q-why-paging3-adapter).\n\n## Features\n\n- Create adapters/viewHolder using Kotlin DSL.\n- [Lifecycle aware](#q-lifecycle-aware-viewholder) View Holders.\n- Built-in support for View binding.\n- Loading state adapters (show loaders during first load or during load more).\n- Less boilerplate to write.\n\n## Quick Setup\n\n![Maven Central](https://img.shields.io/maven-central/v/io.github.kaustubhpatange/compose-adapter)\n\n- Add dependency or directly use the `compose-adapter` module in your project.\n\n```groovy\nimplementation(\"io.github.kaustubhpatange:compose-adapter:$LATEST\")\n```\n\n- Define adapter and ViewHolder(s) for your RecyclerView.\n\n```kotlin\nval adapter = composeAdapter {\n    addHolder(\n        DataClass::class,\n        DataClassViewBinding::inflate\n    ) {\n        onBind = { item, _ -\u003e\n            with(this.binding) {\n              this.textView.text = ...\n              // ^? \"this\" is your ViewBinding context.\n            }\n        }\n    }\n}\n\nrecyclerView.adapter = adapter\n```\n\n- A [sample](sample/) app is available which implements,\n  - **Paging Example**: A compelete network first paging example.\n  - **Nested RecyclerView Example**: An example which implements nested `RecyclerView` using composition adapter.\n\n## Apps using `composition-adapter`\n\n|                                                         |                                                                                                                                                                                                                                                                                                                                   |\n| ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| \u003cimg width=\"300\" src=\"art/pratilipi-comics-demo.gif\" /\u003e | [Pratilipi Comics](https://play.google.com/store/apps/details?id=com.pratilipi.comics) is the most popular comic reading platform in India with over 10+ million downloads. \u003cbr\u003e\u003cbr\u003e The home page is a paging list using `composition-adapter` having over 20+ `ViewHolder`s. \u003cbr\u003e\u003cbr\u003e _Gif is running in 8fps with 1.5x speed._ |\n\n## FAQs\n\n### Q. Why Paging3 adapter?\n\n`PagingDataAdapter` is used to support closed range data as well as open ended (paginated data).\nWith it's async diffutil strategy through `AsyncPagingDataDiffer`, updates are computed on a\nbackground thread which provides performance improvement over synchronous updates. This is typically\nhelpful for a large dataset.\n\nYou don't need `RemoteMediator` for synchronizing local DB and network updates instead you can use\nplain simple `PagingSource` with your custom logic to deal with this use case or a better way would\nbe to rely on HTTP cache-control headers which should be automatically respected by any HTTP client.\nThis way you don't need to overcomplicate things by using `RemoteMediator`.\n\nAs it is generally nothing but a `RecyclerView.Adapter`, we can also use a non-paging (static) data.\n\n### Q. Lifecycle aware ViewHolder\n\n`ViewHolder`s in compose adapter are lifecycle aware which means you can observe `LiveData` / `Flow`\nor launch a coroutine safely within `onBind`, `onCreate`. You will get appropriate state changes\nlike `ON_CREATE`, `ON_RESUME`, `ON_STOP` based on when `RecyclerView` tries to recycle views.\n\nUse `lifecycleCoroutineScope` to launch coroutines. Since `onBind` is called multiple times, it is best to collect `Flow` or `LiveData` during `onAttach`.\n\n# License\n\n- [The MIT License](LICENSE)\n\n```\nCopyright (c) 2022 Kaustubh Patange\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaustubhpatange%2Fcomposition-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaustubhpatange%2Fcomposition-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaustubhpatange%2Fcomposition-adapter/lists"}