Created
August 21, 2020 09:48
-
-
Save amirdew/99aea5a44ff939396c7a5fcd90e22d42 to your computer and use it in GitHub Desktop.
An extention for making previews easier
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
// How to use: | |
struct YourView_Previews: PreviewProvider { | |
static var previews: some View { | |
YourView() | |
.makePreviews() | |
} | |
} | |
// Extensions: | |
extension View { | |
func makePreviews() -> some View { | |
Group { | |
ForEach(PreviewDevice.configs, id: \.name) { | |
previewDevice($0.device) | |
.previewDisplayName($0.name) | |
.environment(\.colorScheme, $0.colorScheme) | |
} | |
} | |
} | |
} | |
extension PreviewDevice { | |
static var configs: [(device: PreviewDevice, name: String, colorScheme: ColorScheme)] { | |
[ | |
(PreviewDevice(rawValue: "iPhone 11 Pro"), "11 Pro", .dark), | |
(PreviewDevice(rawValue: "iPhone 11 Pro Max"), "11 Pro Max", .light), | |
(PreviewDevice(rawValue: "iPhone SE (2nd generation)"), "SE 2nd", .dark), | |
(PreviewDevice(rawValue: "iPod touch (7th generation)"), "iPod", .light) | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment