{"id":13752116,"url":"https://github.com/spacenation/swiftui-grid","last_synced_at":"2025-10-21T10:46:54.947Z","repository":{"id":43532771,"uuid":"199353007","full_name":"spacenation/swiftui-grid","owner":"spacenation","description":":rocket: SwiftUI Grid layout with custom styles","archived":true,"fork":false,"pushed_at":"2020-12-27T00:25:28.000Z","size":27691,"stargazers_count":962,"open_issues_count":0,"forks_count":58,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-09-20T00:43:14.484Z","etag":null,"topics":["apple","grid","ios","macos","swift","swift-library","swift-package","swiftui","swiftui-example","tvos","watchos","xcode"],"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/spacenation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["ay42"]}},"created_at":"2019-07-29T00:51:13.000Z","updated_at":"2025-08-26T23:32:50.000Z","dependencies_parsed_at":"2022-08-30T02:11:36.869Z","dependency_job_id":null,"html_url":"https://github.com/spacenation/swiftui-grid","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/spacenation/swiftui-grid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacenation%2Fswiftui-grid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacenation%2Fswiftui-grid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacenation%2Fswiftui-grid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacenation%2Fswiftui-grid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spacenation","download_url":"https://codeload.github.com/spacenation/swiftui-grid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacenation%2Fswiftui-grid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278715508,"owners_count":26033296,"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-07T02:00:06.786Z","response_time":59,"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":["apple","grid","ios","macos","swift","swift-library","swift-package","swiftui","swiftui-example","tvos","watchos","xcode"],"created_at":"2024-08-03T09:00:59.709Z","updated_at":"2025-10-07T03:30:42.517Z","avatar_url":"https://github.com/spacenation.png","language":"Swift","funding_links":["https://github.com/sponsors/ay42"],"categories":["🌎 by the community","xcode","UI"],"sub_categories":["Grid"],"readme":"[![Build Status](https://github.com/spacenation/swiftui-grid/workflows/ci/badge.svg)](https://github.com/spacenation/swiftui-grid/actions)\n\n## SwiftUI Grid\nSwiftUI Grid view layout with custom styles.\n\n## Features\n- ZStack based layout\n- Vertical and horizontal scrolling\n- Supports all apple platforms\n- Custom styles (ModularGridStyle, StaggeredGridStyle)\n- SwiftUI code patterns (StyleStructs, EnvironmentValues, ViewBuilder)\n- Active development for production apps\n\nOpen `GridDemo.xcodeproj` for more examples for iOS, macOS, watchOS and tvOS\n\n## Styles\n\n### ModularGridStyle (Default)\n\u003ccenter\u003e\n\u003cimg src=\"Resources/modularGrid.png\"/\u003e\n\u003c/center\u003e\n\n```swift\nScrollView {\n    Grid(colors) {\n        Rectangle()\n            .foregroundColor($0)\n    }\n}\n.gridStyle(\n    ModularGridStyle(columns: .min(100), rows: .fixed(100))\n)\n```\n\n### StaggeredGridStyle\n\n\u003ccenter\u003e\n\u003cimg src=\"Resources/staggeredGrid.png\"/\u003e\n\u003c/center\u003e\n\n```swift\nScrollView {\n    Grid(1...69, id: \\.self) { index in\n        Image(\"\\(index)\")\n            .resizable()\n            .scaledToFit()\n    }\n}\n.gridStyle(\n    StaggeredGridStyle(.horizontal, tracks: 8, spacing: 4)\n)\n```\n\n## Tracks\nTracks setting allows you to customize grid behaviour to your specific use-case. Both Modular and Staggered grid use tracks value to calculate layout. In Modular layout both columns and rows are tracks.\n\n```swift\npublic enum Tracks: Hashable {\n    case count(Int)\n    case fixed(CGFloat)\n    case min(CGFloat)\n}\n```\n\n### Count\nGrid is split into equal fractions of size provided by a parent view.\n\n```swift\nModularGridStyle(columns: 3, rows: 3)\nStaggeredGridStyle(tracks: 8)\n```\n\n### Fixed\nItem size is fixed to a specific width or height.\n```swift\nModularGridStyle(columns: .fixed(100), rows: .fixed(100))\nStaggeredGridStyle(tracks: .fixed(100))\n```\n\n### Min\nAutolayout respecting a min item width or height.\n```swift\nModularGridStyle(columns: .min(100), rows: .fixed(100))\nStaggeredGridStyle(tracks: .min(100))\n```\n\n## Preferences\nGet item size and position with preferences\n```swift\nstruct CardsView: View {\n    @State var selection: Int = 0\n    \n    var body: some View {\n        ScrollView {\n            Grid(0..\u003c100) { number in\n                Card(title: \"\\(number)\")\n                    .onTapGesture {\n                        self.selection = number\n                    }\n            }\n            .padding()\n            .overlayPreferenceValue(GridItemBoundsPreferencesKey.self) { preferences in\n                RoundedRectangle(cornerRadius: 16)\n                    .strokeBorder(lineWidth: 4)\n                    .foregroundColor(.white)\n                    .frame(\n                        width: preferences[self.selection].width,\n                        height: preferences[self.selection].height\n                    )\n                    .position(\n                        x: preferences[self.selection].midX,\n                        y: preferences[self.selection].midY\n                    )\n                    .animation(.linear)\n            }\n        }\n    }\n}\n```\n\n## SDKs\n- iOS 13.1+\n- Mac Catalyst 13.1+\n- macOS 10.15+\n- watchOS 6+\n- Xcode 11.0+\n\n## Roadmap\n- Items span\n- 'CSS Grid'-like features\n\n## Code Contributions\nFeel free to contribute via fork/pull request to master branch. If you want to request a feature or report a bug please start a new issue.\n\n## Coffee Contributions\nIf you find this project useful please consider becoming my GitHub sponsor.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacenation%2Fswiftui-grid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspacenation%2Fswiftui-grid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacenation%2Fswiftui-grid/lists"}