Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created October 2, 2020 05:39
Show Gist options
  • Save prafullakumar/639e8752e7bd27f70ad0222b4f1f7c65 to your computer and use it in GitHub Desktop.
Save prafullakumar/639e8752e7bd27f70ad0222b4f1f7c65 to your computer and use it in GitHub Desktop.
import SwiftUI
struct PreviewsDemo: View {
var body: some View {
ZStack {
Color(UIColor.systemBackground)
Text("Hello, World!")
}.ignoresSafeArea()
}
}
struct PreviewsDemo_Previews: PreviewProvider {
static var previews: some View {
LightAndDark {
Landscape {
PreviewsDemo()
}
}
}
}
#if DEBUG
struct LightAndDark<Content>: View where Content: View {
let content: () -> Content
var body: some View {
ForEach(ColorScheme.allCases, id: \.self) { colorScheme in
content().environment(\.colorScheme, colorScheme).previewDisplayName("\(colorScheme)")
}
}
}
struct Landscape<Content>: View where Content: View {
let content: () -> Content
let height = UIScreen.main.bounds.width //toggle width height
let width = UIScreen.main.bounds.height
var body: some View {
content().previewLayout(PreviewLayout.fixed(width: width, height: height))
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment