Skip to content

Add themeOverride view modifier #11

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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