Override a whole theme
Assuming part of view tree requires look that different it from rest of the app:
PartnerView()
.themeOverride(Theme.partner)
Implementation is simple and straightforward:
extension View {
public func themeOverride(_ theme: Theme, animation: Animation? = nil) -> some View {
environment(\.theme, theme)
}
}
Override a part of theme
When a view need several different styles, could be more valid use case:
PromoView()
.themeOverride(\.colors.primaryColor, .init(light: .orange, dark: .yellow))
or
PromoView()
.themeOverride(primaryColor: .init(light: .orange, dark: .yellow))
Implementation is complex, it would require either to convert let to var or generating an enormous number of methods – one for every style.
Override a whole theme
Assuming part of view tree requires look that different it from rest of the app:
Implementation is simple and straightforward:
Override a part of theme
When a view need several different styles, could be more valid use case:
or
Implementation is complex, it would require either to convert
lettovaror generating an enormous number of methods – one for every style.