forked from siteline/swiftui-introspect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatformView.swift
58 lines (52 loc) · 2.09 KB
/
PlatformView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#if !os(watchOS)
import SwiftUI
#if canImport(UIKit)
public typealias PlatformView = UIView
#elseif canImport(AppKit)
public typealias PlatformView = NSView
#endif
#if canImport(UIKit)
public typealias PlatformViewController = UIViewController
#elseif canImport(AppKit)
public typealias PlatformViewController = NSViewController
#endif
#if canImport(UIKit)
typealias _PlatformViewControllerRepresentable = UIViewControllerRepresentable
#elseif canImport(AppKit)
typealias _PlatformViewControllerRepresentable = NSViewControllerRepresentable
#endif
@MainActor
protocol PlatformViewControllerRepresentable: _PlatformViewControllerRepresentable {
#if canImport(UIKit)
typealias ViewController = UIViewControllerType
#elseif canImport(AppKit)
typealias ViewController = NSViewControllerType
#endif
func makePlatformViewController(context: Context) -> ViewController
func updatePlatformViewController(_ controller: ViewController, context: Context)
static func dismantlePlatformViewController(_ controller: ViewController, coordinator: Coordinator)
}
extension PlatformViewControllerRepresentable {
#if canImport(UIKit)
func makeUIViewController(context: Context) -> ViewController {
makePlatformViewController(context: context)
}
func updateUIViewController(_ controller: ViewController, context: Context) {
updatePlatformViewController(controller, context: context)
}
static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) {
dismantlePlatformViewController(controller, coordinator: coordinator)
}
#elseif canImport(AppKit)
func makeNSViewController(context: Context) -> ViewController {
makePlatformViewController(context: context)
}
func updateNSViewController(_ controller: ViewController, context: Context) {
updatePlatformViewController(controller, context: context)
}
static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) {
dismantlePlatformViewController(controller, coordinator: coordinator)
}
#endif
}
#endif