ThemeManager

public class ThemeManager

Manager class which supplies color palette values to Fiori components, and the Color.preferredColor(_:background:interface:display:) API.

Changes made to the manager affect all future calls to Color.preferredColor(_:background:interface:display:). Most components do not reload dynamically, so calls to the ThemeManager should happen at the beginning of the application lifecycle.

Note

AppDelegate.didFinishLaunching(withOptions...) is the recommended location.

Example Usage

// Pin palette version used by application to a specific version (defaults to `.latest`)
ThemeManager.shared.setPaletteVersion(.v7)

// Override some color definitions to match your application palette
ThemeManager.shared.setColor(.darkGray, for: .primary2, background: .light)
ThemeManager.shared.setHexColor("1b931d", for: .positive, background: .light)
  • Singleton instance shared by all application components.

    Declaration

    Swift

    public static let shared: ThemeManager
  • Method to allow selecting a specific version of the palette. Defaults to latest.

    Declaration

    Swift

    public func setPaletteVersion(_ version: PaletteVersion)

    Parameters

    version

    Major version of the color palette.

  • Method to allow supplying a complete custom palette implementation.

    Note

    It is more typical to use setColor(...), or setHexColor(...) to override specific palette values than to provide a full implementation.

    Declaration

    Swift

    public func setPalette(_ palette: Palette)

    Parameters

    palette

    Complete palette implementation. Should include definitions for all consumed ColorStyle types.

  • Accessor to current palette.

    Note

    It is unusual to need to read from the palette directly; generally, use the Color.preferredColor(...) API.

    Declaration

    Swift

    public private(set) var palette: Palette { get set }
  • Method to supply a custom definition for a particular ColorStyle. Will be applied to .light background color scheme.

    Declaration

    Swift

    public func setColor(_ color: Color, for style: ColorStyle)

    Parameters

    color

    Color definition to override the base definition in the palette.

    style

    Reference of ColorStyle to which color is bound.

  • Method to supply a custom definition for a particular ColorStyle and ColorVariant combination.

    Note

    A nil value for background will default to .light.

    Declaration

    Swift

    public func setColor(_ color: Color, for style: ColorStyle, variant: ColorVariant?)

    Parameters

    color

    Color definition to override the base definition in the palette.

    style

    Reference of ColorStyle to which color is bound.

    variant

    Reference of ColorVariant to which color is bound. Defaults to .light. If no value is supplied for .dark, the value for .light will be read as a fallback.

  • Method to supply a custom definition for a particular ColorStyle. Will applied to .light background color scheme.

    Declaration

    Swift

    public func setHexColor(_ hex: String, for style: ColorStyle)

    Parameters

    hex

    Color definition as hexadecimal string to override the base definition in the palette.

    style

    Reference of ColorStyle to which color is bound.

  • Method to supply a custom definition for a particular ColorStyle and ColorVariant combination.

    Declaration

    Swift

    public func setHexColor(_ hex: String, for style: ColorStyle, variant: ColorVariant)

    Parameters

    hex

    Color definition as hexadecimal string to override the base definition in the palette.

    style

    Reference of ColorStyle to which color is bound.

    variant

    Reference of ColorVariant to which color is bound. Defaults to .light. If no value is supplied for .dark, the value for .light will be read as a fallback.

  • Helper method, to clear any override colors set via setColor(...) or setHexColor(...). Does not affect the base definition of the current palette.

    Declaration

    Swift

    public func reset()