{"id":32151852,"url":"https://github.com/oneinc-jp/compositionallayoutviewcontroller","last_synced_at":"2025-10-21T10:54:13.140Z","repository":{"id":56906468,"uuid":"369397827","full_name":"oneinc-jp/CompositionalLayoutViewController","owner":"oneinc-jp","description":"Declaretive UICollectionViewCompositionalLayout interface to implement complex collection view layout.","archived":false,"fork":false,"pushed_at":"2023-05-23T09:30:54.000Z","size":2076,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-21T10:54:07.228Z","etag":null,"topics":["collectionview","collectionviewcontroller","collectionviewlayout","ios","ios13","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/oneinc-jp.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}},"created_at":"2021-05-21T03:01:18.000Z","updated_at":"2025-04-07T05:04:38.000Z","dependencies_parsed_at":"2022-08-21T03:20:47.179Z","dependency_job_id":null,"html_url":"https://github.com/oneinc-jp/CompositionalLayoutViewController","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/oneinc-jp/CompositionalLayoutViewController","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneinc-jp%2FCompositionalLayoutViewController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneinc-jp%2FCompositionalLayoutViewController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneinc-jp%2FCompositionalLayoutViewController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneinc-jp%2FCompositionalLayoutViewController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oneinc-jp","download_url":"https://codeload.github.com/oneinc-jp/CompositionalLayoutViewController/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneinc-jp%2FCompositionalLayoutViewController/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280248570,"owners_count":26297925,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["collectionview","collectionviewcontroller","collectionviewlayout","ios","ios13","swift"],"created_at":"2025-10-21T10:54:11.991Z","updated_at":"2025-10-21T10:54:13.135Z","avatar_url":"https://github.com/oneinc-jp.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CompositionalLayoutViewController\n\n[![CI Status](https://img.shields.io/travis/Akira/CompositionalLayoutViewController.svg?style=flat)](https://travis-ci.org/Akira/CompositionalLayoutViewController)\n[![Version](https://img.shields.io/cocoapods/v/CompositionalLayoutViewController.svg?style=flat)](https://cocoapods.org/pods/CompositionalLayoutViewController)\n[![License](https://img.shields.io/cocoapods/l/CompositionalLayoutViewController.svg?style=flat)](https://cocoapods.org/pods/CompositionalLayoutViewController)\n[![Platform](https://img.shields.io/cocoapods/p/CompositionalLayoutViewController.svg?style=flat)](https://cocoapods.org/pods/CompositionalLayoutViewController)\n\n![](Image/ss.png)\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\niOS 13.0+\n\n## Installation\n\nCompositionalLayoutViewController is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'CompositionalLayoutViewController'\n```\n\n## Usage\nThere are four steps to declare collection view.\n\nFirstly, to compose complex collection view sections, you implement `Section` class that inherits `CollectionViewSection`.\n```swift\nclass TextFormSection: CollectionViewSection {\n    ...\n}\n```\n\nSecondly, implement your sections layout.\n```swift\nfunc layoutSection(environment: NSCollectionLayoutEnvironment) -\u003e NSCollectionLayoutSection\n```\n\nThirdly, register cells and supplementary views for collection view in `func registerCell(collectionView: UICollectionView)` and `func registerSupplementaryView(collectionView: UICollectionView)`.\n```swift\nfunc registerCell(collectionView: UICollectionView) {\n    // register cells here\n}\n```\n\n```swift\nfunc registerSupplementaryView(collectionView: UICollectionView) {\n    // register supplementary views here\n}\n```\nMake sure that you implement `func supplementaryView(_ collectionView: UICollectionView, kind: String, indexPath: IndexPath) -\u003e UICollectionReusableView?`.\nYou may have to deque `UICollectionReusableView` from a collection view.\n\nThese cells and supplementary views are configured following methods.\n```swift\nfunc cell(_ collectionView: UICollectionView, indexPath: IndexPath) -\u003e UICollectionViewCell?\n```\n\n```swift\nfunc configureSupplementaryView(_ view: UICollectionReusableView, indexPath: IndexPath)\n```\n\nYou also have to declare `var snapshotItems: [AnyHashable]` in your section class.\nThis variable contains datas for each cells.\n```swift\nvar snapshotItems: [AnyHashable] {\n    // return AnyHashable items\n}\n```\n\nFinally, you can declare collection view sections in subclass of `CompositionalLayoutViewController` as follows:\n```swift\nsections = [\n    TextFormSection(\n        items: [\n            .init(\n                initialText: nil,\n                textForm: .init(\n                    placeholder: \"Email\",\n                    validationHandler: { text in\n                        guard let text = text else {\n                            return false\n                        }\n                        return text.isValidEmailAddress()\n                    },\n                    validationAppearance: .init(\n                        textColor: .red\n                    )\n                )\n            ),\n            .init(\n                initialText: nil,\n                textForm: .init(\n                    placeholder: \"Password\",\n                    isSecureTextEntry: true\n                )\n            )\n        ]\n    ),\n    ButtonSection(\n        buttonTitle: \"Login\",\n        action: .handler({\n            print(\"Login button pressed\")\n        })\n    )\n]\nreloadSections()\n```\n\nAnd also don't forget to assign `SectionProvider` that manages an array of sections.\n```swift\npublic protocol SectionProvider: AnyObject {\n    var sections: [CollectionViewSection] { get }\n    func section(for sectionIndex: Int) -\u003e CollectionViewSection\n}\n```\n```swift\noverride func viewDidLoad() {\n    super.viewDidLoad()\n    ...\n    provider = // assign your provider e.g. presenter in VIPER\n    ...\n}\n```\n\nTo handle cell selection, override `func didSelectItem(at indexPath: IndexPath)` method in subclass of `CompositionalLayoutViewController`.\n\nSee example code to lean advanced usage.\n\n## Author\n\nAkira, akira.matsuda@me.com\n\n## License\n\nCompositionalLayoutViewController is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foneinc-jp%2Fcompositionallayoutviewcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foneinc-jp%2Fcompositionallayoutviewcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foneinc-jp%2Fcompositionallayoutviewcontroller/lists"}