Really Basic Dark Mode implementation question

Let's say I create a "SwiftUI View" file called "Test"


Then let's modify the PreviewProvider section to look like this:

#if DEBUG
struct Test_Previews : PreviewProvider {
    static var previews: some View {
        Group {
            Test()
            Test()
                .environment(\.colorScheme, .dark)
        }
    }
}
#endif


Now when I look at my preview, I notice that the Text color is different for the Light and the Dark mode, but the background color does not change by default. So the text on the Dark Mode Version will not show up since it is white on white.


If I take my main section of code and then wrap the Text view in a List View like this:

struct Test : View {
    var body: some View {
        List(/0 ..< 5/) { item in
            Text(/"Hello World!")
        }
    }
}


then it handles changing the background color of the list to be black in dark mode so the white text shows up properly.


My question is: Do we have to check manually to see if the mode is Light or Dark to change the Background color in code? Or is there a native container view to wrap the Text in this case inside that will handle changing the background color without having to put it in a List View?


Thanks,

Dave

I found some really helpful info on Stack Overflow about this issue if anyone else is struggling with it:

https://stackoverflow.com/questions/56591669/not-able-to-achieve-dark-mode-using-swiftui


Looks like it may be a bug and if you implement the workaround that is suggested by Guy Booker, it will help you emulate dark mode simply until it is fixed in XCode

This now seems to be fixed with XCode Beta 7 and Catalina Beta 7

Really Basic Dark Mode implementation question
 
 
Q