refactored colorable again

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-10-10 13:51:18 -05:00
parent 27a5d665cf
commit 0abcbde5ec
4 changed files with 52 additions and 25 deletions

View File

@ -8,29 +8,6 @@
import Foundation
import UIKit
public protocol Colorable<ModelType> {
associatedtype ModelType
func getColor(_ viewModel: ModelType) -> UIColor
}
extension Colorable {
public func eraseToAnyColorable() -> AnyColorable<ModelType> {
AnyColorable(colorable: self)
}
}
public struct AnyColorable<ModelType>: Colorable, Withable {
private var wrapped: any Colorable<ModelType>
public init<C: Colorable>(colorable: C) where C.ModelType == ModelType {
wrapped = colorable
}
public func getColor(_ viewModel: ModelType) -> UIColor {
wrapped.getColor(viewModel)
}
}
public protocol BinaryColorable{
var userTrueColor: Bool { get }
}

View File

@ -133,7 +133,7 @@ open class BadgeBase<ModelType: BadgeModel>: View<ModelType> {
return config.getColor(model)
}
public func textColorConfiguration<ModelType: LabelModel>(for fillColor: BadgeFillColor) -> AnyColorable<ModelType> {
public func textColorConfiguration(for fillColor: BadgeFillColor) -> AnyColorable {
switch fillColor {

View File

@ -67,7 +67,7 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, ViewProt
//--------------------------------------------------
// MARK: - Configuration Properties
//--------------------------------------------------
public var textColorConfiguration: AnyColorable<ModelType> = DisabledSurfaceColorConfiguration().with {
public var textColorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration<ModelType>().with {
$0.disabled.lightColor = VDSColor.elementsSecondaryOnlight
$0.disabled.darkColor = VDSColor.elementsSecondaryOndark
$0.enabled.lightColor = VDSColor.elementsPrimaryOnlight

View File

@ -0,0 +1,50 @@
//
// Colorable.swift
// VDS
//
// Created by Matt Bruce on 10/10/22.
//
import Foundation
import UIKit
public protocol Colorable<ModelType> {
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<ModelType>: Colorable, Withable {
private var wrapped: any Colorable<ModelType>
public init<C: Colorable>(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)
}
}