Created
June 21, 2024 14:22
-
-
Save juliensagot/885e31ff15e805b1904cacda67523a7f to your computer and use it in GitHub Desktop.
The missing UIHostingView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
public final class HostingView: UIView { | |
public init(@ViewBuilder content: () -> some View) { | |
super.init(frame: .zero) | |
let contentView = UIHostingConfiguration(content: content) | |
.margins(.all, 0) | |
.makeContentView() | |
contentView.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(contentView) | |
NSLayoutConstraint.activate([ | |
contentView.topAnchor.constraint(equalTo: topAnchor), | |
contentView.leadingAnchor.constraint(equalTo: leadingAnchor), | |
contentView.trailingAnchor.constraint(equalTo: trailingAnchor), | |
contentView.bottomAnchor.constraint(equalTo: bottomAnchor) | |
]) | |
} | |
@available(*, unavailable) | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
π π π π π π