added configurations
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
1146006ca6
commit
b1cf47154e
@ -10,26 +10,89 @@ import UIKit
|
|||||||
|
|
||||||
public typealias ObjectColorable = Colorable & Initable & ObjectWithable
|
public typealias ObjectColorable = Colorable & Initable & ObjectWithable
|
||||||
|
|
||||||
|
public class ControlColorConfiguration: StateColorConfiguration<UIControl.State>, ObjectColorable {
|
||||||
|
public typealias ObjectType = UIControl & Surfaceable
|
||||||
|
|
||||||
|
required public override init() {}
|
||||||
|
|
||||||
|
public func getColor(_ object: any ObjectType) -> UIColor {
|
||||||
|
return getColor(object.surface, forState: object.state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewColorConfiguration: StateColorConfiguration<Bool>, ObjectColorable {
|
||||||
|
public typealias ObjectType = Disabling & Surfaceable
|
||||||
|
|
||||||
|
required public override init() {}
|
||||||
|
|
||||||
|
public func setSurfaceColors(_ lightColor: UIColor, _ darkColor: UIColor, forDisabled disabled: Bool) {
|
||||||
|
setSurfaceColors(lightColor, darkColor, forState: disabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getColor(_ object: any ObjectType) -> UIColor {
|
||||||
|
return getColor(object.surface, forState: object.disabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StateColorConfiguration<StateType: Equatable> {
|
||||||
|
|
||||||
|
struct StateColor {
|
||||||
|
var state: StateType
|
||||||
|
var surfaceConfig: SurfaceColorConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
|
private var stateColors: [StateColor] = []
|
||||||
|
|
||||||
|
public init() { }
|
||||||
|
|
||||||
|
public func getColor(_ surface: Surface, forState state: StateType) -> UIColor {
|
||||||
|
if let stateColor = stateColors.first(where: {$0.state == state }) {
|
||||||
|
return stateColor.surfaceConfig.getColor(surface)
|
||||||
|
} else {
|
||||||
|
return .clear //default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func setSurfaceColors(_ lightColor: UIColor, _ darkColor: UIColor, forState state: StateType) {
|
||||||
|
stateColors.append(.init(state: state, surfaceConfig: .init(lightColor, darkColor)))
|
||||||
|
}
|
||||||
|
|
||||||
|
public func reset() {
|
||||||
|
stateColors.removeAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// 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)
|
||||||
///
|
///
|
||||||
/// let model = TestModel()
|
/// let model = TestModel()
|
||||||
/// model.surface = .light
|
/// model.surface = .light
|
||||||
///
|
///
|
||||||
/// let config = SurfaceColorConfiguration<TestModel>()
|
/// let config = SurfaceColorConfiguration()
|
||||||
///
|
|
||||||
/// config.lightColor = .black
|
/// config.lightColor = .black
|
||||||
/// config.darkColor = .white
|
/// config.darkColor = .white
|
||||||
///
|
///
|
||||||
/// let textColor = config.getColor(model) //returns .black
|
/// let textColor = config.getColor(model) //returns .black
|
||||||
final public class SurfaceColorConfiguration: ObjectColorable {
|
|
||||||
|
open class SurfaceColorConfiguration: ObjectColorable {
|
||||||
public typealias ObjectType = Surfaceable
|
public typealias ObjectType = Surfaceable
|
||||||
public var lightColor: UIColor = .clear
|
public var lightColor: UIColor = .clear
|
||||||
public var darkColor: UIColor = .clear
|
public var darkColor: UIColor = .clear
|
||||||
|
|
||||||
required public init(){}
|
required public init(){}
|
||||||
|
|
||||||
|
public init(_ lightColor: UIColor, _ darkColor: UIColor) {
|
||||||
|
self.lightColor = lightColor
|
||||||
|
self.darkColor = darkColor
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getColor(_ surface: Surface) -> UIColor {
|
||||||
|
return surface == .light ? lightColor : darkColor
|
||||||
|
}
|
||||||
|
|
||||||
public func getColor(_ object: any ObjectType) -> UIColor {
|
public func getColor(_ object: any ObjectType) -> UIColor {
|
||||||
return object.surface == .light ? lightColor : darkColor
|
return getColor(object.surface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,3 +252,52 @@ final public class BinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfac
|
|||||||
getBinaryColor(object)
|
getBinaryColor(object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ControlStateColorConfiguration: ObjectColorable {
|
||||||
|
public typealias ObjectType = UIControl & Surfaceable
|
||||||
|
public var disabled = SurfaceColorConfiguration()
|
||||||
|
public var normal = SurfaceColorConfiguration()
|
||||||
|
public var highlighted: SurfaceColorConfiguration?
|
||||||
|
public var selected: SurfaceColorConfiguration?
|
||||||
|
public var error: SurfaceColorConfiguration?
|
||||||
|
|
||||||
|
required public init(){}
|
||||||
|
|
||||||
|
public func setColorable(_ config: SurfaceColorConfiguration, for state: UIControl.State) {
|
||||||
|
switch state {
|
||||||
|
case .disabled:
|
||||||
|
disabled = config
|
||||||
|
|
||||||
|
case .highlighted:
|
||||||
|
highlighted = config
|
||||||
|
|
||||||
|
case .selected:
|
||||||
|
selected = config
|
||||||
|
|
||||||
|
case .error:
|
||||||
|
error = config
|
||||||
|
|
||||||
|
default:
|
||||||
|
normal = config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func getColor(_ object: any ObjectType) -> UIColor {
|
||||||
|
|
||||||
|
if object.state == .disabled {
|
||||||
|
return disabled.getColor(object)
|
||||||
|
|
||||||
|
} else if let highlighted, object.state == .highlighted {
|
||||||
|
return highlighted.getColor(object)
|
||||||
|
|
||||||
|
} else if let selected, object.state == .selected {
|
||||||
|
return selected.getColor(object)
|
||||||
|
|
||||||
|
} else if let error, object.state == .error {
|
||||||
|
return error.getColor(object)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return normal.getColor(object)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user