From 5811fa7a01e9bf90ab560d7759f6e1b7fd732da3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 13:03:34 -0500 Subject: [PATCH] added isEnabled for setters where disabled is set Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 4 ++-- VDS/Classes/SelectorGroupHandlerBase.swift | 8 ++++++++ VDS/Classes/SelectorItemBase.swift | 4 ++++ VDS/Components/Badge/Badge.swift | 1 + .../BadgeIndicator/BadgeIndicator.swift | 1 + VDS/Components/Buttons/Button/ButtonBase.swift | 2 +- .../Buttons/ButtonGroup/ButtonGroup.swift | 10 ++++++++++ VDS/Components/Checkbox/CheckboxGroup.swift | 1 + VDS/Components/RadioBox/RadioBoxGroup.swift | 1 + VDS/Components/RadioBox/RadioBoxItem.swift | 3 +++ VDS/Components/RadioButton/RadioButtonGroup.swift | 1 + VDS/Components/RadioSwatch/RadioSwatchGroup.swift | 15 ++++++++++++++- VDS/Components/Tabs/TabsContainer.swift | 1 + .../TextFields/EntryField/EntryField.swift | 4 +++- .../TextFields/InputField/InputField.swift | 1 + VDS/Components/Toggle/Toggle.swift | 2 ++ VDS/Components/Tooltip/TrailingTooltipLabel.swift | 3 ++- VDS/Protocols/ViewProtocol.swift | 2 +- 18 files changed, 57 insertions(+), 7 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 317a16d3..9fc40c68 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -143,7 +143,7 @@ public class ControlColorConfiguration: KeyColorConfigurable { ///Meant to be used with any object that implements Surfaceable and Disabling. More than likely this is any View. public class ViewColorConfiguration: KeyColorConfigurable { public typealias KeyType = Bool - public typealias ObjectType = Surfaceable & Disabling + public typealias ObjectType = Surfaceable & Disabling & Enabling public var keyColors: [KeyColorConfiguration] = [] public required init() { } @@ -161,7 +161,7 @@ public class ViewColorConfiguration: KeyColorConfigurable { /// - Parameter object: Object that implements Surfaceable and Disabling /// - Returns: UIColor correspoding to either true/false for the disabled state and surface public func getColor(_ object: ObjectType) -> UIColor { - if let keyColor = keyColors.first(where: {$0.key == object.disabled }) { + if let keyColor = keyColors.first(where: {$0.key == !object.isEnabled }) { return keyColor.surfaceConfig.getColor(object) } else { return .clear //default diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 868276ba..3136a234 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -37,6 +37,14 @@ open class SelectorGroupHandlerBase: Control, Changeable { } } + override open var isEnabled: Bool { + didSet { + selectorViews.forEach { handler in + handler.isEnabled = isEnabled + } + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable. override open var surface: Surface { didSet { diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index b7c916b2..3b057e74 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -192,6 +192,7 @@ open class SelectorItemBase: Control, Errorable, selectorView.isSelected = isSelected selectorView.isHighlighted = isHighlighted selectorView.disabled = disabled + selectorView.isEnabled = isEnabled selectorView.surface = surface } @@ -238,6 +239,7 @@ open class SelectorItemBase: Control, Errorable, if let labelText { label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled label.attributes = labelTextAttributes label.text = labelText label.isHidden = false @@ -253,6 +255,7 @@ open class SelectorItemBase: Control, Errorable, childLabel.text = childText childLabel.surface = surface childLabel.disabled = disabled + childLabel.isEnabled = isEnabled childLabel.attributes = childTextAttributes childLabel.isHidden = false @@ -277,6 +280,7 @@ open class SelectorItemBase: Control, Errorable, errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled + errorLabel.isEnabled = isEnabled mainStackView.spacing = 8 errorLabel.isHidden = false } else { diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index ac8c0e94..2c4da9fe 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -158,5 +158,6 @@ open class Badge: View { label.text = text label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled } } diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index acf43519..043624be 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -342,6 +342,7 @@ open class BadgeIndicator: View { label.text = getText() label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled label.sizeToFit() setNeedsLayout() layoutIfNeeded() diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 2f1e23b5..66b208b8 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -11,7 +11,7 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public protocol Buttonable: UIControl, Surfaceable, Disabling { +public protocol Buttonable: UIControl, Surfaceable, Disabling, Enabling { var availableSizes: [ButtonSize] { get } var text: String? { get set } var intrinsicContentSize: CGSize { get } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 836ba6da..972e8e65 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -103,6 +103,16 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega } } + /// Whether this object is enabled or not + override open var isEnabled: Bool { + didSet { + buttons.forEach { button in + var b = button + b.isEnabled = isEnabled + } + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable override open var surface: Surface { didSet { diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 763a18ab..69cde8e3 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -41,6 +41,7 @@ open class CheckboxGroup: SelectorGroupHandlerBase { selectorViews = selectorModels.enumerated().map { index, model in return CheckboxItem().with { $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 209a5769..a6d2ec06 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -44,6 +44,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { $0.subTextRight = model.subText $0.subTextRightAttributes = model.subTextAttributes $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.inputId = model.inputId $0.isSelected = model.selected } diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index e789785e..4b33d5c0 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -188,6 +188,7 @@ open class RadioBoxItem: Control, Changeable { textLabel.text = text textLabel.surface = surface textLabel.disabled = disabled + textLabel.isEnabled = isEnabled textLabel.attributes = textAttributes //subText label @@ -195,6 +196,7 @@ open class RadioBoxItem: Control, Changeable { subTextLabel.text = subText subTextLabel.surface = surface subTextLabel.disabled = disabled + subTextLabel.isEnabled = isEnabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false @@ -210,6 +212,7 @@ open class RadioBoxItem: Control, Changeable { subTextRightLabel.text = subTextRight subTextRightLabel.surface = surface subTextRightLabel.disabled = disabled + subTextRightLabel.isEnabled = isEnabled subTextRightLabel.attributes = subTextRightAttributes subTextRightLabel.isHidden = false diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 4298f827..863899b8 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -36,6 +36,7 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { selectorViews = selectorModels.enumerated().map { index, model in return RadioButtonItem().with { $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 25827392..91ab2413 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -33,6 +33,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo $0.secondaryColor = model.secondaryColor $0.strikethrough = model.strikethrough $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value @@ -80,6 +81,17 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo collectionView.reloadData() } } + + /// Whether this object is disabled or not + override public var isEnabled: Bool { + didSet { + for selector in selectorViews { + selector.isEnabled = isEnabled + } + collectionView.reloadData() + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable override public var surface: Surface { didSet { @@ -133,6 +145,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo label.text = selectedHandler?.text ?? " " label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled collectionView.reloadData() } @@ -151,7 +164,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo // MARK: - UICollectionViewDelegate //-------------------------------------------------- open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { - return !selectorViews[indexPath.row].disabled + return selectorViews[indexPath.row].isEnabled } open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 58745a5b..39c92d4d 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -164,6 +164,7 @@ open class TabsContainer: View { tabMenu.surface = surface tabMenu.disabled = disabled + tabMenu.isEnabled = isEnabled tabMenu.orientation = orientation tabMenu.borderLine = borderLine tabMenu.fillContainer = fillContainer diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 819e805e..dab18d80 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -302,7 +302,7 @@ open class EntryField: Control, Changeable { titleLabel.attributes = attributes titleLabel.surface = surface titleLabel.disabled = disabled - + titleLabel.isEnabled = isEnabled } open func updateErrorLabel(){ @@ -310,6 +310,7 @@ open class EntryField: Control, Changeable { errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled + errorLabel.isEnabled = isEnabled errorLabel.isHidden = false icon.name = .error icon.color = VDSColor.paletteBlack @@ -327,6 +328,7 @@ open class EntryField: Control, Changeable { helperLabel.text = helperText helperLabel.surface = surface helperLabel.disabled = disabled + helperLabel.isEnabled = isEnabled helperLabel.isHidden = false } else { helperLabel.isHidden = true diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index f6df3da8..2fe4d2e9 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -176,6 +176,7 @@ open class InputField: EntryField, UITextFieldDelegate { successLabel.text = successText successLabel.surface = surface successLabel.disabled = disabled + successLabel.isEnabled = isEnabled successLabel.isHidden = false errorLabel.isHidden = true icon.name = .checkmarkAlt diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index cfdef454..1d9b0599 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -200,6 +200,7 @@ open class Toggle: Control, Changeable { updateLabel() toggleView.surface = surface toggleView.disabled = disabled + toggleView.isEnabled = isEnabled toggleView.isOn = isOn } @@ -235,6 +236,7 @@ open class Toggle: Control, Changeable { label.text = statusText label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled switch textPosition { case .left: NSLayoutConstraint.deactivate(rightConstraints) diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 4a1be607..d119333e 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -72,7 +72,8 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.attributes = labelAttributes label.surface = surface label.disabled = disabled - + label.isEnabled = isEnabled + //add tooltip if let labelText, !labelText.isEmpty { label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView)) diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index 47b9f9b0..cf5e26dd 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import Combine -public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Surfaceable { +public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Enabling, Surfaceable { /// Set of Subscribers for any Publishers for this Control. var subscribers: Set { get set }