JAHelia
JAHelia

Reputation: 7932

Wrong accent color is used when forcing a color scheme on the app and using .task modifier

I have an app that has the AccentColor set in the Assets Catalog using two colors for light and dark modes, when I force using the light color scheme in my app using: the .preferredColorScheme(.light) modifier on the root ContentView, I notice that the app uses the dark accent color when the following both conditions are met:

  1. the iOS appearance setting is set to dark.
  2. using .task modifier on the root ContentView (with or without code inside the task closure).

The same happens vice versa: i.e. the app uses the light accent color when the iOS’s Appearance setting is light and the .task modifier is used at the root ContentView.

The app is as simple as the following two code snippets:

@main
struct TestAccentColorApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .preferredColorScheme(.dark)
                
                
        }
    }
}
struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
            
            Button("test") {
                
            }
        }
        .padding()
        
        .task { //<------ when removing this modifier, the app will use the correct accent color that matches the .preferredColorScheme's value
            
        }
    }
}

And the AccentColor is set as follows:

enter image description here

Note1: when I use the app switcher or set the app in background, the app refreshes the view to use the correct accent color that matches the .preferredColorScheme's value.

Note2: The issue happens on XCode 15.3 and iOS 17.4's device (i don't test on simulators).

Any thoughts are appreciated.

Upvotes: 0

Views: 50

Answers (0)

Related Questions