From 11416b5343b315c9ecec8539696576e9c49d3223 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 17:56:49 -0600 Subject: [PATCH] override getColor for state Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 9a4f855b..c14e6f1c 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -15,6 +15,23 @@ public class ControlColorConfiguration: StateColorConfiguration required public override init() {} + public override func getColor(_ surface: Surface, forState state: UIControl.State) -> UIColor { + + // find the exact match + if let stateColor = stateColors.first(where: {$0.state == state }) { + return stateColor.surfaceConfig.getColor(surface) + + } else if state.contains(.disabled), let stateColor = stateColors.first(where: {$0.state == .disabled }) { + return stateColor.surfaceConfig.getColor(surface) + + } else if state.contains(.highlighted), let stateColor = stateColors.first(where: {$0.state == .highlighted }) { + return stateColor.surfaceConfig.getColor(surface) + + } else { + return .clear + + } + } public func getColor(_ object: any ObjectType) -> UIColor { return getColor(object.surface, forState: object.state) } @@ -41,7 +58,7 @@ public class StateColorConfiguration { var surfaceConfig: SurfaceColorConfiguration } - private var stateColors: [StateColor] = [] + internal var stateColors: [StateColor] = [] public init() { }