rizwankce / SwiftUIColorSchemeTest

Test project for SwiftUI's preferredColorScheme modifier
MIT License
11 stars 1 forks source link

Use .unspecified to support automatic #4

Open wyhaya opened 2 years ago

wyhaya commented 2 years ago

Hi, I read your article, I am a swift newbie and I don't know if this is valuable, but it works well

@main
struct YourApp: App {
    @AppStorage(appearanceName) var appearance = Appearance.system
    var body: some Scene {
        WindowGroup {
            ContentView()
                .preferredColorScheme(
                    appearance == Appearance.dark ? .dark
                        : appearance == Appearance.light ? .light
                        : .init(UIUserInterfaceStyle.unspecified)
                )
        }
    }
}
@AppStorage(appearanceName) var appearance = Appearance.system
Picker("Appearance", selection: $appearance) {
    Text("System").tag(Appearance.system)
    Text("Light").tag(Appearance.light)
    Text("Dark").tag(Appearance.dark)
}
rizwankce commented 2 years ago

Thanks for taking time to comment. I'll check and update the repo with latest details.