ColorScheme

The possible color schemes, corresponding to the light and dark appearances.

EnumerationiOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+ColorScheme in SwiftUI

Declaration

React
type ColorScheme = 'dark' | 'light';
Swift
enum ColorScheme

Pass a literal, or build one with SwiftUI.ColorScheme from import { SwiftUI } from 'swiftui-react-native'.

Type properties

Overview

You receive a color scheme value when you read the EnvironmentValues.colorScheme environment value. The value tells you if a light or dark appearance currently applies to the view. SwiftUI updates the value whenever the appearance changes, and redraws views that depend on the value. For example, the following Text view automatically updates when the user enables Dark Mode:

@Environment(\.colorScheme) private var colorScheme

var body: some View {
    Text(colorScheme == .dark ? "Dark" : "Light")
}

Set a preferred appearance for a particular view hierarchy to override the user's Dark Mode setting using the View.preferredColorScheme(_:) view modifier.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Appearance.