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
versionMajor version of the color palette.
-
Method to allow supplying a complete custom palette implementation.
Note
It is more typical to use
setColor(...), orsetHexColor(...)to override specific palette values than to provide a full implementation.Declaration
Swift
public func setPalette(_ palette: Palette)Parameters
paletteComplete palette implementation. Should include definitions for all consumed
ColorStyletypes. -
Accessor to current palette.
Note
It is unusual to need to read from the palette directly; generally, use theColor.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.lightbackground color scheme.Declaration
Swift
public func setColor(_ color: Color, for style: ColorStyle)Parameters
colorColor definition to override the base definition in the palette.
styleReference of
ColorStyleto which color is bound. -
Method to supply a custom definition for a particular
ColorStyleandColorVariantcombination.Note
A
nilvalue forbackgroundwill default to.light.Declaration
Swift
public func setColor(_ color: Color, for style: ColorStyle, variant: ColorVariant?)Parameters
colorColor definition to override the base definition in the palette.
styleReference of
ColorStyleto which color is bound.variantReference of
ColorVariantto which color is bound. Defaults to.light. If no value is supplied for.dark, the value for.lightwill be read as a fallback. -
Method to supply a custom definition for a particular
ColorStyle. Will applied to.lightbackground color scheme.Declaration
Swift
public func setHexColor(_ hex: String, for style: ColorStyle)Parameters
hexColor definition as hexadecimal string to override the base definition in the palette.
styleReference of
ColorStyleto which color is bound. -
Method to supply a custom definition for a particular
ColorStyleandColorVariantcombination.Declaration
Swift
public func setHexColor(_ hex: String, for style: ColorStyle, variant: ColorVariant)Parameters
hexColor definition as hexadecimal string to override the base definition in the palette.
styleReference of
ColorStyleto which color is bound.variantReference of
ColorVariantto which color is bound. Defaults to.light. If no value is supplied for.dark, the value for.lightwill be read as a fallback. -
Helper method, to clear any override colors set via
setColor(...)orsetHexColor(...). Does not affect the base definition of the current palette.Declaration
Swift
public func reset()