From bffd7f8dd9194444b2662a4b99f1d7a61d9a5ca9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 6 Dec 2022 09:18:06 -0600 Subject: [PATCH 01/28] removed double line height Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 7dd4839f..d3ede278 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -112,7 +112,6 @@ open class TextLink: ButtonBase { //need to set the properties so the super class //can render out the label correctly heightConstraint?.constant = height - lineHeightConstraint?.constant = isHighlighted ? 2.0 : 1.0 line.backgroundColor = textColor //always call last so the label is rendered From de9b57362c8c75a60094ca0214c360b0218b4589 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 6 Dec 2022 11:04:28 -0600 Subject: [PATCH 02/28] added animation block for updateview Signed-off-by: Matt Bruce --- .../Buttons/Button/ButtonBase.swift | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 887fff2c..121ae8f6 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -43,9 +43,23 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab open var surface: Surface = .light { didSet { didChange() }} open var disabled: Bool = false { didSet { isEnabled = !disabled } } - - open override var isHighlighted: Bool { didSet { if isHighlighted != oldValue { updateView() } } } - + + var isHighlightAnimating = false + open override var isHighlighted: Bool { + didSet { + if isHighlightAnimating == false { + isHighlightAnimating = true + UIView.animate(withDuration: 0.1, animations: { [weak self] in + self?.updateView() + }) { [weak self] _ in + //you update the view since this is typically a quick change + self?.updateView() + self?.isHighlightAnimating = false + } + } + } + } + open var typograpicalStyle: TypographicalStyle { .defaultStyle } open var textColor: UIColor { .black } @@ -129,7 +143,6 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab // MARK: - PRIVATE //-------------------------------------------------- private func updateLabel() { - let font = typograpicalStyle.font //clear the arrays holding actions From 7da9e33f9d4d23cd92dc037dab636423803cb01d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 6 Dec 2022 11:04:39 -0600 Subject: [PATCH 03/28] remveod cell Signed-off-by: Matt Bruce --- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 165ac959..916609e4 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -152,7 +152,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega button.pinLeading() button.pinTrailing() button.centerYAnchor.constraint(equalTo: cell.centerYAnchor).isActive = true - //cell.debugBorder() return cell } From edcaadf2748afce334780c816cad8c1549dceb7e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 6 Dec 2022 15:58:05 -0600 Subject: [PATCH 04/28] enforced animation back from highlight Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/ButtonBase.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 121ae8f6..005c542a 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -53,8 +53,10 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab self?.updateView() }) { [weak self] _ in //you update the view since this is typically a quick change - self?.updateView() - self?.isHighlightAnimating = false + UIView.animate(withDuration: 0.1, animations: { [weak self] in + self?.updateView() + self?.isHighlightAnimating = false + }) } } } From bd96705b4e987211346122396613f544eacf586b Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 7 Dec 2022 10:45:43 -0600 Subject: [PATCH 05/28] fixed bug in toggle being out of sync with isSelected Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index ab7428f1..9f5e17e0 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -130,7 +130,15 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var isOn: Bool = false { didSet { didChange() }} + open var isOn: Bool { + get { isSelected } + set { + if isSelected != newValue { + isSelected = newValue + } + didChange() + } + } open var isAnimated: Bool = true { didSet { didChange() }} @@ -292,7 +300,6 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { public override func reset() { super.reset() label.reset() - isSelected = false isOn = false isAnimated = true @@ -313,7 +320,6 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { /// This will toggle the state of the Toggle and execute the actionBlock if provided. open func toggle() { isOn.toggle() - isSelected = isOn sendActions(for: .valueChanged) } From 89b200c005696c592a39c8f619b878af2655a1ef Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 11:03:13 -0600 Subject: [PATCH 06/28] added highlight Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 90dae4e5..d5af7f46 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -29,8 +29,24 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable { open override var isSelected: Bool { didSet { didChange() } } - open override var isHighlighted: Bool { didSet { updateView() } } - + var isHighlightAnimating = false + open override var isHighlighted: Bool { + didSet { + if isHighlightAnimating == false { + isHighlightAnimating = true + UIView.animate(withDuration: 0.1, animations: { [weak self] in + self?.updateView() + }) { [weak self] _ in + //you update the view since this is typically a quick change + UIView.animate(withDuration: 0.1, animations: { [weak self] in + self?.updateView() + self?.isHighlightAnimating = false + }) + } + } + } + } + open override var isEnabled: Bool { get { !disabled } set { From d02794e369cd4dc5af4d7eca035443720fe28048 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 11:03:33 -0600 Subject: [PATCH 07/28] added UIControl extension Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 8 ++++++-- VDS/Extensions/UIControl.swift | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 VDS/Extensions/UIControl.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 7351cf9e..c89651a4 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -63,6 +63,7 @@ EAB5FEF12927F4AA00998C17 /* SelfSizingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */; }; EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF4292D371F00998C17 /* ButtonBase.swift */; }; EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */; }; + EAB5FF0129424ACB00998C17 /* UIControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FF0029424ACB00998C17 /* UIControl.swift */; }; EAC9257D29119B5400091998 /* TextLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257C29119B5400091998 /* TextLink.swift */; }; EAC925832911B35400091998 /* TextLinkCaret.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC925822911B35300091998 /* TextLinkCaret.swift */; }; EAC925842911C63100091998 /* Colorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEDF28F49DB3003B3210 /* Colorable.swift */; }; @@ -157,6 +158,7 @@ EAB5FEF02927F4AA00998C17 /* SelfSizingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingCollectionView.swift; sourceTree = ""; }; EAB5FEF4292D371F00998C17 /* ButtonBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonBase.swift; sourceTree = ""; }; EAB5FEF729393A7200998C17 /* ButtonGroupConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonGroupConstants.swift; sourceTree = ""; }; + EAB5FF0029424ACB00998C17 /* UIControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIControl.swift; sourceTree = ""; }; EAC9257C29119B5400091998 /* TextLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLink.swift; sourceTree = ""; }; EAC925822911B35300091998 /* TextLinkCaret.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaret.swift; sourceTree = ""; }; EAC925872911C9DE00091998 /* TextEntryField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextEntryField.swift; sourceTree = ""; }; @@ -331,6 +333,7 @@ EAF7F0B4289C126F00B287F5 /* UILabel.swift */, EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */, EAB5FED329267EB300998C17 /* UIView.swift */, + EAB5FF0029424ACB00998C17 /* UIControl.swift */, ); path = Extensions; sourceTree = ""; @@ -694,6 +697,7 @@ EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */, EA336171288B19200071C351 /* VDS.docc in Sources */, EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */, + EAB5FF0129424ACB00998C17 /* UIControl.swift in Sources */, EAB1D2E628AE842000DAE764 /* Publisher+Bind.swift in Sources */, EA3361AA288B25E40071C351 /* Disabling.swift in Sources */, EA3361B6288B2A410071C351 /* Control.swift in Sources */, @@ -864,7 +868,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../../SharedFrameworks"; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../SharedFrameworks"; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -897,7 +901,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../../SharedFrameworks"; + FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)/../SharedFrameworks"; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; diff --git a/VDS/Extensions/UIControl.swift b/VDS/Extensions/UIControl.swift new file mode 100644 index 00000000..057f4dac --- /dev/null +++ b/VDS/Extensions/UIControl.swift @@ -0,0 +1,13 @@ +// +// UIControl.swift +// VDS +// +// Created by Matt Bruce on 12/8/22. +// + +import Foundation +import UIKit + +extension UIControl.State { + public static var error = UIControl.State(rawValue: 1 << 16) +} From 312dd949b55de179a7e4e1b0207f4023b92810e9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:46:51 -0600 Subject: [PATCH 08/28] added success to UIControl.State Signed-off-by: Matt Bruce --- VDS/Extensions/UIControl.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/VDS/Extensions/UIControl.swift b/VDS/Extensions/UIControl.swift index 057f4dac..abccd3f3 100644 --- a/VDS/Extensions/UIControl.swift +++ b/VDS/Extensions/UIControl.swift @@ -10,4 +10,5 @@ import UIKit extension UIControl.State { public static var error = UIControl.State(rawValue: 1 << 16) + public static var success = UIControl.State(rawValue: 1 << 16) } From e027b05046b0e473e65f9d1d957f7f3eea5c8764 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:47:19 -0600 Subject: [PATCH 09/28] added state overrides Signed-off-by: Matt Bruce --- VDS/Components/TextFields/EntryField/EntryField.swift | 10 ++++++++++ .../TextFields/TextEntryField/TextEntryField.swift | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 150ad842..b45389dd 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -107,6 +107,16 @@ open class EntryField: Control, Accessable { open var showError: Bool = false { didSet { didChange() }} + open override var state: UIControl.State { + get { + var state = super.state + if showError { + state.insert(.error) + } + return state + } + } + open var errorText: String? { didSet { didChange() }} open var tooltipTitle: String? { didSet { didChange() }} diff --git a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift index c0eee646..6d8b8742 100644 --- a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift +++ b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift @@ -54,6 +54,16 @@ open class TextEntryFieldBase: EntryField { open var showSuccess: Bool = false { didSet { didChange() }} + open override var state: UIControl.State { + get { + var state = super.state + if showSuccess { + state.insert(.success) + } + return state + } + } + open var successText: String? { didSet { didChange() }} open var helperTextPlacement: HelperTextPlacement = .bottom { didSet { didChange() }} From 1146006ca65026388fba022c045637134cdd4bed Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:47:40 -0600 Subject: [PATCH 10/28] updated badge Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 92 ++++++++++---------------------- 1 file changed, 28 insertions(+), 64 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 9541a483..b3ffb2bd 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -102,74 +102,36 @@ public class Badge: View, Accessable { //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- - public func backgroundColor() -> UIColor { - var config: SurfaceColorConfiguration - switch fillColor { - case .red: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.backgroundBrandhighlight - $0.darkColor = VDSColor.backgroundBrandhighlight - } - case .yellow: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteYellow62 - $0.darkColor = VDSColor.paletteYellow62 - } - case .green: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteGreen26 - $0.darkColor = VDSColor.paletteGreen34 - } - case .orange: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteOrange39 - $0.darkColor = VDSColor.paletteOrange46 - } - case .blue: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteBlue35 - $0.darkColor = VDSColor.paletteBlue45 - } - case .black: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteBlack - $0.darkColor = VDSColor.paletteBlack - } - case .white: - config = SurfaceColorConfiguration().with { - $0.lightColor = VDSColor.paletteWhite - $0.darkColor = VDSColor.paletteWhite - } - } - - return config.getColor(self) - } - - public func textColorConfiguration() -> AnyColorable { + private var backgroundColorConfig: StateColorConfiguration = { + let config = StateColorConfiguration() + config.setSurfaceColors(VDSColor.backgroundBrandhighlight, VDSColor.backgroundBrandhighlight, forState: .red) + config.setSurfaceColors(VDSColor.paletteYellow62, VDSColor.paletteYellow62, forState: .yellow) + config.setSurfaceColors(VDSColor.paletteGreen26, VDSColor.paletteGreen34, forState: .green) + config.setSurfaceColors(VDSColor.paletteOrange39, VDSColor.paletteOrange46, forState: .orange) + config.setSurfaceColors(VDSColor.paletteBlue35, VDSColor.paletteBlue45, forState: .blue) + config.setSurfaceColors(VDSColor.paletteBlack, VDSColor.paletteBlack, forState: .black) + config.setSurfaceColors(VDSColor.paletteWhite, VDSColor.paletteWhite, forState: .white) + return config + }() + + private var textColorConfig = ViewColorConfiguration() + + public func updateTextColorConfig() { + textColorConfig.reset() switch fillColor { case .red, .black: - return DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsPrimaryOndark - $0.disabled.darkColor = VDSColor.elementsPrimaryOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - }.eraseToAnyColorable() + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forDisabled: false) + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forDisabled: true) + case .yellow, .white: - return DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight - }.eraseToAnyColorable() + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOnlight, forDisabled: false) + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOnlight, forDisabled: true) + case .orange, .green, .blue: - return DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsPrimaryOndark - $0.disabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.enabled.darkColor = VDSColor.elementsPrimaryOnlight - }.eraseToAnyColorable() + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forDisabled: false) + textColorConfig.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forDisabled: true) } } @@ -177,9 +139,11 @@ public class Badge: View, Accessable { // MARK: - State //-------------------------------------------------- open override func updateView() { - backgroundColor = backgroundColor() + updateTextColorConfig() - label.textColorConfiguration = textColorConfiguration() + backgroundColor = backgroundColorConfig.getColor(surface, forState: fillColor) + + label.textColorConfiguration = textColorConfig.eraseToAnyColorable() label.numberOfLines = numberOfLines label.text = text label.surface = surface From b1cf47154ee10b3dafbea8c45e8dff3421c214b3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:47:49 -0600 Subject: [PATCH 11/28] added configurations Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 120 ++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 4 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index cafac5f9..9a4f855b 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -10,26 +10,89 @@ import UIKit public typealias ObjectColorable = Colorable & Initable & ObjectWithable +public class ControlColorConfiguration: StateColorConfiguration, 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, 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 { + + 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 /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .light /// -/// let config = SurfaceColorConfiguration() -/// +/// let config = SurfaceColorConfiguration() /// config.lightColor = .black /// config.darkColor = .white /// /// let textColor = config.getColor(model) //returns .black -final public class SurfaceColorConfiguration: ObjectColorable { + +open class SurfaceColorConfiguration: ObjectColorable { public typealias ObjectType = Surfaceable public var lightColor: UIColor = .clear public var darkColor: UIColor = .clear 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 { - return object.surface == .light ? lightColor : darkColor + return getColor(object.surface) } } @@ -189,3 +252,52 @@ final public class BinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfac 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) + } + } +} From 4ac73e3d38a2b80cc072e08819eda6a9163cd43c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:48:24 -0600 Subject: [PATCH 12/28] refactored radioButton to new color states Signed-off-by: Matt Bruce --- VDS/Components/RadioButton/RadioButton.swift | 70 +++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 6a1c28c7..49cc28d9 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -131,6 +131,16 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open var showError: Bool = false { didSet { didChange() }} + open override var state: UIControl.State { + get { + var state = super.state + if showError { + state.insert(.error) + } + return state + } + } + open var errorText: String? { didSet { didChange() }} open var inputId: String? { didSet { didChange() }} @@ -178,7 +188,8 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, isAccessibilityElement = true accessibilityTraits = .button addSubview(mainStackView) - + mainStackView.isUserInteractionEnabled = false + mainStackView.addArrangedSubview(selectorStackView) mainStackView.addArrangedSubview(errorLabel) selectorStackView.addArrangedSubview(selectorView) @@ -321,38 +332,33 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, //-------------------------------------------------- public let radioButtonSize = CGSize(width: 20, height: 20) public let radioButtonSelectedSize = CGSize(width: 10, height: 10) + + private var radioButtonBackgroundColorConfiguration: ControlColorConfiguration = { + var config = ControlColorConfiguration() + config.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) + return config + }() + + private var radioButtonBorderColorConfiguration: ControlColorConfiguration = { + var config = ControlColorConfiguration() + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) + config.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) + config.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) + return config + }() - private var radioButtonBackgroundColorConfiguration = ErrorBinaryDisabledSurfaceColorConfiguration().with { - //error doesn't care enabled/disable - $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight - $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark - $0.error.forFalse.lightColor = VDSColor.feedbackErrorBackgroundOnlight - $0.error.forFalse.darkColor = VDSColor.feedbackErrorBackgroundOndark - } - - private var radioButtonBorderColorConfiguration = ErrorBinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - //error doesn't care enabled/disable - $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight - $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark - $0.error.forFalse.lightColor = VDSColor.feedbackErrorOnlight - $0.error.forFalse.darkColor = VDSColor.feedbackErrorOndark - } - - private var radioButtonCheckColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - + private var radioButtonCheckColorConfiguration: ControlColorConfiguration = { + var config = ControlColorConfiguration() + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + return config + }() + //-------------------------------------------------- // MARK: - RadioButton View //-------------------------------------------------- From 77f957b23f0fe194e1cc2afd1ce8f6c191be694e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:48:35 -0600 Subject: [PATCH 13/28] refacored checkbox to new color states Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 119 ++++++++++--------------- 1 file changed, 48 insertions(+), 71 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 21e31c9b..70a93588 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -125,8 +125,25 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er } } - open var showError: Bool = false { didSet { didChange() }} + open var showError: Bool = false { + didSet { + if showError && isSelected { + isSelected.toggle() + } + didChange() + } + } + open override var state: UIControl.State { + get { + var state = super.state + if showError { + state.insert(.error) + } + return state + } + } + open var errorText: String? { didSet { didChange() }} open var inputId: String? { didSet { didChange() }} @@ -162,18 +179,13 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open override func setup() { super.setup() - - //add tapGesture to self - publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in - self?.sendActions(for: .touchUpInside) - }.store(in: &subscribers) - + isAccessibilityElement = true accessibilityTraits = .button addSubview(mainStackView) + mainStackView.isUserInteractionEnabled = false mainStackView.addArrangedSubview(selectorStackView) mainStackView.addArrangedSubview(errorLabel) @@ -313,45 +325,34 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //-------------------------------------------------- public let checkboxSize = CGSize(width: 20, height: 20) - private var checkboxBackgroundColorConfiguration: ErrorBinaryDisabledSurfaceColorConfiguration = { - return ErrorBinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - //error doesn't care enabled/disable - $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight - $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark - $0.error.forFalse.lightColor = VDSColor.feedbackErrorBackgroundOnlight - $0.error.forFalse.darkColor = VDSColor.feedbackErrorBackgroundOndark - } - }() - - private var checkboxBorderColorConfiguration: ErrorBinaryDisabledSurfaceColorConfiguration = { - return ErrorBinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - //error doesn't care enabled/disable - $0.error.forTrue.lightColor = VDSColor.elementsPrimaryOnlight - $0.error.forTrue.darkColor = VDSColor.elementsPrimaryOndark - $0.error.forFalse.lightColor = VDSColor.feedbackErrorOnlight - $0.error.forFalse.darkColor = VDSColor.feedbackErrorOndark - } + private var checkboxBackgroundColorConfig: ControlColorConfiguration = { + var config = ControlColorConfiguration() + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + config.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) + return config }() - private var checkboxCheckColorConfiguration: BinarySurfaceColorConfiguration = { - return BinarySurfaceColorConfiguration().with { - $0.forTrue.lightColor = VDSColor.elementsPrimaryOndark - $0.forTrue.darkColor = VDSColor.elementsPrimaryOnlight - } + private var checkboxBorderColorConfig: ControlColorConfiguration = { + var config = ControlColorConfiguration() + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) + config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) + config.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) + config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) + config.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) + return config }() - + + private var checkboxCheckColorConfig: ControlColorConfiguration = { + var config = ControlColorConfiguration() + config.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected) + config.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: [.selected, .disabled]) + return config + }() + //-------------------------------------------------- // MARK: - Checkbox View //-------------------------------------------------- @@ -364,9 +365,9 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er open func updateSelector() { //get the colors - let backgroundColor = checkboxBackgroundColorConfiguration.getColor(self) - let borderColor = checkboxBorderColorConfiguration.getColor(self) - let checkColor = checkboxCheckColorConfiguration.getColor(self) + let backgroundColor = checkboxBackgroundColorConfig.getColor(self) + let borderColor = checkboxBorderColorConfig.getColor(self) + let checkColor = checkboxCheckColorConfig.getColor(self) if let shapeLayer = shapeLayer, let sublayers = layer.sublayers, sublayers.contains(shapeLayer) { shapeLayer.removeFromSuperlayer() @@ -413,27 +414,3 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er } } } - -//-------------------------------------------------- -// MARK: - Color Class Configurations -//-------------------------------------------------- -internal class ErrorBinaryDisabledSurfaceColorConfiguration: BinaryDisabledSurfaceColorable { - typealias ObjectType = Errorable & Disabling & Surfaceable & BinaryColorable - var error = BinarySurfaceColorConfiguration() - var forTrue = DisabledSurfaceColorConfiguration() - var forFalse = DisabledSurfaceColorConfiguration() - - required init() {} - - func getColor(_ object: ObjectType) -> UIColor { - //only show error is enabled and showError == true - let showErrorColor = !object.disabled && object.showError - - if showErrorColor { - return error.getColor(object) - } else { - return getBinaryColor(object) - } - } -} - From 9fcff487520e2b3175617fa1deeb15735993a654 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 12:48:51 -0600 Subject: [PATCH 14/28] updated label to new color states Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index b1e9256f..25b5c18a 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -57,11 +57,9 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable { //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - public var textColorConfiguration: AnyColorable = DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.disabled.darkColor = VDSColor.elementsSecondaryOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark + public var textColorConfiguration: AnyColorable = ViewColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: true) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false) }.eraseToAnyColorable() //-------------------------------------------------- From 431ea81ad9a1c630280188d84ff4b91a86845221 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 13:20:58 -0600 Subject: [PATCH 15/28] refactored button Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/Button.swift | 113 +++++++++------------ 1 file changed, 50 insertions(+), 63 deletions(-) diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index d23106af..ed615958 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -39,7 +39,7 @@ open class Button: ButtonBase, Useable { open var width: CGFloat? { didSet { didChange() }} open override var textColor: UIColor { - buttonTitleColorConfiguration.getColor(self) + textColorConfiguration.getColor(self) } open override var typograpicalStyle: TypographicalStyle { @@ -49,58 +49,52 @@ open class Button: ButtonBase, Useable { //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- - private var buttonBackgroundColorConfiguration = UseableColorConfiguration().with { - $0.primary.enabled.lightColor = VDSColor.backgroundPrimaryDark - $0.primary.enabled.darkColor = VDSColor.backgroundPrimaryLight - $0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark + + // Background Color Config + private var primaryBackgroundColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.backgroundPrimaryDark, VDSColor.backgroundPrimaryLight, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + } - $0.primaryHighlighted.lightColor = VDSColor.interactiveActiveOnlight - $0.primaryHighlighted.darkColor = VDSColor.interactiveActiveOndark - - $0.secondary.enabled.lightColor = UIColor.clear - $0.secondary.enabled.darkColor = UIColor.clear - $0.secondary.disabled.lightColor = UIColor.clear - $0.secondary.disabled.darkColor = UIColor.clear + private var secondaryBackgroundColorConfiguration = ControlColorConfiguration() - $0.secondaryHighlighted.lightColor = UIColor.clear - $0.secondaryHighlighted.darkColor = UIColor.clear + private var backgroundColorConfiguration: ControlColorConfiguration{ + use == .primary ? primaryBackgroundColorConfiguration : secondaryBackgroundColorConfiguration } - private var buttonBorderColorConfiguration = UseableColorConfiguration().with { - $0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.primary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.primary.disabled.darkColor = VDSColor.interactiveDisabledOndark - - $0.primaryHighlighted.lightColor = VDSColor.elementsPrimaryOndark - $0.primaryHighlighted.darkColor = VDSColor.elementsPrimaryOnlight - - $0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark - - $0.secondaryHighlighted.lightColor = VDSColor.interactiveActiveOnlight - $0.secondaryHighlighted.darkColor = VDSColor.interactiveActiveOndark + // Border Color Config + private var primaryBorderColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .normal) + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .highlighted) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) } - private var buttonTitleColorConfiguration = UseableColorConfiguration().with { - $0.primary.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.primary.enabled.darkColor = VDSColor.elementsPrimaryOnlight - $0.primary.disabled.lightColor = VDSColor.elementsPrimaryOndark - $0.primary.disabled.darkColor = VDSColor.elementsPrimaryOnlight + private var secondaryBorderColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + } + + private var borderColorConfiguration: ControlColorConfiguration { + use == .primary ? primaryBorderColorConfiguration : secondaryBorderColorConfiguration + } - $0.primaryHighlighted.lightColor = VDSColor.elementsPrimaryOndark - $0.primaryHighlighted.darkColor = VDSColor.elementsPrimaryOnlight - - $0.secondary.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.secondary.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.secondary.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.secondary.disabled.darkColor = VDSColor.interactiveDisabledOndark - - $0.secondaryHighlighted.lightColor = VDSColor.interactiveActiveOnlight - $0.secondaryHighlighted.darkColor = VDSColor.interactiveActiveOndark + // Text Color Config + private var primaryTextColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .normal) + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .highlighted) + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .disabled) + } + + private var secondaryTextColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + } + + private var textColorConfiguration: ControlColorConfiguration { + use == .primary ? primaryTextColorConfiguration : secondaryTextColorConfiguration } //-------------------------------------------------- @@ -150,8 +144,8 @@ open class Button: ButtonBase, Useable { open override func updateView() { super.updateView() - let bgColor = buttonBackgroundColorConfiguration.getColor(self) - let borderColor = buttonBorderColorConfiguration.getColor(self) + let bgColor = backgroundColorConfiguration.getColor(self) + let borderColor = borderColorConfiguration.getColor(self) let borderWidth = use == .secondary ? 1.0 : 0.0 let buttonHeight = size.height let cornerRadius = size.cornerRadius @@ -183,27 +177,20 @@ open class Button: ButtonBase, Useable { private class UseableColorConfiguration: ObjectColorable { typealias ObjectType = Buttonable & Useable - public var primary = DisabledSurfaceColorConfiguration() - public var secondary = DisabledSurfaceColorConfiguration() - - public var primaryHighlighted = SurfaceColorConfiguration() - public var secondaryHighlighted = SurfaceColorConfiguration() + public var primary = ControlStateColorConfiguration() + public var secondary = ControlStateColorConfiguration() required public init(){} public func getColor(_ object: ObjectType) -> UIColor { - if object.isHighlighted { - return object.use == .primary ? primaryHighlighted.getColor(object) : secondaryHighlighted.getColor(object) - } else { - return object.use == .primary ? primary.getColor(object) : secondary.getColor(object) - } + return object.use == .primary ? primary.getColor(object) : secondary.getColor(object) } } } -extension ButtonSize { +fileprivate extension ButtonSize { - public var height: CGFloat { + var height: CGFloat { switch self { case .large: return 44 @@ -212,11 +199,11 @@ extension ButtonSize { } } - public var cornerRadius: CGFloat { + var cornerRadius: CGFloat { height / 2 } - public var minimumWidth: CGFloat { + var minimumWidth: CGFloat { switch self { case .large: return 76 @@ -225,7 +212,7 @@ extension ButtonSize { } } - public var edgeInsets: UIEdgeInsets { + var edgeInsets: UIEdgeInsets { var verticalPadding = 0.0 var horizontalPadding = 0.0 switch self { From 338f70ae2bd137ed3e6c2e6945e0895321a1310d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 13:23:51 -0600 Subject: [PATCH 16/28] reactored textLInk to color config Signed-off-by: Matt Bruce --- .../Buttons/TextLink/TextLink.swift | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index d3ede278..872374aa 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -32,20 +32,11 @@ open class TextLink: ButtonBase { } open override var textColor: UIColor { - textColorConfiguration.getColor(self) + textColors.getColor(self) } - - private var textColorConfiguration = HighlightDisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.disabled.darkColor = VDSColor.elementsSecondaryOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.highlighted.lightColor = VDSColor.interactiveActiveOnlight - $0.highlighted.darkColor = VDSColor.interactiveActiveOndark - - } - + private var textColors = ControlColorConfiguration() + private var height: CGFloat { switch size { case .large: @@ -80,6 +71,10 @@ open class TextLink: ButtonBase { open override func setup() { super.setup() + textColors.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) + textColors.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .disabled) + textColors.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) + if let titleLabel { addSubview(line) line.pinLeading(titleLabel.leadingAnchor) @@ -119,20 +114,3 @@ open class TextLink: ButtonBase { } } - -class HighlightDisabledSurfaceColorConfiguration: ObjectColorable { - typealias ObjectType = Buttonable - public var highlighted = SurfaceColorConfiguration() - public var disabled = SurfaceColorConfiguration() - public var enabled = SurfaceColorConfiguration() - - required public init(){} - - public func getColor(_ object: any ObjectType) -> UIColor { - if object.isHighlighted { - return highlighted.getColor(object) - } else { - return object.disabled ? disabled.getColor(object) : enabled.getColor(object) - } - } -} From 1791718c75f7926918b224fbbe2556090e0c2854 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 13:26:32 -0600 Subject: [PATCH 17/28] refactored to match classes for textColorConfiguration Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 14 +++++++------- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 12 ++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 872374aa..4f543ac5 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -32,10 +32,14 @@ open class TextLink: ButtonBase { } open override var textColor: UIColor { - textColors.getColor(self) + textColorConfiguration.getColor(self) } - private var textColors = ControlColorConfiguration() + private var textColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) + } private var height: CGFloat { switch size { @@ -70,11 +74,7 @@ open class TextLink: ButtonBase { //-------------------------------------------------- open override func setup() { super.setup() - - textColors.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) - textColors.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .disabled) - textColors.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) - + if let titleLabel { addSubview(line) line.pinLeading(titleLabel.leadingAnchor) diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index ee702981..0013c77a 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -65,14 +65,10 @@ open class TextLinkCaret: ButtonBase { textColorConfiguration.getColor(self) } - private var textColorConfiguration = HighlightDisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.disabled.darkColor = VDSColor.elementsSecondaryOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - - $0.highlighted.lightColor = VDSColor.interactiveActiveOnlight - $0.highlighted.darkColor = VDSColor.interactiveActiveOndark + private var textColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted) } //-------------------------------------------------- From 081e60ddbaffb8ac8b42c9a015c7582ac8776475 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 13:54:32 -0600 Subject: [PATCH 18/28] refactored to use color configuartion and remove tap gesture Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBox.swift | 48 ++++++++------------ VDS/Components/RadioButton/RadioButton.swift | 5 -- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index ee53b936..2ffab628 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -160,14 +160,10 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ open override func setup() { super.setup() - //add tapGesture to self - publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in - self?.sendActions(for: .touchUpInside) - }.store(in: &subscribers) - isAccessibilityElement = true accessibilityTraits = .button addSubview(selectorView) + selectorView.isUserInteractionEnabled = false selectorView.addSubview(mainStackView) @@ -289,29 +285,21 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ private var selectorCornerRadius: CGFloat = 4.0 private var selectorBorderWidthSelected: CGFloat = 2.0 private var selectorBorderWidth: CGFloat = 1.0 - - private var radioBoxBackgroundColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark - - $0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark + + private var backgroundColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal) + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .disabled) + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .selected) + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: [.selected, .disabled]) + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .highlighted) } - - private var radioBoxBorderColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark + + private var borderColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted) } //-------------------------------------------------- @@ -323,8 +311,8 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ open func updateSelector() { //get the colors - let backgroundColor = radioBoxBackgroundColorConfiguration.getColor(self) - let borderColor = radioBoxBorderColorConfiguration.getColor(self) + let backgroundColor = backgroundColorConfiguration.getColor(self) + let borderColor = borderColorConfiguration.getColor(self) let borderWidth = isSelected ? selectorBorderWidthSelected : selectorBorderWidth selectorView.backgroundColor = backgroundColor @@ -343,7 +331,7 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ open override func draw(_ layer: CALayer, in ctx: CGContext) { - let borderColor = radioBoxBorderColorConfiguration.getColor(self) + let borderColor = borderColorConfiguration.getColor(self) shapeLayer?.removeFromSuperlayer() shapeLayer = nil diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 49cc28d9..fe367b27 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -180,11 +180,6 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, open override func setup() { super.setup() - //add tapGesture to self - publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in - self?.sendActions(for: .touchUpInside) - }.store(in: &subscribers) - isAccessibilityElement = true accessibilityTraits = .button addSubview(mainStackView) From 1ba50e9d6422dd42e24eb611d129254d4590e9ff Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 14:10:41 -0600 Subject: [PATCH 19/28] updated border width for highlighted Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBox.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 2ffab628..4f7858fb 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -313,7 +313,7 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ //get the colors let backgroundColor = backgroundColorConfiguration.getColor(self) let borderColor = borderColorConfiguration.getColor(self) - let borderWidth = isSelected ? selectorBorderWidthSelected : selectorBorderWidth + let borderWidth = isSelected || isHighlighted ? selectorBorderWidthSelected : selectorBorderWidth selectorView.backgroundColor = backgroundColor selectorView.layer.borderColor = borderColor.cgColor From 3825488d0e051f7b9885c8adeadc2069a3de60ad Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 15:18:41 -0600 Subject: [PATCH 20/28] refactored vars Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 50 +++++++++----------- VDS/Components/RadioButton/RadioButton.swift | 46 ++++++++---------- VDS/Components/Toggle/Toggle.swift | 31 +++++------- 3 files changed, 54 insertions(+), 73 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 70a93588..e27a2829 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -325,33 +325,27 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er //-------------------------------------------------- public let checkboxSize = CGSize(width: 20, height: 20) - private var checkboxBackgroundColorConfig: ControlColorConfiguration = { - var config = ControlColorConfiguration() - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - config.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) - return config - }() + private var backgroundColorConfig = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) + } - private var checkboxBorderColorConfig: ControlColorConfiguration = { - var config = ControlColorConfiguration() - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) - config.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) - config.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) - return config - }() + private var borderColorConfig = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) + $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) + } - private var checkboxCheckColorConfig: ControlColorConfiguration = { - var config = ControlColorConfiguration() - config.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected) - config.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: [.selected, .disabled]) - return config - }() + private var checkColorConfig = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected) + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: [.selected, .disabled]) + } //-------------------------------------------------- // MARK: - Checkbox View @@ -365,9 +359,9 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er open func updateSelector() { //get the colors - let backgroundColor = checkboxBackgroundColorConfig.getColor(self) - let borderColor = checkboxBorderColorConfig.getColor(self) - let checkColor = checkboxCheckColorConfig.getColor(self) + let backgroundColor = backgroundColorConfig.getColor(self) + let borderColor = borderColorConfig.getColor(self) + let checkColor = checkColorConfig.getColor(self) if let shapeLayer = shapeLayer, let sublayers = layer.sublayers, sublayers.contains(shapeLayer) { shapeLayer.removeFromSuperlayer() diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index fe367b27..fed9b6fb 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -328,31 +328,25 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, public let radioButtonSize = CGSize(width: 20, height: 20) public let radioButtonSelectedSize = CGSize(width: 10, height: 10) - private var radioButtonBackgroundColorConfiguration: ControlColorConfiguration = { - var config = ControlColorConfiguration() - config.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) - return config - }() + private var backgroundColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) + } - private var radioButtonBorderColorConfiguration: ControlColorConfiguration = { - var config = ControlColorConfiguration() - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) - config.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) - config.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) - return config - }() + private var borderColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) + $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) + } - private var radioButtonCheckColorConfiguration: ControlColorConfiguration = { - var config = ControlColorConfiguration() - config.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) - config.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - return config - }() + private var checkColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) + } //-------------------------------------------------- // MARK: - RadioButton View @@ -375,9 +369,9 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, guard length > 0.0, shapeLayer == nil else { return } //get the colors - let backgroundColor = radioButtonBackgroundColorConfiguration.getColor(self) - let borderColor = radioButtonBorderColorConfiguration.getColor(self) - let radioSelectedColor = radioButtonCheckColorConfiguration.getColor(self) + let backgroundColor = backgroundColorConfiguration.getColor(self) + let borderColor = borderColorConfiguration.getColor(self) + let radioSelectedColor = checkColorConfiguration.getColor(self) selectorView.backgroundColor = backgroundColor selectorView.layer.borderColor = borderColor.cgColor diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 9f5e17e0..fbb0e04a 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -88,27 +88,20 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { public let toggleSize = CGSize(width: 52, height: 24) public let toggleContainerSize = CGSize(width: 52, height: 44) public let knobSize = CGSize(width: 20, height: 20) - - private var toggleColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.paletteGreen26 - $0.forTrue.enabled.darkColor = VDSColor.paletteGreen34 - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.enabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.forFalse.enabled.darkColor = VDSColor.paletteGray44 - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark + + private var toggleColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.paletteGray44, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.paletteGreen26, VDSColor.paletteGreen34, forState: .selected) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) } - private var knobColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forTrue.disabled.lightColor = VDSColor.paletteGray95 - $0.forTrue.disabled.darkColor = VDSColor.paletteGray44 - $0.forFalse.enabled.lightColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.disabled.lightColor = VDSColor.paletteGray95 - $0.forFalse.disabled.darkColor = VDSColor.paletteGray44 + private var knobColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: .disabled) + + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: [.selected, .disabled]) } private var typograpicalStyle: TypographicalStyle { From 66c39fb701c7d09c68f47a08cc439c555a90e640 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 15:18:54 -0600 Subject: [PATCH 21/28] updated RadioSwatch to new color config Signed-off-by: Matt Bruce --- VDS/Components/RadioSwatch/RadioSwatch.swift | 63 +++++++------------ .../RadioSwatch/RadioSwatchGroup.swift | 7 ++- 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 3e987d5a..0d9d5ac3 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -13,6 +13,15 @@ import Combine @objc(VDSRadioSwatch) public class RadioSwatch: RadioSwatchBase{ + //for groups allows "toggle" + open override func toggle() { + print("toggle: \(text)") + isSelected.toggle() + } +} + +@objc(VDSSoloRadioSwatch) +public class SolorRadioSwatch: RadioSwatchBase{ public override func initialSetup() { super.initialSetup() publisher(for: .touchUpInside) @@ -92,15 +101,10 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable open override func setup() { super.setup() - //add tapGesture to self - publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in - self?.sendActions(for: .touchUpInside) - }.store(in: &subscribers) - isAccessibilityElement = true accessibilityTraits = .button addSubview(selectorView) - + selectorView.isUserInteractionEnabled = false selectorView.addSubview(fillView) selectorView.pinToSuperView() @@ -153,6 +157,7 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable setAccessibilityHint() setAccessibilityValue(isSelected) setAccessibilityLabel(isSelected) + print("updateView: \(text)") layer.setNeedsDisplay() } @@ -165,33 +170,12 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable public let fillSize = CGSize(width: 36, height: 36) public let disabledAlpha = 0.5 - private var radioSwatchBackgroundColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forFalse.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forFalse.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forFalse.disabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forTrue.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.forTrue.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.forTrue.disabled.darkColor = VDSFormControlsColor.backgroundOndark - } - - private var radioSwatchBorderColorConfiguration = BinaryDisabledSurfaceColorConfiguration().with { - $0.forTrue.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.forTrue.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.forFalse.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.forFalse.enabled.darkColor = VDSFormControlsColor.borderOndark - $0.forTrue.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forTrue.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.forFalse.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.forFalse.disabled.darkColor = VDSColor.interactiveDisabledOndark - } - - private var radioSwatchFillBorderColorConfiguration = DisabledSurfaceColorConfiguration().with { - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark - $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.disabled.darkColor = VDSColor.interactiveDisabledOndark + private var borderColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) } //-------------------------------------------------- @@ -213,14 +197,15 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable } open override func draw(_ layer: CALayer, in ctx: CGContext) { - - let backgroundColor = radioSwatchBackgroundColorConfiguration.getColor(self) - let borderColor = isSelected ? radioSwatchBorderColorConfiguration.getColor(self) : .clear - let fillBorderColor = radioSwatchFillBorderColorConfiguration.getColor(self) + print("draw:\(text)") + let drawOuterBorder = isSelected || isHighlighted + let backgroundColor = UIColor.clear + let borderColor = isSelected ? borderColorConfiguration.getColor(self) : .clear + let fillBorderColor = borderColorConfiguration.getColor(self) selectorView.backgroundColor = backgroundColor selectorView.layer.borderColor = borderColor.cgColor selectorView.layer.cornerRadius = selectorView.bounds.width * 0.5 - selectorView.layer.borderWidth = isSelected ? selectorBorderWidth : 0 + selectorView.layer.borderWidth = drawOuterBorder ? selectorBorderWidth : 0 selectorView.layer.masksToBounds = true gradientLayer?.removeFromSuperlayer() @@ -258,7 +243,7 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable shapeLayer = nil if strikethrough { - let strikeThroughBorderColor = radioSwatchBorderColorConfiguration.getColor(self) + let strikeThroughBorderColor = borderColorConfiguration.getColor(self) let bounds = selectorView.bounds let length = max(bounds.size.height, bounds.size.width) guard length > 0.0, shapeLayer == nil else { return } diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 526df5d5..9929da63 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -16,6 +16,7 @@ public class RadioSwatchGroup: RadioSwatchGroupBase { selectedHandler?.toggle() selector.toggle() label.text = selector.text + didChange() valueChanged() } @@ -157,7 +158,11 @@ public class RadioSwatchGroupBase: SelectorGroupSe public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) let handler = selectorViews[indexPath.row] - handler.isUserInteractionEnabled = false + handler.subscribers.forEach{ $0.cancel() } + handler.subscribers.removeAll() + handler.publisher(for: .touchUpInside).sink { [weak self] handler in + self?.didSelect(selector: handler) + }.store(in: &handler.subscribers) cell.subviews.forEach { $0.removeFromSuperview() } cell.addSubview(handler) handler.pinToSuperView() From 11416b5343b315c9ecec8539696576e9c49d3223 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 17:56:49 -0600 Subject: [PATCH 22/28] 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() { } From 4393a87283454b72cfc528c0ef8c9bae288e1db1 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 17:59:05 -0600 Subject: [PATCH 23/28] removed duplicates for states Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBox.swift | 2 - VDS/Components/RadioButton/RadioButton.swift | 15 ++-- VDS/Components/RadioSwatch/RadioSwatch.swift | 1 - .../TextFields/EntryField/EntryField.swift | 70 ++++++------------- VDS/Components/Toggle/Toggle.swift | 5 +- 5 files changed, 27 insertions(+), 66 deletions(-) diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 4f7858fb..ad3846db 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -290,7 +290,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal) $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .disabled) $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .selected) - $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: [.selected, .disabled]) $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .highlighted) } @@ -298,7 +297,6 @@ open class RadioBoxBase: Control, BinaryColorable, Accessable, DataTrackable{ $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted) } diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index fed9b6fb..fd36bded 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -329,18 +329,15 @@ open class RadioButtonBase: Control, Accessable, DataTrackable, BinaryColorable, public let radioButtonSelectedSize = CGSize(width: 10, height: 10) private var backgroundColorConfiguration = ControlColorConfiguration().with { - $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) + $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: .error) } private var borderColorConfiguration = ControlColorConfiguration().with { - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) - $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) - $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted) + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.disabled]) + $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: .error) } private var checkColorConfiguration = ControlColorConfiguration().with { diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 0d9d5ac3..85a9ac9e 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -175,7 +175,6 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted) $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) } //-------------------------------------------------- diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index b45389dd..59dda2b1 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -76,28 +76,28 @@ open class EntryField: Control, Accessable { // Sizes are from InVision design specs. internal let containerSize = CGSize(width: 45, height: 45) - internal let primaryColorConfig = DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.enabled.lightColor = VDSColor.elementsPrimaryOnlight - $0.enabled.darkColor = VDSColor.elementsPrimaryOndark + internal let primaryColorConfig = ViewColorConfiguration().with { + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false) } - internal let secondaryColorConfig = DisabledSurfaceColorConfiguration().with { - $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.disabled.darkColor = VDSColor.interactiveDisabledOndark - $0.enabled.lightColor = VDSColor.elementsSecondaryOnlight - $0.enabled.darkColor = VDSColor.elementsSecondaryOndark + internal let secondaryColorConfig = ViewColorConfiguration().with { + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true) + $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.elementsSecondaryOndark, forDisabled: false) + } + + internal var backgroundColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .normal) + $0.setSurfaceColors(VDSFormControlsColor.backgroundOnlight, VDSFormControlsColor.backgroundOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: .error) + } + + internal var borderColorConfiguration = ControlColorConfiguration().with { + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOnlight, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: .error) } - internal lazy var backgroundColorConfiguration: AnyColorable = { - return getBackgroundConfig() - }() - - internal lazy var borderColorConfiguration: AnyColorable = { - return getBorderConfig() - }() - //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- @@ -162,15 +162,11 @@ open class EntryField: Control, Accessable { //-------------------------------------------------- open override func setup() { super.setup() - - //add tapGesture to self - publisher(for: UITapGestureRecognizer()).sink { [weak self] _ in - self?.sendActions(for: .touchUpInside) - }.store(in: &subscribers) - + isAccessibilityElement = true accessibilityTraits = .button addSubview(stackView) + stackView.isUserInteractionEnabled = false //create the wrapping view heightConstraint = containerView.heightAnchor.constraint(greaterThanOrEqualToConstant: containerSize.height) @@ -199,32 +195,6 @@ open class EntryField: Control, Accessable { return containerView } - open func getBackgroundConfig() -> AnyColorable { - return ErrorDisabledSurfaceColorConfiguration().with { - $0.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.disabled.darkColor = VDSFormControlsColor.backgroundOndark - - //error doesn't care enabled/disable - $0.error.lightColor = VDSColor.feedbackErrorBackgroundOnlight - $0.error.darkColor = VDSColor.feedbackErrorBackgroundOndark - }.eraseToAnyColorable() - } - - open func getBorderConfig() -> AnyColorable { - return ErrorDisabledSurfaceColorConfiguration().with { - $0.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.enabled.darkColor = VDSFormControlsColor.borderOnlight - $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.disabled.darkColor = VDSColor.interactiveDisabledOndark - - //error doesn't care enabled/disable - $0.error.lightColor = VDSColor.feedbackErrorOnlight - $0.error.darkColor = VDSColor.feedbackErrorOndark - }.eraseToAnyColorable() - } - open func getToolTipView() -> UIView? { guard let tooltipTitle, let tooltipContent else { return nil diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index fbb0e04a..775768d3 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -93,15 +93,12 @@ open class ToggleBase: Control, Accessable, DataTrackable, BinaryColorable { $0.setSurfaceColors(VDSColor.elementsSecondaryOnlight, VDSColor.paletteGray44, forState: .normal) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) $0.setSurfaceColors(VDSColor.paletteGreen26, VDSColor.paletteGreen34, forState: .selected) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) } private var knobColorConfiguration = ControlColorConfiguration().with { $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .normal) - $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: .disabled) - + $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: .disabled) $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOndark, forState: .selected) - $0.setSurfaceColors(VDSColor.paletteGray95, VDSColor.paletteGray44, forState: [.selected, .disabled]) } private var typograpicalStyle: TypographicalStyle { From 139d8fbce9127f383758aaa9685e7349a5aa3a4c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 17:59:31 -0600 Subject: [PATCH 24/28] added success updated config Signed-off-by: Matt Bruce --- .../TextEntryField/TextEntryField.swift | 33 ++----------------- VDS/Extensions/UIControl.swift | 2 +- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift index 6d8b8742..5d9866fe 100644 --- a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift +++ b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift @@ -90,6 +90,9 @@ open class TextEntryFieldBase: EntryField { successLabel.textColorConfiguration = primaryColorConfig.eraseToAnyColorable() + backgroundColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessBackgroundOnlight, VDSColor.feedbackSuccessBackgroundOndark, forState: .success) + borderColorConfiguration.setSurfaceColors(VDSColor.feedbackSuccessOnlight, VDSColor.feedbackSuccessOndark, forState: .success) + } public override func reset() { @@ -109,36 +112,6 @@ open class TextEntryFieldBase: EntryField { return containerStackView } - open override func getBackgroundConfig() -> AnyColorable { - return TextEntryFieldColorConfiguration().with { - $0.enabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.enabled.darkColor = VDSFormControlsColor.backgroundOndark - $0.disabled.lightColor = VDSFormControlsColor.backgroundOnlight - $0.disabled.darkColor = VDSFormControlsColor.backgroundOndark - - //error/success doesn't care enabled/disable - $0.error.lightColor = VDSColor.feedbackErrorBackgroundOnlight - $0.error.darkColor = VDSColor.feedbackErrorBackgroundOndark - $0.success.lightColor = VDSColor.feedbackSuccessBackgroundOnlight - $0.success.darkColor = VDSColor.feedbackSuccessBackgroundOndark - }.eraseToAnyColorable() - } - - open override func getBorderConfig() -> AnyColorable { - return TextEntryFieldColorConfiguration().with { - $0.enabled.lightColor = VDSFormControlsColor.borderOnlight - $0.enabled.darkColor = VDSFormControlsColor.borderOnlight - $0.disabled.lightColor = VDSColor.interactiveDisabledOnlight - $0.disabled.darkColor = VDSColor.interactiveDisabledOndark - - //error/success doesn't care enabled/disable - $0.error.lightColor = VDSColor.feedbackErrorOnlight - $0.error.darkColor = VDSColor.feedbackErrorOndark - $0.success.lightColor = VDSColor.feedbackSuccessOnlight - $0.success.darkColor = VDSColor.feedbackSuccessOndark - }.eraseToAnyColorable() - } - //-------------------------------------------------- // MARK: - State //-------------------------------------------------- diff --git a/VDS/Extensions/UIControl.swift b/VDS/Extensions/UIControl.swift index abccd3f3..ce32dcad 100644 --- a/VDS/Extensions/UIControl.swift +++ b/VDS/Extensions/UIControl.swift @@ -10,5 +10,5 @@ import UIKit extension UIControl.State { public static var error = UIControl.State(rawValue: 1 << 16) - public static var success = UIControl.State(rawValue: 1 << 16) + public static var success = UIControl.State(rawValue: 1 << 17) } From 5b754502da1378a3149a42c9e3c110203e12a6b6 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 17:59:40 -0600 Subject: [PATCH 25/28] updated checkbox logic Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index e27a2829..54b8e76b 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -124,13 +124,16 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er didChange() } } - - open var showError: Bool = false { - didSet { - if showError && isSelected { - isSelected.toggle() + + var _showError: Bool = false + open var showError: Bool { + get { _showError } + set { + if !isSelected && _showError != newValue { + _showError = newValue + didChange() } - didChange() + print("checkbox showError:\(_showError)") } } @@ -326,20 +329,17 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er public let checkboxSize = CGSize(width: 20, height: 20) private var backgroundColorConfig = ControlColorConfiguration().with { - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: [.error]) + $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: .error) } private var borderColorConfig = ControlColorConfiguration().with { - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected]) - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.highlighted]) - $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.error, .highlighted]) - $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: [.normal]) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.normal, .disabled]) - $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.error, .disabled]) - $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: [.error]) + $0.setSurfaceColors(VDSFormControlsColor.borderOnlight, VDSFormControlsColor.borderOndark, forState: .normal) + $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: .disabled) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .highlighted) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.feedbackErrorOnlight, VDSColor.feedbackErrorOndark, forState: .error) } private var checkColorConfig = ControlColorConfiguration().with { From bc4f0e8915f4192caaff092dbed8e6ba9c4a956f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 18:06:11 -0600 Subject: [PATCH 26/28] added selected,highlighted Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 54b8e76b..5c9cd4a0 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -330,6 +330,7 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er private var backgroundColorConfig = ControlColorConfiguration().with { $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: .selected) + $0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forState: [.selected,.highlighted]) $0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forState: [.selected, .disabled]) $0.setSurfaceColors(VDSColor.feedbackErrorBackgroundOnlight, VDSColor.feedbackErrorBackgroundOndark, forState: .error) } @@ -345,6 +346,7 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er private var checkColorConfig = ControlColorConfiguration().with { $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: .selected) $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: [.selected, .disabled]) + $0.setSurfaceColors(VDSColor.elementsPrimaryOndark, VDSColor.elementsPrimaryOnlight, forState: [.selected, .highlighted]) } //-------------------------------------------------- From 0842998c97d900454801a01c1727f9b1d594ae61 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 18:10:52 -0600 Subject: [PATCH 27/28] fixed logic in showError/showSuccess Signed-off-by: Matt Bruce --- .../TextEntryField/TextEntryField.swift | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift index 5d9866fe..92cf1cc6 100644 --- a/VDS/Components/TextFields/TextEntryField/TextEntryField.swift +++ b/VDS/Components/TextFields/TextEntryField/TextEntryField.swift @@ -52,8 +52,28 @@ open class TextEntryFieldBase: EntryField { open var type: TextEntryFieldType = .text { didSet { didChange() }} - open var showSuccess: Bool = false { didSet { didChange() }} - + var _showError: Bool = false + open override var showError: Bool { + get { _showError } + set { + if !showSuccess && _showError != newValue { + _showError = newValue + didChange() + } + } + } + + var _showSuccess: Bool = false + open var showSuccess: Bool { + get { _showSuccess } + set { + if !showError && _showSuccess != newValue { + _showSuccess = newValue + didChange() + } + } + } + open override var state: UIControl.State { get { var state = super.state From 84ccbac762369b542ebcb2955b3c75c10d6bdfd4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Dec 2022 18:15:16 -0600 Subject: [PATCH 28/28] removed prints Signed-off-by: Matt Bruce --- VDS/Components/Checkbox/Checkbox.swift | 1 - VDS/Components/RadioSwatch/RadioSwatch.swift | 3 --- 2 files changed, 4 deletions(-) diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 5c9cd4a0..97bd6361 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -133,7 +133,6 @@ open class CheckboxBase: Control, Accessable, DataTrackable, BinaryColorable, Er _showError = newValue didChange() } - print("checkbox showError:\(_showError)") } } diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 85a9ac9e..0ee397a7 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -15,7 +15,6 @@ import Combine public class RadioSwatch: RadioSwatchBase{ //for groups allows "toggle" open override func toggle() { - print("toggle: \(text)") isSelected.toggle() } } @@ -157,7 +156,6 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable setAccessibilityHint() setAccessibilityValue(isSelected) setAccessibilityLabel(isSelected) - print("updateView: \(text)") layer.setNeedsDisplay() } @@ -196,7 +194,6 @@ open class RadioSwatchBase: Control, Accessable, DataTrackable, BinaryColorable } open override func draw(_ layer: CALayer, in ctx: CGContext) { - print("draw:\(text)") let drawOuterBorder = isSelected || isHighlighted let backgroundColor = UIColor.clear let borderColor = isSelected ? borderColorConfiguration.getColor(self) : .clear