diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 831d9704..cad4fd18 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -13,6 +13,18 @@ public protocol Colorable: AnyObject, ObjectWithable { func getColor(_ viewModel: ModelType) -> UIColor } +public class AnyColorable: Colorable { + + private var wrapper: (ModelType) -> UIColor + + public init(colorable: C) where C.ModelType == ModelType { + wrapper = colorable.getColor(_:) + } + public func getColor(_ viewModel: ModelType) -> UIColor { + wrapper(viewModel) + } +} + public protocol BinaryColorable{ var userTrueColor: Bool { get } } @@ -142,15 +154,3 @@ open class BinaryDisabledSurfaceColorConfiguration: Colorable { - - private var colorHelper: (ModelType) -> UIColor - - public init(colorable: C) where C.ModelType == ModelType { - colorHelper = colorable.getColor(_:) - } - public func getColor(_ viewModel: ModelType) -> UIColor { - colorHelper(viewModel) - } -} diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 69d41b6a..ed724abe 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -133,31 +133,31 @@ open class BadgeBase: View { return config.getColor(model) } - public func textColorConfiguration(for fillColor: BadgeFillColor) -> DisabledSurfaceColorConfiguration { + public func textColorConfiguration(for fillColor: BadgeFillColor) -> AnyColorable { switch fillColor { case .red, .black: - return DisabledSurfaceColorConfiguration().with { + return .init(colorable: DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsPrimaryOndark $0.disabled.darkColor = VDSColor.elementsPrimaryOndark $0.enabled.lightColor = VDSColor.elementsPrimaryOndark $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - } + }) case .yellow, .white: - return DisabledSurfaceColorConfiguration().with { + return .init(colorable: DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsPrimaryOnlight $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight - } + }) case .orange, .green, .blue: - return DisabledSurfaceColorConfiguration().with { + return .init(colorable: DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsPrimaryOndark $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight $0.enabled.lightColor = VDSColor.elementsPrimaryOndark $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight - } + }) } } diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 8dae7755..a6fdb666 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -67,12 +67,12 @@ open class LabelBase: UILabel, ModelHandlerable, ViewProt //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - public var textColorConfiguration = DisabledSurfaceColorConfiguration().with { + public var textColorConfiguration: AnyColorable = .init(colorable: DisabledSurfaceColorConfiguration().with { $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight $0.disabled.darkColor = VDSColor.elementsSecondaryOndark $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - } + }) //-------------------------------------------------- // MARK: - Initializers