{"id":22192550,"url":"https://github.com/3sidedcube/hybridkit","last_synced_at":"2025-10-16T05:36:42.308Z","repository":{"id":184407258,"uuid":"608707258","full_name":"3sidedcube/HybridKit","owner":"3sidedcube","description":"Bridging between UIKit and SwiftUI","archived":false,"fork":false,"pushed_at":"2023-08-01T09:24:00.000Z","size":28,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":9,"default_branch":"develop","last_synced_at":"2025-01-30T01:22:38.071Z","etag":null,"topics":[],"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/3sidedcube.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-02T15:18:08.000Z","updated_at":"2024-08-01T14:57:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"d017d166-b53d-43dc-b143-7185c8474a46","html_url":"https://github.com/3sidedcube/HybridKit","commit_stats":null,"previous_names":["3sidedcube/hybridkit"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHybridKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHybridKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHybridKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHybridKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3sidedcube","download_url":"https://codeload.github.com/3sidedcube/HybridKit/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245351757,"owners_count":20601090,"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":[],"created_at":"2024-12-02T12:26:02.149Z","updated_at":"2025-10-16T05:36:37.291Z","avatar_url":"https://github.com/3sidedcube.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HybridKit\n\nBridging between UIKit and SwiftUI.\n\nThis package is nothing more than functionality that enables a SwiftUI `View` to interface with its UIKit container view controllers via environment variables. \nThe built-in [UIHostingController](https://developer.apple.com/documentation/swiftui/uihostingcontroller) does the real heavy lifting.  \n\n## Usage\n\nIn order for the environment variables to be set, create the `UIHostingController` using the static `hosted(_:in:)` method\n\n```swift\nlet viewController: UIViewController = .hosted(SomeView())\n```\n\noptionally passing in a navigation controller\n\n```swift\nlet viewController: UIViewController = .hosted(SomeView(), in: navigationController)\n```\n\nIf `SomeView` conforms to `HostedView`, then it then has access to the containing `UIHostingController` and `UINavigationController` via `@Environment` variables.\n\n## Environment Variables\n\nA SwiftUI `View` may conform to `HostedView` in order to interface with its containing `UIHostingController` and `UINavigationController`.\nThese are passed as environment variables when the `UIHostingController` is instantiated.\nWith a reference to these view controllers, the SwiftUI can push, present, and dismiss the containing view controller.\n`SomeView` doesn't have to be a `HostedView` to work. It's only needed when interfacing with UIKit.\n\nFor example:\n\n```swift\nstruct ExampleScreen: HostedView {\n\n    /// Access the the `UIHostingController`\n    @Environment(\\.hostingController) var hostingController\n\n    /// Access the `UINavigationController` of the `UIHostingController`\n    @Environment(\\.navigationController) var navigationController\n\n    ...\n}\n```\n\nAs a result of conforming to `HostedView`, the SwiftUI `View` is able to do stuff like:\n\n```swift\npush(PushedScreen()) // Push on navigation stack\npresent(PresentedScreen()) // Present modal\ndismiss() // Dismiss modal\n```\n\n## Caveats\n\n* Unless the `@Environment` are specified, they default to `nil`. So ensure they are set in order to bridge with UIKit\n* In `HostingController`, the `viewController` property is set *after* instantiating the SwiftUI view.\n\n## Architecture and Data Flow\n\nWhen developing navigation flows, be conscious that the SwiftUI `View`s are instantiated when the hosting `UIHostingController` is instantiated and pushed on the navigation stack. I.e. on a when-needed basis. This is a different way of thinking to pure SwiftUI where `NavigationLink` instantiates views all the way through the flow.\n\n## Example\n\nThere is an example iOS app showing SwiftUI views working alongside a UIKit app in the package directory.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3sidedcube%2Fhybridkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3sidedcube%2Fhybridkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3sidedcube%2Fhybridkit/lists"}