Last active
April 4, 2025 11:17
-
-
Save sergeyshalnov/4c150c4f97cb898a04f826b041c32b13 to your computer and use it in GitHub Desktop.
UIView preview snippet
This file contains hidden or 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 DEBUG | |
import UIKit | |
import SwiftUI | |
// MARK: - Preview Struct | |
@available(iOS 13, *) | |
extension UIView { | |
private struct Preview<V: UIView>: UIViewRepresentable { | |
// MARK: - Properties | |
let view: V | |
// MARK: - Methods | |
func makeUIView(context: UIViewRepresentableContext<Preview<V>>) -> V { | |
return view | |
} | |
func updateUIView(_ uiView: V, context: UIViewRepresentableContext<Preview<V>>) { } | |
} | |
} | |
// MARK: - Preview Property | |
@available(iOS 13, *) | |
extension UIView { | |
var preview: some View { | |
Preview(view: self) | |
} | |
} | |
#endif |
This file contains hidden or 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 DEBUG | |
import SwiftUI | |
@available(iOS 13, *) | |
struct Preview: PreviewProvider { | |
static var previews: some View { | |
return UIView().preview | |
.edgesIgnoringSafeArea(.all) | |
.previewLayout(.fixed(width: 320, height: 400)) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment