// // UIHostingView.swift // PayCash // // Created by Saveliy Stavitsky on 2/1/22. // Copyright © 2022 AM. All rights reserved. // import Foundation import SwiftUI #if os(macOS) public typealias PlatformViewType = NSView #elseif !os(watchOS) import UIKit public typealias PlatformViewType = UIView #endif #if !os(watchOS) @available(iOS 13.0, macOS 10.15, tvOS 13.0, *) open class UIHostingView : PlatformViewType where Content : View { #if os(macOS) typealias HostingController = NSHostingController #else typealias HostingController = UIHostingController #endif private let hostingVC: HostingController public var rootView: Content { get { return hostingVC.rootView } set { hostingVC.rootView = newValue } } public init(rootView: Content, frame: CGRect = .zero, backgroundColor: UIColor = .clear) { self.hostingVC = HostingController(rootView: rootView) super.init(frame: frame) self.backgroundColor = backgroundColor addSubview(hostingVC.view) hostingVC.view.translatesAutoresizingMaskIntoConstraints = false hostingVC.view.backgroundColor = backgroundColor NSLayoutConstraint.activate([ hostingVC.view.topAnchor.constraint(equalTo: self.topAnchor), hostingVC.view.bottomAnchor.constraint(equalTo: self.bottomAnchor), hostingVC.view.leadingAnchor.constraint(equalTo: self.leadingAnchor), hostingVC.view.trailingAnchor.constraint(equalTo: self.trailingAnchor) ]) } @available(*, unavailable) required public init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } var sizeThatFits: CGSize { hostingVC.view.sizeThatFits(UIScreen.main.bounds.size) } } #endif