diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index fa4b30d8..dc66efc8 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -8,29 +8,6 @@ import Foundation import UIKit -public protocol Colorable { - associatedtype ModelType - func getColor(_ viewModel: ModelType) -> UIColor -} - -extension Colorable { - public func eraseToAnyColorable() -> AnyColorable { - AnyColorable(colorable: self) - } -} - -public struct AnyColorable: Colorable, Withable { - private var wrapped: any Colorable - - public init(colorable: C) where C.ModelType == ModelType { - wrapped = colorable - } - - public func getColor(_ viewModel: ModelType) -> UIColor { - wrapped.getColor(viewModel) - } -} - public protocol BinaryColorable{ var userTrueColor: Bool { get } } diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 285b228d..caf908b0 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -133,7 +133,7 @@ open class BadgeBase: View { return config.getColor(model) } - public func textColorConfiguration(for fillColor: BadgeFillColor) -> AnyColorable { + public func textColorConfiguration(for fillColor: BadgeFillColor) -> AnyColorable { switch fillColor { diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 4951ecdb..12216af7 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -67,7 +67,7 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - public var textColorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration().with { + public var textColorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight $0.disabled.darkColor = VDSColor.elementsSecondaryOndark $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight diff --git a/VDS/Protocols/Colorable.swift b/VDS/Protocols/Colorable.swift new file mode 100644 index 00000000..92a7f461 --- /dev/null +++ b/VDS/Protocols/Colorable.swift @@ -0,0 +1,50 @@ +// +// Colorable.swift +// VDS +// +// Created by Matt Bruce on 10/10/22. +// + +import Foundation +import UIKit + +public protocol Colorable { + associatedtype ModelType + func getColor(_ viewModel: ModelType) -> UIColor +} + +extension Colorable { + fileprivate func getColor(_ viewModel: Any) -> UIColor { + guard let model = viewModel as? ModelType else { + assertionFailure("Invalid ModelType, Expecting type \(ModelType.self), received \(viewModel) ") + return .black + } + return getColor(model) + } + + public func eraseToAnyColorable() -> AnyColorable { AnyColorable(self) } +} + +public struct GenericColorable: Colorable, Withable { + private var wrapped: any Colorable + + public init(colorable: C) where C.ModelType == ModelType { + wrapped = colorable + } + + public func getColor(_ viewModel: ModelType) -> UIColor { + wrapped.getColor(viewModel) + } +} + +public struct AnyColorable: Colorable, Withable { + private let wrapped: any Colorable + + public init(_ colorable: any Colorable) { + wrapped = colorable + } + + public func getColor(_ viewModel: Any) -> UIColor { + wrapped.getColor(viewModel) + } +}