Skip to content

Add themeOverride view modifier #11

@rozd

Description

@rozd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions