updated label/badge to AnyColorable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
f6b0696457
commit
50bb9dd3d4
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user