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,9 +3,27 @@ import SFSafeSymbols
struct ContentView: View {
@Environment(\.colorScheme)
var defaultColorScheme: ColorScheme
let info: CVInfo
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 {
VStack(alignment: .leading) {
@ -14,11 +32,20 @@ struct ContentView: View {
Label("Save", systemSymbol: .squareAndArrowUp)
}
.padding()
Toggle("Dark mode", isOn: $darkModeEnabled)
}
ScrollView(.vertical) {
CV(info: info, style: style)
}.frame(width: style.pageWidth)
}
.preferredColorScheme(colorStyle)
.onAppear {
guard !didReadDarkMode else {
return
}
darkModeEnabled = defaultColorScheme == .dark
didReadDarkMode = true
}
}
private func createAndSavePDF() {