ThemeManager
public final class ThemeManager : ObservableObject, Identifiable
Implements ObservableObject, Identifiable protocols. Manages available theme and current active one.
Singleton class, call ThemeManager.shared
to retrieve it.
You can set the active theme by calling ThemeManager.shared.setCurrentTheme(CAITheme)
-
Returns the current active CAITheme
Declaration
Swift
public private(set) var theme: CAITheme { get }
-
Singleton instance
Declaration
Swift
public static let shared: ThemeManager
-
Set active theme. Triggers UI Binding.
Declaration
Swift
public func setCurrentTheme(_ theme: CAITheme)
Parameters
theme
CAITheme
-
Binds this method in your SwiftUI Views to get the color for the current theme
Declaration
Swift
public func color(for key: Theme.Color.Key) -> Color
Parameters
key
Theme.Key
Return Value
Color
-
Binds this method in your SwiftUI Views to get the value for the current theme
Declaration
Swift
public func value(for key: Theme.Key) -> Any?
Parameters
key
Theme.Key
Return Value
Any. Nil if key is not found
-
Binds this method in your SwiftUI Views to get the value for the current theme
Declaration
Swift
public func value<T>(for key: Theme.Key, type: T.Type, defaultValue: T) -> T
Parameters
key
Theme.Key
Type
Expected Type T that this value should be
defaultValue
Default value to return if key does not exist OR is of wrong type
Return Value
Value of type T
-
Binds this method in your SwiftUI Views to get the value for the current theme
Declaration
Swift
public func value<T>(for key: Theme.Key, type: T.Type) -> T?
Parameters
key
Theme.Key
Type
Expected Type T that this value should be
Return Value
Value of type T?