Slather logo

Coverage for "UIHostingControllerWithContextFactory.swift" : 100.00%

(5 of 5 relevant lines covered)

RouteComposer/Classes/Factories/SwiftUI/UIHostingControllerWithContextFactory.swift

1
//
2
// RouteComposer
3
// UIHostingControllerWithContextFactory.swift
4
// https://github.com/ekazaev/route-composer
5
//
6
// Created by Eugene Kazaev in 2018-2022.
7
// Distributed under the MIT license.
8
//
9
// Become a sponsor:
10
// https://github.com/sponsors/ekazaev
11
//
12
13
#if canImport(SwiftUI)
14
15
import Foundation
16
import SwiftUI
17
import UIKit
18
19
/// Builds `UIHostingController` with `ContentView` as a `UIHostingController.rootView` using the constructor
20
/// provided with `ContextInstantiatable` implementation.
21
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
22
public struct UIHostingControllerWithContextFactory<ContentView: View & ContextInstantiatable>: Factory {
23
24
    // MARK: Associated types
25
26
    public typealias ViewController = UIHostingController<ContentView>
27
28
    public typealias Context = ContentView.Context
29
30
    // MARK: Methods
31
32
    /// Constructor
33
    public init() {}
1x
34
35
    public func build(with context: Context) throws -> UIHostingController<ContentView> {
1x
36
        let viewController = UIHostingController(rootView: ContentView(with: context))
1x
37
        return viewController
1x
38
    }
1x
39
40
}
41
42
#endif