added AnyColorConfiguration
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c29cd4a7a5
commit
d7f243a09e
@ -8,7 +8,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol Colorable: AnyObject, ObjectWithable, Initable {
|
public protocol Colorable: AnyObject, ObjectWithable {
|
||||||
associatedtype ModelType
|
associatedtype ModelType
|
||||||
func getColor(_ viewModel: ModelType) -> UIColor
|
func getColor(_ viewModel: ModelType) -> UIColor
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ extension BinaryColorable where Self: Selectable {
|
|||||||
/// config.darkColor = .white
|
/// config.darkColor = .white
|
||||||
///
|
///
|
||||||
/// let textColor = config.getColor(model) //returns .black
|
/// let textColor = config.getColor(model) //returns .black
|
||||||
open class SurfaceColorConfiguration<ModelType:Surfaceable>: Colorable {
|
open class SurfaceColorConfiguration<ModelType:Surfaceable>: Colorable, Initable {
|
||||||
public var lightColor: UIColor = .clear
|
public var lightColor: UIColor = .clear
|
||||||
public var darkColor: UIColor = .clear
|
public var darkColor: UIColor = .clear
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ open class SurfaceColorConfiguration<ModelType:Surfaceable>: Colorable {
|
|||||||
/// let textColor = config.getColor(model) //returns .white
|
/// let textColor = config.getColor(model) //returns .white
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>: Colorable {
|
open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>: Colorable, Initable {
|
||||||
public var disabled = SurfaceColorConfiguration<ModelType>()
|
public var disabled = SurfaceColorConfiguration<ModelType>()
|
||||||
public var enabled = SurfaceColorConfiguration<ModelType>()
|
public var enabled = SurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>:
|
|||||||
/// let textColor = config.getColor(model) //returns .white
|
/// let textColor = config.getColor(model) //returns .white
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
open class BinarySurfaceColorConfiguration<ModelType:Surfaceable & BinaryColorable>: Colorable{
|
open class BinarySurfaceColorConfiguration<ModelType:Surfaceable & BinaryColorable>: Colorable, Initable{
|
||||||
public var forTrue = SurfaceColorConfiguration<ModelType>()
|
public var forTrue = SurfaceColorConfiguration<ModelType>()
|
||||||
public var forFalse = SurfaceColorConfiguration<ModelType>()
|
public var forFalse = SurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ open class BinarySurfaceColorConfiguration<ModelType:Surfaceable & BinaryColorab
|
|||||||
/// let textColor = config.getColor(model)
|
/// let textColor = config.getColor(model)
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
open class BinaryDisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable & BinaryColorable>: Colorable {
|
open class BinaryDisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable & BinaryColorable>: Colorable, Initable {
|
||||||
public var forTrue = DisabledSurfaceColorConfiguration<ModelType>()
|
public var forTrue = DisabledSurfaceColorConfiguration<ModelType>()
|
||||||
public var forFalse = DisabledSurfaceColorConfiguration<ModelType>()
|
public var forFalse = DisabledSurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
@ -142,3 +142,15 @@ open class BinaryDisabledSurfaceColorConfiguration<ModelType:Disabling & Surface
|
|||||||
return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user