{"id":13872430,"url":"https://github.com/pourhadi/collectionview","last_synced_at":"2025-07-16T02:30:50.647Z","repository":{"id":146414431,"uuid":"230554934","full_name":"pourhadi/collectionview","owner":"pourhadi","description":"SwiftUI implementation of a collection view, similar to UICollectionView with UICollectionViewFlowLayout.","archived":false,"fork":false,"pushed_at":"2020-01-07T10:17:04.000Z","size":184,"stargazers_count":37,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-05T13:46:32.270Z","etag":null,"topics":["collectionview","ios","ios13","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pourhadi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-12-28T03:52:07.000Z","updated_at":"2023-09-29T15:53:30.000Z","dependencies_parsed_at":"2024-01-16T10:09:29.943Z","dependency_job_id":null,"html_url":"https://github.com/pourhadi/collectionview","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourhadi%2Fcollectionview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourhadi%2Fcollectionview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourhadi%2Fcollectionview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pourhadi%2Fcollectionview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pourhadi","download_url":"https://codeload.github.com/pourhadi/collectionview/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":214112062,"owners_count":15685288,"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":["collectionview","ios","ios13","swift","swiftui"],"created_at":"2024-08-05T23:00:42.720Z","updated_at":"2024-08-05T23:02:01.000Z","avatar_url":"https://github.com/pourhadi.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# CollectionView\n\nA SwiftUI implementation of a grid layout similar to UICollectionView with UICollectionViewFlowLayout.\n\nUpdates and documentation to follow.\n\n## Features\n\n* Bindings to the data source and selected items\n* Selection mode\n* Custom column count\n* Custom row height\n* Custom spacing\n* Block-based tap and long-press actions\n* @ViewBuilder to produce each item's view (cell)\n\n## Usage\n\nAdd `import CollectionView` to your SwiftUI file and add `CollectionView(...)` to your view hierarchy. \n\n```swift\nimport SwiftUI\nimport CollectionView\n\nstruct CollectionView_Previews: PreviewProvider {\n    struct ItemModel: Identifiable, Equatable {\n        let id: Int\n        let color: Color\n    }\n    \n    @State static var items = [ItemModel(id: 0, color: Color.red),\n                               ItemModel(id: 1, color: Color.blue),\n                               ItemModel(id: 2, color: Color.green),\n                               ItemModel(id: 3, color: Color.yellow),\n                               ItemModel(id: 4, color: Color.orange),\n                               ItemModel(id: 5, color: Color.purple)]\n    \n    @State static var selectedItems = [ItemModel]()\n    @State static var selectionMode = false\n    \n    static var previews: some View {\n        CollectionView(items: $items,\n                       selectedItems: $selectedItems,\n                       selectionMode: $selectionMode)\n        { item, _ in\n            Rectangle()\n                .foregroundColor(item.color)\n        }\n    }\n}\n\n```\n![Screenshot](https://github.com/pourhadi/collectionview/blob/master/screenshot.png?raw=true)\n\n### CollectionView init parameters\n\n * `items: Binding\u003c[Item]\u003e`\n\n    Required. \n\n    A binding to an array of values that conform to `Identifiable` and `Equatable`. This is the collection view's data source.\n\n* `selectedItems: Binding\u003c[Item]\u003e`\n\n    Required.\n\n    A binding to an array of values that conform to `Identifiable` and `Equatable`.\n\n    When `selectionMode` is true, this will populate with the items selected by the user. When `selectionMode` is false, this will either be an empty array or be populated with the most-recently-selected item. Good to use for displaying / dismissing a child / detail view.\n\n* `selectionMode: Binding\u003cBool\u003e`\n\n    Required.\n\n    A binding to a bool value. Set to true to set the collection view in to selection mode.\n\n* `layout: CollectionView.Layout`\n\n    Not required. Default is `CollectionView.Layout()`\n    \n    `Layout` is a struct containing the layout information for the collection view, with the defaults:\n   \n    * `itemSpacing: CGFloat` = 2.0\n    * `numberOfColumns: Int` = 3   \n    * `rowHeight: CollectionView.RowHeight` = .sameAsItemWidth\n\n        An enum for setting the desired height for the collection view's rows.\n\n         ```swift\n         public typealias CollectionViewRowHeightBlock = (_ row: Int, _ rowMetrics: GeometryProxy, _ itemSpacing: CGFloat, _ numberOfColumns: Int) -\u003e CGFloat\n\n         public enum RowHeight {\n             case constant(CGFloat)\n             case sameAsItemWidth\n             case dynamic(CollectionViewRowHeightBlock)\n         }\n          ```\n    * `rowPadding: EdgeInsets` = EdgeInsets initialized with all zeros\n    * `scrollViewInsets: EdgeInsets` = EdgeInsets initialized with all zeros\n\n* `tapAction: ((Item, GeometryProxy) -\u003e Void)?`\n\n    Not required. Defaults to nil.\n\n    A block that will be called if an item is tapped on.\n\n* `longPressAction: ((Item, GeometryProxy) -\u003e Void)?`\n\n    Not required. Defaults to nil.\n\n    A block that will be called after a successful long-press gesture on the item cell.\n    \n* `pressAction: ((Item, Bool) -\u003e Void)?`\n\n    Not required. Defaults to nil.\n\n    A block that will be called when a long-press gesture is possible, with a bool indicating whether the item is being pressed.\n    \n* `itemBuilder: @escaping (Item, _ itemMetrics: GeometryProxy) -\u003e ItemContent)`\n\n    Required.\n\n    A block that produces the view (cell) associated with a particular item.\n    \n\n\n## Planned features:\n* Sections\n* Customizable selection style\n* ??\n\n## Installation\n\n#### Swift Package Manager\nYou can use [The Swift Package Manager](https://swift.org/package-manager) to install this library.\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"YOUR_PROJECT_NAME\",\n    targets: [],\n    dependencies: [\n        .package(url: \"https://github.com/pourhadi/collectionview.git\", .branch(\"master\"))    \n    ]\n)\n```\n\nNote that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more information checkout its [GitHub Page](https://github.com/apple/swift-package-manager).\n\n## License (MIT)\n\nCopyright (c) 2019 - present Daniel Pourhadi\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\nall copies 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\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpourhadi%2Fcollectionview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpourhadi%2Fcollectionview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpourhadi%2Fcollectionview/lists"}