Created
March 5, 2022 08:05
-
-
Save TheWorstProgrammerEver/bd8402ba726312f1582694519257d9a1 to your computer and use it in GitHub Desktop.
SwiftUI StandardPreviews - reusable previews with dark- and light-mode, large- and small-text (Dynamic Type) variations.
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 StandardPreviews<Content: View> : View { | |
var light: Bool = true | |
var dark: Bool = true | |
var large: Bool = true | |
var small: Bool = true | |
var content: () -> Content | |
var body: some View { | |
Group { | |
if light { | |
content() | |
.environment(\.colorScheme, .light) | |
} | |
if dark { | |
content() | |
.environment(\.colorScheme, .dark) | |
} | |
if large { | |
content() | |
.environment(\.sizeCategory, .accessibilityExtraLarge) | |
} | |
if small { | |
content() | |
.environment(\.sizeCategory, .extraSmall) | |
} | |
} | |
} | |
} | |
struct StandardPreviews_Previews : PreviewProvider { | |
static var previews: some View { | |
StandardPreviews { | |
NavigationView { | |
Text("Hello") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment