UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Colour issue for confirmationDialog on physical iPads in dark mode

Forums > SwiftUI

Displaying a confirmationDialog in dark mode in an iPad simulator displays the dialog correctly using the system dark mode colours:

alert-simulator

However, the same comfirmationDialog in dark mode on a physical device displays incorrectly using colours that make it difficult to read the title text (the image below actually makes the text clearer than it is on the device):

alert-ipad

The iPad is running iPadOS 17.1.1 and the simulator is iOS 17.0.

The confirmationDialog is displayed correctly in light mode on both the simulator and real device.

The code to display the test confirmationDialog is:

struct ContentView: View {
    @State private var isShowingDialog = false
    var body: some View {
        Button("Empty Trash") {
            isShowingDialog = true
        }
        .confirmationDialog(
            "Permanently erase the items in the Trash?",
            isPresented: $isShowingDialog,
            titleVisibility: .visible
        ) {
            Button("Empty Trash", role: .destructive) {
                // Handle empty trash action.
            }
        }
        .buttonStyle(.borderedProminent)
    }
}

Anyone have any ideas how I can work around this? I've tried using tint(color) in varous places to no effect. I really don't want to have to hand craft a confirmation dialog just for dark mode on the iPad.

Thanks.

Gavin

3      

The inconsistency in dark mode display might stem from system versions or rendering variations. Consider reporting it as a bug to Apple. For a temporary fix, explore customizing dialog styles or adjusting contrast to enhance readability for iPad dark mode. It seems like the issue might be related to the system-level settings or possibly a bug specific to iPadOS 17.1.1. To address this, try using custom styling with SwiftUI's .preferredColorScheme modifier to enforce dark mode styling explicitly for the dialog on the physical device. Alternatively, consider reporting the discrepancy to Apple for a potential system fix.

3      

I was experiencing the same problem in 17.1.2. Updating to 17.2 fixed it.

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.