Swift UI safe area stays white in dark mode

As shown from the pictures below, using a navigationView in darkmode causes the safe areas of the screen to turn white. Is there a modifier that can help me fix this?

Here’s the code:

import SwiftUI
import SwiftData

struct ContentView: View {
    @State var showTab = false
    
    var body: some View {
        NavigationView{
            Button {
                showTab = true
            } label: {
                Text("open tab")
            }
        }
        .sheet(isPresented: $showTab){
            SettingsView()
        }
    }
}

struct SettingsView: View {
    var body: some View{
        Text("hello")
    }
}


#Preview {
    ContentView()
        .modelContainer(for: Item.self, inMemory: true)
}


Above the tab sheet, you can see the white "safe area" which is not supposed to be there

  • It seemed only preview effect. In simulator tested it is fine. Change NavigationView to NaviagtionStack

    – 




I believe this is a visual bug in the Xcode Preview. Have you tried running your project on the iOS Simulator instead?

Preview

Simulator

Leave a Comment