refactored colorable again
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
27a5d665cf
commit
0abcbde5ec
@ -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 }
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
50
VDS/Protocols/Colorable.swift
Normal file
50
VDS/Protocols/Colorable.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user