vds_ios/VDS/Classes/ColorConfiguration.swift
Matt Bruce 0abcbde5ec refactored colorable again
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-10-10 13:51:18 -05:00

142 lines
4.7 KiB
Swift

//
// ModelColorConfiguration.swift
// VDS
//
// Created by Matt Bruce on 8/4/22.
//
import Foundation
import UIKit
public protocol BinaryColorable{
var userTrueColor: Bool { get }
}
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)
///
/// let model = TestModel()
/// model.surface = .light
///
/// let config = SurfaceColorConfiguration<TestModel>()
///
/// config.lightColor = .black
/// config.darkColor = .white
///
/// let textColor = config.getColor(model) //returns .black
open class SurfaceColorConfiguration<ModelType:Surfaceable>: ClassColorable {
public var lightColor: UIColor = .clear
public var darkColor: UIColor = .clear
required public init(){}
public func getColor(_ viewModel: ModelType) -> UIColor {
return viewModel.surface == .light ? lightColor : darkColor
}
}
/// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations
/// - Disabling (var disabled: Bool)
/// - Surfaceable (var surface: Surface)
///
/// let model = TestModel()
/// model.surface = .dark
/// model.disabled = false
///
/// let config = DisabledSurfaceColorConfiguration<TestModel>()
///
/// //disabled == false
/// config.enabled.lightColor = .black
/// config.enabled.darkColor = .white
///
/// //disabled == true
/// config.disabled.lightColor = .gray
/// config.disabled.darkColor = .lightGray
///
/// let textColor = config.getColor(model) //returns .white
///
///
open class DisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable>: ClassColorable {
public var disabled = SurfaceColorConfiguration<ModelType>()
public var enabled = SurfaceColorConfiguration<ModelType>()
required public init(){}
public func getColor(_ viewModel: ModelType) -> UIColor {
return viewModel.disabled ? disabled.getColor(viewModel) : enabled.getColor(viewModel)
}
}
/// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations
/// - BinaryColorable (var userTrueColor: Bool)
/// - Surfaceable (var surface: Surface)
///
/// let model = TestModel()
/// model.surface = .dark
/// model.on = true //this is read in the extension var userTrueColor
/// let config = BinarySurfaceColorConfiguration<TestModel>()
///
/// //True from BinaryColorable.userTrueColor
/// config.forTrue.lightColor = .black
/// config.forTrue.darkColor = .white
///
/// //False from BinaryColorable.userTrueColor
/// config.forFalse.lightColor = .red
/// config.forFalse.darkColor = .red
///
/// let textColor = config.getColor(model) //returns .white
///
///
open class BinarySurfaceColorConfiguration<ModelType:Surfaceable & BinaryColorable>: ClassColorable {
public var forTrue = SurfaceColorConfiguration<ModelType>()
public var forFalse = SurfaceColorConfiguration<ModelType>()
required public init(){}
public func getColor(_ viewModel: ModelType) -> UIColor {
return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel)
}
}
/// Meant to be used in a Object that implements the following interfaces for 8 possible color combinations
/// - BinaryColorable (var userTrueColor: Bool)
/// - Disabling (var disabled: Bool)
/// - Surfaceable (var surface: Surface)
///
/// let model = TestModel()
/// model.on = false
/// model.disabled = false
/// model.surface = .light
/// let config = BinaryDisabledSurfaceColorConfiguration<TestModel>()
///
/// //True
/// config.forTrue.enabled.lightColor = .black
/// config.forTrue.enabled.darkColor = .white
/// config.forTrue.disabled.lightColor = .darkGray
/// config.forTrue.disabled.darkColor = .lightGray
///
/// //False
/// config.forFalse.enabled.lightColor = .red
/// config.forFalse.enabled.darkColor = .red
/// config.forFalse.disabled.lightColor =.darkGray
/// config.forFalse.disabled.darkColor = .lightGray
///
/// let textColor = config.getColor(model)
///
///
open class BinaryDisabledSurfaceColorConfiguration<ModelType:Disabling & Surfaceable & BinaryColorable>: ClassColorable {
public var forTrue = DisabledSurfaceColorConfiguration<ModelType>()
public var forFalse = DisabledSurfaceColorConfiguration<ModelType>()
required public init(){}
public func getColor(_ viewModel: ModelType) -> UIColor {
return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel)
}
}