`Text` (Label) text color issue during app resuming from suspended (changes from black to light or vice versa, depending on current appearance mode).

Its important to note that this same app did not have this issue in iOS 17.

Ever since iOS 18 I have noticed that when application written in SwiftUI uses Label with the default color (which auto changes between light and dark appearance), from time to time when resuming an application that has been in the background, the color of those labels (only the Label elements) switches from the opposite to the correct one. Here is an example:

Steps to reproduce

  • Phone is in dark appearance
  • Open app
  • Labels text color is white and labels background is black
  • Go to home so that app is on background
  • Wait random time (does not happen all the time), some times 1 min some times 10
  • Reopen the application.
  • During the opening transition the Label text color was changed while the app was in suspended mode to the light appearance variant (black)
  • Once the app opening transition finishes the Label text color switches back to the correct color for dark appearance (white)

Same issue happens if you start from light appearance. I cannot reproduce this on Xcode simulators, I have tried to force memory warning to check if that has anything to do with it but that also does not cause the issue to appear on simulators. For now I can only reproduce this on real device.

Screenshots

Here is screenshots of the above example:

During transition

After transition

Could you post the full code of the view ?

@Claude31 , Yes of course but it is pure SwiftUI from template.

struct ContentView: View {
    private var tabSelection: Binding<String> { Binding(
        get: { selectedTab },
        set: { selectedTab = $0 }
    )}
    @State private var selectedTab: String = "Test"
    
    var body: some View {
        TabView(selection: tabSelection,
                content: {
            NavigationStack {
                List {
                    ForEach(0...1000, id: \.self) { index in
                        Text("Test 1 - Row: \(index)")
                    }
                }
                .navigationTitle("Test 1")
            }
            .listStyle(.insetGrouped)
            .tabItem {
                Image(systemName: "sun")
                Text("Test")
            }
            .tag("Test")
        })
        .tabViewStyle(.sidebarAdaptable)
    }
}

@Claude31 Some more info on this.

I think it happens during "CoreData" processing (insert/deleted + save) while the application is not active (in the background)

Example 1:

If I process userNotificationCenter(_:didReceive:withCompletionHandler:) and interact with CoreData's manage view context to insert a new object.

Example 2:

Processing HealthKit APIs to once again interact with CoreData's view context. For example observing a long running HKAnchoredObjectQuery.

I can confirm that the issue I am describing happens 100% both on device and simulator in this scenario:

Prerequisites: Phone/simulator is in light appearance (also happens in reverse when in dark mode)

  1. Application written in SwiftUI
  2. Uses CoreData to store entities
  3. Application adds UNNotificationRequest with action to insert entity in CoreData to UNUserNotificationCenter via UNUserNotificationCenter.add(_:withCompletionHandler:)
  4. Application is opened
  5. Go to Home Screen and make application non active (do not force close)
  6. Receive notification
  7. Trigger the notification action without opening the app (hold the notification and tap the action button)
  8. In the code the userNotificationCenter(_:didReceive:) handled it and inserts new entity in CoreData.
  9. Open app switcher

10 Application's labels' text color is switched to white (it was black in light appearance before CoreData interaction) 11. Resume application by opening it, label's text color switches back to white

Here is a video of this scenario

Created a sample project that reproduces the issue, it ca nee found here: https://github.com/VladimirAmiorkov/SwiftUI-Label-text-color-issue

Opened a feedback issue report with ID: FB16412433

&#96;Text&#96; (Label) text color issue during app resuming from suspended (changes from black to light or vice versa, depending on current appearance mode).
 
 
Q