Skip to content

heckj/PreviewBackground

Repository files navigation

PreviewBackground

Actions Status swift-5.1 swiftpm @heckj codecov

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

Build and test

git clone https://github.com/heckj/PreviewBackground
cd PreviewBackground
swift test -v
swiftformat --lint . && swiftlint