diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 373ab90c..fa4b30d8 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -8,7 +8,7 @@ import Foundation import UIKit -public protocol Colorable: AnyObject, ObjectWithable { +public protocol Colorable { associatedtype ModelType func getColor(_ viewModel: ModelType) -> UIColor } @@ -19,15 +19,15 @@ extension Colorable { } } -public class AnyColorable: Colorable { - - private var wrapper: (ModelType) -> UIColor +public struct AnyColorable: Colorable, Withable { + private var wrapped: any Colorable public init(colorable: C) where C.ModelType == ModelType { - wrapper = colorable.getColor(_:) + wrapped = colorable } + public func getColor(_ viewModel: ModelType) -> UIColor { - wrapper(viewModel) + wrapped.getColor(viewModel) } } @@ -39,6 +39,8 @@ extension BinaryColorable where Self: Selectable { public var userTrueColor: Bool { return selected } } +public typealias ClassColorable = Colorable & Initable & ObjectWithable + /// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations /// - Surfaceable (var surface: Surface) /// @@ -51,7 +53,7 @@ extension BinaryColorable where Self: Selectable { /// config.darkColor = .white /// /// let textColor = config.getColor(model) //returns .black -open class SurfaceColorConfiguration: Colorable, Initable { +open class SurfaceColorConfiguration: ClassColorable { public var lightColor: UIColor = .clear public var darkColor: UIColor = .clear @@ -82,7 +84,7 @@ open class SurfaceColorConfiguration: Colorable, Initable /// let textColor = config.getColor(model) //returns .white /// /// -open class DisabledSurfaceColorConfiguration: Colorable, Initable { +open class DisabledSurfaceColorConfiguration: ClassColorable { public var disabled = SurfaceColorConfiguration() public var enabled = SurfaceColorConfiguration() @@ -113,7 +115,7 @@ open class DisabledSurfaceColorConfiguration: /// let textColor = config.getColor(model) //returns .white /// /// -open class BinarySurfaceColorConfiguration: Colorable, Initable{ +open class BinarySurfaceColorConfiguration: ClassColorable { public var forTrue = SurfaceColorConfiguration() public var forFalse = SurfaceColorConfiguration() @@ -150,7 +152,7 @@ open class BinarySurfaceColorConfiguration: Colorable, Initable { +open class BinaryDisabledSurfaceColorConfiguration: ClassColorable { public var forTrue = DisabledSurfaceColorConfiguration() public var forFalse = DisabledSurfaceColorConfiguration() diff --git a/VDS/Components/Button/Button.swift b/VDS/Components/Button/Button.swift index bdddb0a9..46f916ab 100644 --- a/VDS/Components/Button/Button.swift +++ b/VDS/Components/Button/Button.swift @@ -213,7 +213,7 @@ open class ButtonBase: UIButton, ModelHandlerable, ViewP // MARK: - PRIVATE //-------------------------------------------------- - private class UseableColorConfiguration : Colorable { + private class UseableColorConfiguration : ClassColorable { public var primary = DisabledSurfaceColorConfiguration() public var secondary = DisabledSurfaceColorConfiguration()