Created
October 2, 2020 05:39
-
-
Save prafullakumar/639e8752e7bd27f70ad0222b4f1f7c65 to your computer and use it in GitHub Desktop.
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
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