-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathRepresentableViewController.swift
More file actions
43 lines (32 loc) · 1.01 KB
/
RepresentableViewController.swift
File metadata and controls
43 lines (32 loc) · 1.01 KB
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
import Foundation
import SwiftUI
/**
Helper used to render UIViewController inside of SwiftUI.
This solves issues in some cases that can't found root UINavigationController.
*/
struct RepresentableViewController: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
var view: PlatformView
#if os(macOS)
func makeNSView(context: Context) -> PlatformView {
let wrapper = NSView()
wrapper.addSubview(view)
return wrapper
}
func updateNSView(_ nsView: PlatformView, context: Context) {}
#else
func makeUIView(context: Context) -> PlatformView {
let wrapper = UIView()
wrapper.addSubview(view)
return wrapper
}
func makeUIViewController(context: Context) -> UIViewController {
let contentVC = UIViewController()
contentVC.view.backgroundColor = .clear
contentVC.view.addSubview(view)
return contentVC
}
func updateUIView(_ uiView: PlatformView, context: Context) {}
#endif
}