1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// ContextInstantiatable.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 |
/// `View` instance should conform to this protocol to be used with `UIHostingControllerWithContextFactory`
|
|
20 |
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
|
21 |
public protocol ContextInstantiatable where Self: View {
|
|
22 |
|
|
23 |
/// Type of `Context` object that `View` can be initialised with
|
|
24 |
associatedtype Context
|
|
25 |
|
|
26 |
/// Constructor
|
|
27 |
init(with context: Context)
|
|
28 |
|
|
29 |
}
|
|
30 |
|
|
31 |
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
|
32 |
public extension ContextInstantiatable where Context == Void {
|
|
33 |
|
|
34 |
/// Constructor
|
|
35 |
init() {
|
1x |
36 |
self.init(with: ())
|
1x |
37 |
}
|
1x |
38 |
|
|
39 |
}
|
|
40 |
|
|
41 |
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
|
|
42 |
public extension ContextInstantiatable where Context == Any? {
|
|
43 |
|
|
44 |
/// Constructor
|
|
45 |
init() {
|
1x |
46 |
self.init(with: nil)
|
1x |
47 |
}
|
1x |
48 |
|
|
49 |
}
|
|
50 |
|
|
51 |
#endif
|
|