import SwiftUI import WidgetKit struct WidgetCustomColorSchemeViewModifier: ViewModifier { // As we're not changing the preferred color scheme we can trust this to always be the system value @Environment(\.colorScheme) var colorScheme let customColorScheme: CustomColorScheme init(_ customColorScheme: CustomColorScheme) { self.customColorScheme = customColorScheme } func body(content: Content) -> some View { content // .preferredColorScheme doesn't work on widgets .colorScheme(customColorScheme.colorScheme ?? colorScheme) } } extension View { func widgetCustomColorScheme(_ customColorScheme: CustomColorScheme) -> some View { self.modifier(WidgetCustomColorSchemeViewModifier(customColorScheme)) } }