A demo of the preferredColorScheme modifier in SwiftUI multiplatform apps that demonstrates a couple of bugs:
On macOS 11β4, setting the preferredColorScheme
modifier on a view to .light
does not override the system’s colour scheme. This behaviour is expected if preferredColorScheme
is .none
; otherwise the app should remain in light mode regardless of the system scheme. Note that preferredColorScheme
is respected when set to .dark
instead.
- If necessary, set your Mac running Big Sur β4 to light mode
- Open the attached SwiftUI multiplatform sample project
- Build and run the macOS app
- Choose the “Light” option in the segmented control
- Change the system’s colour scheme to dark
The app continues to be presented in its light colour scheme.
The app switches to match the system’s colour scheme.
FB8383053 - "On iOS 14β4/macOS 11β4, it is not possible to unset preferredColorScheme after setting it to either .light or .dark"
In iOS 14β4/macOS 11β4, if a view’s preferredColorScheme
is initially nil
, the view will respect the system scheme setting. After setting the preferredColorScheme
modifier on the view to either .light
or .dark
, it is no longer possible to revert back to having the app respect the system scheme setting.
- Open the attached SwiftUI multiplatform sample project
- Build and run the iOS or macOS app
- Observe that the default “System” option sets the app’s color scheme based on the system setting
- Choose either the “Light” or “Dark” option in the segmented control, and observe that the app’s color scheme changes to that selection
- Choose the “System” option again and test changing the system’s scheme setting
The app’s color scheme follows the system’s scheme setting.
The app’s color scheme remains “stuck” on whatever the last preferredColorScheme setting was.