{"id":20336627,"url":"https://github.com/olehkorchytskyi/fit","last_synced_at":"2025-04-11T22:41:05.357Z","repository":{"id":224601100,"uuid":"751029207","full_name":"OlehKorchytskyi/Fit","owner":"OlehKorchytskyi","description":"SwiftUI layout for arranging elements in lines, dynamically adjusting to the available space.","archived":false,"fork":false,"pushed_at":"2024-06-09T14:52:11.000Z","size":33,"stargazers_count":57,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-20T19:43:39.094Z","etag":null,"topics":["flow-layout","layout","swift","swiftui","ui"],"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/OlehKorchytskyi.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":"2024-01-31T19:46:34.000Z","updated_at":"2025-03-19T09:36:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"d38a9e85-24e6-45f7-a819-5a80e32764f4","html_url":"https://github.com/OlehKorchytskyi/Fit","commit_stats":null,"previous_names":["olehkorchytskyi/fit"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OlehKorchytskyi%2FFit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OlehKorchytskyi%2FFit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OlehKorchytskyi%2FFit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OlehKorchytskyi%2FFit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OlehKorchytskyi","download_url":"https://codeload.github.com/OlehKorchytskyi/Fit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248493022,"owners_count":21113159,"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":["flow-layout","layout","swift","swiftui","ui"],"created_at":"2024-11-14T21:06:12.153Z","updated_at":"2025-04-11T22:41:05.331Z","avatar_url":"https://github.com/OlehKorchytskyi.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/SwiftUI-874dbf.svg\"/\u003e\n    \u003cimg src=\"https://img.shields.io/badge/macOS-13.0+-212121.svg\"/\u003e\n    \u003cimg src=\"https://img.shields.io/badge/iOS-16+-212121.svg\"/\u003e\n    \u003cimg src=\"https://img.shields.io/badge/tvOS-16.0+-212121.svg\"/\u003e\n    \u003cimg src=\"https://img.shields.io/badge/watchOS-9.0+-212121.svg\"/\u003e\n    \u003ca href=\"https://twitter.com/OKorchytskyi\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Contact-@OKorchytskyi-212121\" alt=\"Twitter: @OKorchytskyi\"/\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n**Fit** allows you to lay out your views into lines without ever bothering to group or measure them, all thanks to the implementation of the **Layout** protocol.\n\n\n## Usage\n\n\nAdd your views just like you would do it with all other **SwiftUI** stacks:\n\n```swift\nimport Fit\n\nFit {\n    Text(\"Tags:\")\n\n    ForEach(tags) { tag in\n        TagView(tag: tag)\n    }\n\n    TextField(\"New tag\", text: $input)\n}\n```\n![tag_list_example](https://github.com/OlehKorchytskyi/Fit/assets/4789347/270802ea-6bea-455a-afa6-084ba48ffdba)\n\n\u003e [!NOTE]\n\u003e Full code for this example: [Tag List Example](https://github.com/OlehKorchytskyi/FitPlayground/blob/main/FitPlayground/FitPlayground/Examples/TagListExample.swift).\n\n## Customisation\n\n**Fit** provides multiple ways to customise your layout:\n\n#### Line Alignment and Spacing\n\n```swift\n// .leading (default), .center or .trailing\nFit(lineAlignment: .center, lineSpacing: 12) {\n    // views\n}\n```\n\u003e [!NOTE]\n\u003e The default line spacing is **.viewSpacing**, which merges spacing of all items in the line and then uses vertical distance, [ViewSpacing.distance](https://developer.apple.com/documentation/swiftui/viewspacing/distance(to:along:)), to add spacing between to lines.\n\n#### Item Alignment and Spacing\n\nYou can align items in the same way you would do in **HStack**:\n\n```swift\n// fixed item spacing\nFit(itemAlignment: .firstTextBaseline, itemSpacing: 8) {\n    // views\n}\n\n// view's preferred spacing\nFit(itemAlignment: .firstTextBaseline, itemSpacing: .viewSpacing(minimum: 8)) {\n    // views\n}\n```\n\n#### Line-Break\n\nUse view modifier to add line-break before or after a particular view:\n\n```swift\nFit {\n    Text(\"Title:\")\n        .fit(lineBreak: .after)\n    // next views\n}\n```\n\n#### Per-line styling\n\nYou can define secific style for each line with **LineStyle**:\n```swift\nlet conveyorBeltStyle: LineStyle = .lineSpecific { style, line in\n    // reverse every second line\n    style.reversed = (line.index + 1).isMultiple(of: 2)\n    // if the line is reversed, it should start from the trailing edge\n    style.alignment = style.reversed ? .trailing : .leading\n}\n\nFit(lineStyle: conveyorBeltStyle) {\n    // views\n}\n```\n![conveyor_belt_example](https://github.com/OlehKorchytskyi/Fit/assets/4789347/586f3c5c-f769-4ee0-a93d-2f6316ee9444)\n\n\u003e [!NOTE]\n\u003e Full code for this example: [Conveyor Belt Example](https://github.com/OlehKorchytskyi/FitPlayground/blob/main/FitPlayground/FitPlayground/Examples/ConveyorBeltExample.swift).\n\nIt is also possible to create a variable style:\n\n```swift\nvar fancyAlignJustified: LineStyle {\n    .lineSpecific { style, line in\n        if stretch {\n            style.stretched = line.percentageFilled \u003e= threshold\n        }\n    }\n}\n\nFit(lineStyle: fancyAlignJustified) {\n    // views\n}\n```\n![stretching_example](https://github.com/OlehKorchytskyi/Fit/assets/4789347/a926cac6-9ac5-431a-88cc-a62e4d7ee456)\n\n\u003e [!NOTE]\n\u003e Full code for this example: [Long Text Example](https://github.com/OlehKorchytskyi/FitPlayground/blob/main/FitPlayground/FitPlayground/Examples/LongTextExample.swift).\n\n## Installing\n\nUse **Swift Package Manager** to get **Fit**:\n```swift\n.package(url: \"https://github.com/OlehKorchytskyi/Fit\", from: \"1.0.2\")\n```\n\nImport **Fit** into your Swift code:\n\n```swift\nimport Fit\n```\n\n\n\n## License\n\nMIT License.\n\nCopyright (c) 2024 Oleh Korchytskyi.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folehkorchytskyi%2Ffit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folehkorchytskyi%2Ffit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folehkorchytskyi%2Ffit/lists"}