SwiftUI component that provides a flat background color for Preview based on the environment setting.
This allows it to be used to provide background shadings appropriate to the mode, regardless of device:
#if DEBUG
struct PreviewBackground_Previews: PreviewProvider {
static var previews: some View {
Group {
ForEach(ColorScheme.allCases, id: \.self) { colorScheme in
PreviewBackground(content: {
Text("hi")
})
.environment(\.colorScheme, colorScheme)
.frame(width: 100, height: 100, alignment: .center)
.previewDisplayName("\(colorScheme)")
}
}
}
}
#endif
git clone https://github.com/heckj/PreviewBackground
cd PreviewBackground
swift test -v
swiftformat --lint . && swiftlint