Created
March 4, 2023 22:53
-
-
Save vladimir-anisimov/b6e4f7298411899297d092f085785acf to your computer and use it in GitHub Desktop.
UIKit + SwiftUIPreview
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
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable { | |
func updateUIViewController(_ uiViewController: ViewController, context: Context) { | |
} | |
let viewController: ViewController | |
init(_ builder: @escaping () -> ViewController) { | |
viewController = builder() | |
} | |
// MARK: - UIViewControllerRepresentable | |
func makeUIViewController(context: Context) -> ViewController { | |
viewController | |
} | |
} | |
struct UIViewPreview<View: UIView>: UIViewRepresentable { | |
let view: View | |
init(_ builder: @escaping () -> View) { | |
view = builder() | |
} | |
// MARK: UIViewRepresentable | |
func makeUIView(context: Context) -> UIView { | |
return view | |
} | |
func updateUIView(_ view: UIView, context: Context) { | |
view.setContentHuggingPriority(.defaultHigh, for: .horizontal) | |
view.setContentHuggingPriority(.defaultHigh, for: .vertical) | |
} | |
} | |
#endif | |
//#if canImport(SwiftUI) && DEBUG | |
//import SwiftUI | |
//struct <#Preview_Class_Name_Here#>_Previews: PreviewProvider { | |
// static var previews: some View { | |
// UIViewPreview { | |
// <#ViewHere#> | |
// } | |
// .edgesIgnoringSafeArea(.all) | |
// } | |
//} | |
//#endif | |
// | |
//#if canImport(SwiftUI) && DEBUG | |
//import SwiftUI | |
//struct <#Preview_Class_Name_Here#>_Previews: PreviewProvider { | |
// static var previews: some View { | |
// UIViewControllerPreview { | |
// <#ViewControllerHere#> | |
// } | |
// .edgesIgnoringSafeArea(.all) | |
// } | |
//} | |
//#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment