Add dark mode switch

This commit is contained in:
Christoph Hagen 2023-08-18 22:56:11 +02:00
parent bd87a4fb6f
commit 55de8ada91

View File

@ -3,10 +3,28 @@ import SFSafeSymbols
struct ContentView: View { struct ContentView: View {
@Environment(\.colorScheme)
var defaultColorScheme: ColorScheme
let info: CVInfo let info: CVInfo
let style: CVStyle let style: CVStyle
init(info: CVInfo, style: CVStyle) {
self.info = info
self.style = style
}
@State
var darkModeEnabled = true
@State
var didReadDarkMode = false
var colorStyle: ColorScheme {
darkModeEnabled ? .dark : .light
}
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
HStack { HStack {
@ -14,11 +32,20 @@ struct ContentView: View {
Label("Save", systemSymbol: .squareAndArrowUp) Label("Save", systemSymbol: .squareAndArrowUp)
} }
.padding() .padding()
Toggle("Dark mode", isOn: $darkModeEnabled)
} }
ScrollView(.vertical) { ScrollView(.vertical) {
CV(info: info, style: style) CV(info: info, style: style)
}.frame(width: style.pageWidth) }.frame(width: style.pageWidth)
} }
.preferredColorScheme(colorStyle)
.onAppear {
guard !didReadDarkMode else {
return
}
darkModeEnabled = defaultColorScheme == .dark
didReadDarkMode = true
}
} }
private func createAndSavePDF() { private func createAndSavePDF() {