updated label/badge to AnyColorable

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-10-10 10:44:04 -05:00
parent f6b0696457
commit 50bb9dd3d4
3 changed files with 21 additions and 21 deletions

View File

@ -13,6 +13,18 @@ public protocol Colorable: AnyObject, ObjectWithable {
func getColor(_ viewModel: ModelType) -> UIColor
}
public class AnyColorable<ModelType>: Colorable {
private var wrapper: (ModelType) -> UIColor
public init<C: Colorable>(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<ModelType:Disabling & Surface
return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel)
}
}
public class AnyColorConfiguration<ModelType>: Colorable {
private var colorHelper: (ModelType) -> UIColor
public init<C: Colorable>(colorable: C) where C.ModelType == ModelType {
colorHelper = colorable.getColor(_:)
}
public func getColor(_ viewModel: ModelType) -> UIColor {
colorHelper(viewModel)
}
}

View File

@ -133,31 +133,31 @@ open class BadgeBase<ModelType: BadgeModel>: View<ModelType> {
return config.getColor(model)
}
public func textColorConfiguration<ModelType: LabelModel>(for fillColor: BadgeFillColor) -> DisabledSurfaceColorConfiguration<ModelType> {
public func textColorConfiguration<ModelType: LabelModel>(for fillColor: BadgeFillColor) -> AnyColorable<ModelType> {
switch fillColor {
case .red, .black:
return DisabledSurfaceColorConfiguration<ModelType>().with {
return .init(colorable: DisabledSurfaceColorConfiguration<ModelType>().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<ModelType>().with {
return .init(colorable: DisabledSurfaceColorConfiguration<ModelType>().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<ModelType>().with {
return .init(colorable: DisabledSurfaceColorConfiguration<ModelType>().with {
$0.disabled.lightColor = VDSColor.elementsPrimaryOndark
$0.disabled.darkColor = VDSColor.elementsPrimaryOnlight
$0.enabled.lightColor = VDSColor.elementsPrimaryOndark
$0.enabled.darkColor = VDSColor.elementsPrimaryOnlight
}
})
}
}

View File

@ -67,12 +67,12 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerable, ViewProt
//--------------------------------------------------
// MARK: - Configuration Properties
//--------------------------------------------------
public var textColorConfiguration = DisabledSurfaceColorConfiguration<ModelType>().with {
public var textColorConfiguration: AnyColorable<ModelType> = .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