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 UIKit
|
||||
|
||||
public protocol Colorable: AnyObject, ObjectWithable {
|
||||
public protocol Colorable<ModelType> {
|
||||
associatedtype ModelType
|
||||
func getColor(_ viewModel: ModelType) -> UIColor
|
||||
}
|
||||
@ -19,15 +19,15 @@ extension Colorable {
|
||||
}
|
||||
}
|
||||
|
||||
public class AnyColorable<ModelType>: Colorable {
|
||||
|
||||
private var wrapper: (ModelType) -> UIColor
|
||||
public struct AnyColorable<ModelType>: Colorable, Withable {
|
||||
private var wrapped: any Colorable<ModelType>
|
||||
|
||||
public init<C: Colorable>(colorable: C) where C.ModelType == ModelType {
|
||||
wrapper = colorable.getColor(_:)
|
||||
wrapped = colorable
|
||||
}
|
||||
|
||||
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 typealias ClassColorable = Colorable & Initable & ObjectWithable
|
||||
|
||||
/// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations
|
||||
/// - Surfaceable (var surface: Surface)
|
||||
///
|
||||
@ -51,7 +53,7 @@ extension BinaryColorable where Self: Selectable {
|
||||
/// config.darkColor = .white
|
||||
///
|
||||
/// 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 darkColor: UIColor = .clear
|
||||
|
||||
@ -82,7 +84,7 @@ open class SurfaceColorConfiguration<ModelType:Surfaceable>: Colorable, Initable
|
||||
/// 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 enabled = SurfaceColorConfiguration<ModelType>()
|
||||
|
||||
@ -113,7 +115,7 @@ open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>:
|
||||
/// 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 forFalse = SurfaceColorConfiguration<ModelType>()
|
||||
|
||||
@ -150,7 +152,7 @@ open class BinarySurfaceColorConfiguration<ModelType:Surfaceable & BinaryColorab
|
||||
/// 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 forFalse = DisabledSurfaceColorConfiguration<ModelType>()
|
||||
|
||||
|
||||
@ -213,7 +213,7 @@ open class ButtonBase<ModelType: ButtonModel>: UIButton, ModelHandlerable, ViewP
|
||||
// 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 secondary = DisabledSurfaceColorConfiguration<ModelType>()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user