refactored more colorable for AnyColorable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
b81dac7039
commit
27a5d665cf
@ -8,7 +8,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol Colorable: AnyObject, ObjectWithable {
|
public protocol Colorable<ModelType> {
|
||||||
associatedtype ModelType
|
associatedtype ModelType
|
||||||
func getColor(_ viewModel: ModelType) -> UIColor
|
func getColor(_ viewModel: ModelType) -> UIColor
|
||||||
}
|
}
|
||||||
@ -19,15 +19,15 @@ extension Colorable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AnyColorable<ModelType>: Colorable {
|
public struct AnyColorable<ModelType>: Colorable, Withable {
|
||||||
|
private var wrapped: any Colorable<ModelType>
|
||||||
private var wrapper: (ModelType) -> UIColor
|
|
||||||
|
|
||||||
public init<C: Colorable>(colorable: C) where C.ModelType == ModelType {
|
public init<C: Colorable>(colorable: C) where C.ModelType == ModelType {
|
||||||
wrapper = colorable.getColor(_:)
|
wrapped = colorable
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getColor(_ viewModel: ModelType) -> UIColor {
|
public func getColor(_ viewModel: ModelType) -> UIColor {
|
||||||
wrapper(viewModel)
|
wrapped.getColor(viewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +39,8 @@ extension BinaryColorable where Self: Selectable {
|
|||||||
public var userTrueColor: Bool { return selected }
|
public var userTrueColor: Bool { return selected }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public typealias ClassColorable = Colorable & Initable & ObjectWithable
|
||||||
|
|
||||||
/// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations
|
/// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations
|
||||||
/// - Surfaceable (var surface: Surface)
|
/// - Surfaceable (var surface: Surface)
|
||||||
///
|
///
|
||||||
@ -51,7 +53,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, Initable {
|
open class SurfaceColorConfiguration<ModelType:Surfaceable>: ClassColorable {
|
||||||
public var lightColor: UIColor = .clear
|
public var lightColor: UIColor = .clear
|
||||||
public var darkColor: UIColor = .clear
|
public var darkColor: UIColor = .clear
|
||||||
|
|
||||||
@ -82,7 +84,7 @@ open class SurfaceColorConfiguration<ModelType:Surfaceable>: Colorable, Initable
|
|||||||
/// let textColor = config.getColor(model) //returns .white
|
/// let textColor = config.getColor(model) //returns .white
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>: Colorable, Initable {
|
open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>: ClassColorable {
|
||||||
public var disabled = SurfaceColorConfiguration<ModelType>()
|
public var disabled = SurfaceColorConfiguration<ModelType>()
|
||||||
public var enabled = SurfaceColorConfiguration<ModelType>()
|
public var enabled = SurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
@ -113,7 +115,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, Initable{
|
open class BinarySurfaceColorConfiguration<ModelType:Surfaceable & BinaryColorable>: ClassColorable {
|
||||||
public var forTrue = SurfaceColorConfiguration<ModelType>()
|
public var forTrue = SurfaceColorConfiguration<ModelType>()
|
||||||
public var forFalse = SurfaceColorConfiguration<ModelType>()
|
public var forFalse = SurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
@ -150,7 +152,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, Initable {
|
open class BinaryDisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable & BinaryColorable>: ClassColorable {
|
||||||
public var forTrue = DisabledSurfaceColorConfiguration<ModelType>()
|
public var forTrue = DisabledSurfaceColorConfiguration<ModelType>()
|
||||||
public var forFalse = DisabledSurfaceColorConfiguration<ModelType>()
|
public var forFalse = DisabledSurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
|
|||||||
@ -213,7 +213,7 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
|||||||
// MARK: - PRIVATE
|
// MARK: - PRIVATE
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
private class UseableColorConfiguration<ModelType:Disabling & Surfaceable & Useable> : Colorable {
|
private class UseableColorConfiguration<ModelType:Disabling & Surfaceable & Useable> : ClassColorable {
|
||||||
public var primary = DisabledSurfaceColorConfiguration<ModelType>()
|
public var primary = DisabledSurfaceColorConfiguration<ModelType>()
|
||||||
public var secondary = DisabledSurfaceColorConfiguration<ModelType>()
|
public var secondary = DisabledSurfaceColorConfiguration<ModelType>()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user