Let's assume that default colour system scheme is Light mode.
If I open this app and open settings window then change colour scheme to Dark and then change again to System, the main window get back the Light mode but the settings window remains in Dark mode.
If I change default colour system scheme is Dark mode, then open this app, open settings window then change colour scheme to Light and then change again to System, the main window get back the Dark mode but the settings window remains in Light mode.
What am I doing wrong? Here is simplified code to demo my issue
import SwiftUI
struct ContentView: View {
@State private var isSettingsViewPresented = false
@State private var colorScheme = ColorScheme?.none
var body: some View {
NavigationStack {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.toolbar {
ToolbarItem {
Button {
isSettingsViewPresented.toggle()
} label: {
Label("Settings", systemImage: "gear")
}
}
}
.sheet(isPresented: $isSettingsViewPresented) {
NavigationStack {
Form {
Picker("Colour Scheme", selection: $colorScheme) {
Text("System").tag(ColorScheme?.none)
Text("Light").tag(Optional(ColorScheme.light))
Text("Dark").tag(Optional(ColorScheme.dark))
}
}
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
isSettingsViewPresented.toggle()
}
}
}
}
.preferredColorScheme(colorScheme)
}
}
.preferredColorScheme(colorScheme)
}
}