added type erasure

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-10-10 10:52:49 -05:00
parent 94ad6cd9f8
commit b81dac7039
3 changed files with 14 additions and 8 deletions

View File

@ -13,6 +13,12 @@ public protocol Colorable: AnyObject, ObjectWithable {
func getColor(_ viewModel: ModelType) -> UIColor
}
extension Colorable {
public func eraseToAnyColorable() -> AnyColorable<ModelType> {
AnyColorable(colorable: self)
}
}
public class AnyColorable<ModelType>: Colorable {
private var wrapper: (ModelType) -> UIColor

View File

@ -138,26 +138,26 @@ open class BadgeBase<ModelType: BadgeModel>: View<ModelType> {
switch fillColor {
case .red, .black:
return .init(colorable: DisabledSurfaceColorConfiguration<ModelType>().with {
return DisabledSurfaceColorConfiguration<ModelType>().with {
$0.disabled.lightColor = VDSColor.elementsPrimaryOndark
$0.disabled.darkColor = VDSColor.elementsPrimaryOndark
$0.enabled.lightColor = VDSColor.elementsPrimaryOndark
$0.enabled.darkColor = VDSColor.elementsPrimaryOndark
})
}.eraseToAnyColorable()
case .yellow, .white:
return .init(colorable: DisabledSurfaceColorConfiguration<ModelType>().with {
return DisabledSurfaceColorConfiguration<ModelType>().with {
$0.disabled.lightColor = VDSColor.elementsPrimaryOnlight
$0.disabled.darkColor = VDSColor.elementsPrimaryOnlight
$0.enabled.lightColor = VDSColor.elementsPrimaryOnlight
$0.enabled.darkColor = VDSColor.elementsPrimaryOnlight
})
}.eraseToAnyColorable()
case .orange, .green, .blue:
return .init(colorable: DisabledSurfaceColorConfiguration<ModelType>().with {
return DisabledSurfaceColorConfiguration<ModelType>().with {
$0.disabled.lightColor = VDSColor.elementsPrimaryOndark
$0.disabled.darkColor = VDSColor.elementsPrimaryOnlight
$0.enabled.lightColor = VDSColor.elementsPrimaryOndark
$0.enabled.darkColor = VDSColor.elementsPrimaryOnlight
})
}.eraseToAnyColorable()
}
}

View File

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