{"id":30719831,"url":"https://github.com/dankinsoid/uikitviews","last_synced_at":"2025-09-03T10:42:21.564Z","repository":{"id":170293796,"uuid":"646423816","full_name":"dankinsoid/UIKitViews","owner":"dankinsoid","description":"UIKitViews is a SwiftUI wrapper around UIView and UIViewController","archived":false,"fork":false,"pushed_at":"2025-01-02T11:41:30.000Z","size":245,"stargazers_count":22,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-27T13:32:32.284Z","etag":null,"topics":["swift","swiftui","uiviewcontrollerrepresentable","uiviewrepresentable"],"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/dankinsoid.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":"2023-05-28T11:04:18.000Z","updated_at":"2025-05-26T00:12:20.000Z","dependencies_parsed_at":"2024-09-15T12:59:22.752Z","dependency_job_id":"85fb8595-b73b-47cf-b9a2-2043f40b7155","html_url":"https://github.com/dankinsoid/UIKitViews","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"d2910f785d7b56c942a102d9f7eade3f238d152f"},"previous_names":["dankinsoid/uikitview"],"tags_count":18,"template":false,"template_full_name":"dankinsoid/iOSLibraryTemplate","purl":"pkg:github/dankinsoid/UIKitViews","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FUIKitViews","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FUIKitViews/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FUIKitViews/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FUIKitViews/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dankinsoid","download_url":"https://codeload.github.com/dankinsoid/UIKitViews/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FUIKitViews/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273431361,"owners_count":25104491,"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-09-03T02:00:09.631Z","response_time":76,"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":["swift","swiftui","uiviewcontrollerrepresentable","uiviewrepresentable"],"created_at":"2025-09-03T10:42:20.665Z","updated_at":"2025-09-03T10:42:21.551Z","avatar_url":"https://github.com/dankinsoid.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UIKitViews\n\nUIKitViews is a SwiftUI wrapper around `UIView` and `UIViewController`. It provides seamless integration of UIKit components with the SwiftUI framework. The UIKitView wrapper makes it incredibly easy to add and manipulate UIKit views and view controllers directly from your SwiftUI views.\\\nUIKitViews is built on top of [VDChain](https://github.com/dankinsoid/VDChain.git) and is part of the [VDLayout](https://github.com/dankinsoid/VDLayout.git) library that provides DSL syntax for UIKit views and view controllers.\n\n## Features\n\n- Straightforward integration of UIKit components into SwiftUI environment\n- Support for environment variables through `UIView`/`UIViewController` keypaths\n- `HostingView`, an analog of `UIHostingController` for UIView that supports updating via keypath\n- `SelfSizingHostingController` - a `UIHostingController` that matches the root view size\n- Provides `uiKitViewFixedSize()` and `uiKitViewContentMode()` methods for dynamic self-sizing of UIKit views\n\n## Usage\nUsing UIKitViews is as simple as placing the `UIView` or `UIViewController` you want within the `UIKitView` closure:\n\n```swift\nUIKitView {\n    UILabel().chain\n       .font(.systemFont(ofSize: 24)) // Constant properties\n       .textColor(.black)\n}\n.text(title) // Updatable properties\n```\n\u003e [!NOTE]\n\u003e The `UIKitView` body closure is called only once when the view is created, so there is no reason to use any updatable variables in this closure. However, it’s the perfect place to set up constant parameters, such as constraints or fonts, for example.\n\n\u003e [!NOTE]\n\u003e `.text`, `.textColor`, and `.font` in this example are not hardcoded methods; they are keypath chains. This means any properties of your UIKit views can be used as modifier methods with `UIKitView`.\n\n### Operator\nUIKitViews provides a special operator `§` that allows you to create a `UIKitView` more concisely with an autoclosure:\n\n```swift\nUILabel()§\n  .font(.systemFont(ofSize: 24)) \n  .textColor(.black)\n  .text(title)\n```\n\n## Environments\n\n`UIKitView` also supports environment variables through `UIView`/`UIViewController` keypaths:\n\n```swift\nVStack {\n  UIKitView {\n    UILabel()\n  }\n  UIKitView {\n    UILabel()\n  }\n}\n.uiKitViewEnvironment(\\UILabel.font, .systemFont(ofSize: 24))\n```\n\nIf you need to access the environment, you can do it like this:\n\n```swift\n@Environment(\\UILabel.font) var uiLabelFont\n```\n You can also bind SwiftUI environments to `UIKitView`:\n ```swift\nUIKitView {\n\tUIScrollView()\n}\n.uiKitViewBind(environment: \\.isScrollEnabled, to: \\UIScrollView.isScrollEnabled)\n ```\n## Self-sizing with `uiKitViewFixedSize()`\n\nThe library includes a method `uiKitViewFixedSize()` that allows the UIKit view to adjust its size dynamically according to its content. You can specify the axis for self-sizing:\n\n- For self-sizing in both dimensions:\n\n```swift\n.uiKitViewFixedSize()\n```\n\n- For self-sizing mostly in the vertical dimension:\n\n```swift\n.uiKitViewFixedSize(.vertical)\n```\n\n- For self-sizing mostly in the horizontal dimension:\n\n```swift\n.uiKitViewFixedSize(.horizontal)\n```\n\n\u003e [!NOTE]\n\u003e If you know the height or width of your view, it’s more reliable to set it using the SwiftUI `frame` modifier instead of `uiKitViewFixedSize`.\n\n\u003e [!WARNING]\n\u003e The behavior of these methods may differ slightly between iOS 16+ and previous versions. It's recommended to test on different iOS versions.\\\nIf you notice any undesirable differences, you can use the `uiKitViewUseWrapper(.always)` method to fix it.\n\n### uiKitViewContentMode(_:)\n\nThe `uiKitViewContentMode(_:)` method adjusts the content resizing behavior of a UIView when its size is not fixed.\nYou pass a `UIKitViewContentMode` value to this method to specify how you want the view to resize its content.\n\nIt comes with two modes:\n- `.fill`: The content should resize to completely fill the view. The aspect ratio may not be preserved.\n- `.fit(Alignment)`: The UIView should resize to fit within the view while preserving its aspect ratio. The alignment parameter determines how the UIView is positioned within the view if there is extra space.\n\nHere's an example:\n\n```swift\nUIKitView {\n    UILabel().chain\n       .font(.system(34))\n       .textColor(.black)\n       .textAlignment(.left)\n}\n.uiKitViewFixedSize(.vertical)\n.uiKitViewContentMode(.fit(.trailing))\n```\nIn this example, the UILabel will resize its content to fit within its bounds while preserving its aspect ratio. The content is positioned at the trailing edge of the UIKitView.\n\n## `HostingView` and `SelfSizingHostingController`\n\nThe repository contains two other key features:\n\n- `HostingView`: This is an analogy of `UIHostingController` for `UIView`. It supports updating by keypath.\n```swift\nstruct SomeView: View {\n\n  var text: String\n  // ...\n}\n// ...\nlet hosting = HostingView(SomeView())\nhosting.text = \"new text\" // it will update the view\n```\n- `SelfSizingHostingController`: This is an `UIHostingController` that matches the View size, allowing your views to automatically adjust to the size of their content.\n\n## Installation\n\n1. [Swift Package Manager](https://github.com/apple/swift-package-manager)\n\nCreate a `Package.swift` file.\n```swift\n// swift-tools-version:5.7\nimport PackageDescription\n\nlet package = Package(\n  name: \"SomeProject\",\n  dependencies: [\n    .package(url: \"https://github.com/dankinsoid/UIKitViews.git\", from: \"1.5.0\")\n  ],\n  targets: [\n    .target(name: \"SomeProject\", dependencies: [\"UIKitView\"])\n  ]\n)\n```\n```ruby\n$ swift build\n```\n\n2.  [CocoaPods](https://cocoapods.org)\n\nAdd the following line to your Podfile:\n```ruby\npod 'UIKitViews'\n```\nand run `pod update` from the podfile directory first.\n\n## Author\n\ndankinsoid, voidilov@gmail.com\n\n## License\n\nUIKitView is available under the MIT license. See the LICENSE file for more info.\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankinsoid%2Fuikitviews","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdankinsoid%2Fuikitviews","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankinsoid%2Fuikitviews/lists"}