From 5811fa7a01e9bf90ab560d7759f6e1b7fd732da3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 13:03:34 -0500 Subject: [PATCH 1/2] 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 } From 7f461e72e9556d7fd13f15bc75106cc942026a8c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 14:55:11 -0500 Subject: [PATCH 2/2] removed disabled Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 2 +- VDS/Classes/Control.swift | 12 +----------- VDS/Classes/SelectorGroupHandlerBase.swift | 10 +--------- VDS/Classes/SelectorItemBase.swift | 6 +----- VDS/Classes/View.swift | 12 +----------- VDS/Components/Badge/Badge.swift | 1 - .../BadgeIndicator/BadgeIndicator.swift | 1 - VDS/Components/Buttons/Button/ButtonBase.swift | 14 ++------------ .../Buttons/ButtonGroup/ButtonGroup.swift | 10 ---------- VDS/Components/Checkbox/Checkbox.swift | 2 +- VDS/Components/Checkbox/CheckboxGroup.swift | 3 +-- VDS/Components/Label/Label.swift | 14 ++------------ VDS/Components/RadioBox/RadioBoxGroup.swift | 3 +-- VDS/Components/RadioBox/RadioBoxItem.swift | 3 --- .../RadioButton/RadioButtonGroup.swift | 3 +-- VDS/Components/RadioSwatch/RadioSwatch.swift | 8 ++++---- .../RadioSwatch/RadioSwatchGroup.swift | 16 ++-------------- VDS/Components/Tabs/TabsContainer.swift | 1 - .../TextFields/EntryField/EntryField.swift | 7 ++----- .../TextFields/InputField/InputField.swift | 5 ++--- .../TextFields/TextArea/TextArea.swift | 2 +- VDS/Components/Toggle/Toggle.swift | 3 +-- VDS/Components/Toggle/ToggleView.swift | 2 +- .../Tooltip/TrailingTooltipLabel.swift | 1 - VDS/Protocols/Disabling.swift | 10 +++++----- VDS/Protocols/ViewProtocol.swift | 2 +- 26 files changed, 32 insertions(+), 121 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 9fc40c68..4e1e8952 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 & Enabling + public typealias ObjectType = Surfaceable & Enabling public var keyColors: [KeyColorConfiguration] = [] public required init() { } diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 1acca2d5..73ea2f82 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -40,16 +40,6 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Current Surface and this is used to pass down to child objects that implement Surfacable open var surface: Surface = .light { didSet { setNeedsUpdate() } } - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - /// Whether the Control is selected or not. open override var isSelected: Bool { didSet { setNeedsUpdate() } } @@ -140,7 +130,7 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } //-------------------------------------------------- diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 3136a234..122dea1b 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -28,15 +28,7 @@ open class SelectorGroupHandlerBase: Control, Changeable { } } - /// Whether this object is disabled or not - override open var disabled: Bool { - didSet { - selectorViews.forEach { handler in - handler.disabled = disabled - } - } - } - + /// Whether this object is enabled or not override open var isEnabled: Bool { didSet { selectorViews.forEach { handler in diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index 3b057e74..e7942bdb 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -33,7 +33,7 @@ open class SelectorItemBase: Control, Errorable, // MARK: - Private Properties //-------------------------------------------------- private var shouldShowError: Bool { - guard showError && !disabled && errorText?.isEmpty == false else { return false } + guard showError && isEnabled && errorText?.isEmpty == false else { return false } return true } @@ -191,7 +191,6 @@ open class SelectorItemBase: Control, Errorable, selectorView.showError = showError selectorView.isSelected = isSelected selectorView.isHighlighted = isHighlighted - selectorView.disabled = disabled selectorView.isEnabled = isEnabled selectorView.surface = surface } @@ -238,7 +237,6 @@ open class SelectorItemBase: Control, Errorable, //top label if let labelText { label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled label.attributes = labelTextAttributes label.text = labelText @@ -254,7 +252,6 @@ open class SelectorItemBase: Control, Errorable, if let childText { childLabel.text = childText childLabel.surface = surface - childLabel.disabled = disabled childLabel.isEnabled = isEnabled childLabel.attributes = childTextAttributes childLabel.isHidden = false @@ -279,7 +276,6 @@ open class SelectorItemBase: Control, Errorable, if let errorText, shouldShowError { errorLabel.text = errorText errorLabel.surface = surface - errorLabel.disabled = disabled errorLabel.isEnabled = isEnabled mainStackView.spacing = 8 errorLabel.isHidden = false diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index 8f1e40a3..66866fb1 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -33,16 +33,6 @@ open class View: UIView, ViewProtocol, UserInfoable { /// Current Surface and this is used to pass down to child objects that implement Surfacable open var surface: Surface = .light { didSet { setNeedsUpdate() } } - /// Whether this object is disabled or not. - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - /// Whether the View is enabled or not. open var isEnabled: Bool = true { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -101,7 +91,7 @@ open class View: UIView, ViewProtocol, UserInfoable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } } diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 2c4da9fe..ef7569fb 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -157,7 +157,6 @@ open class Badge: View { label.numberOfLines = numberOfLines 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 043624be..c71b4f31 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -341,7 +341,6 @@ open class BadgeIndicator: View { label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() label.text = getText() label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled label.sizeToFit() setNeedsLayout() diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 66b208b8..a8e983ba 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, Enabling { +public protocol Buttonable: UIControl, Surfaceable, Enabling { var availableSizes: [ButtonSize] { get } var text: String? { get set } var intrinsicContentSize: CGSize { get } @@ -83,16 +83,6 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab } } } - - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } /// Whether the Control is enabled or not. open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -144,7 +134,7 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab open func reset() { shouldUpdateView = false surface = .light - disabled = false + isEnabled = true text = nil accessibilityCustomActions = [] shouldUpdateView = true diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 972e8e65..c0472fe6 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -93,16 +93,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Whether this object is disabled or not - override open var disabled: Bool { - didSet { - buttons.forEach { button in - var b = button - b.disabled = disabled - } - } - } - /// Whether this object is enabled or not override open var isEnabled: Bool { didSet { diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 9c22e616..1179e58e 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -99,7 +99,7 @@ open class Checkbox: SelectorBase { shapeLayer?.removeAllAnimations() - if isAnimated && !disabled && !isHighlighted { + if isAnimated && isEnabled && !isHighlighted { let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd") animateStrokeEnd.timingFunction = CAMediaTimingFunction(name: .linear) animateStrokeEnd.duration = 0.3 diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 69cde8e3..c5cd4d9e 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -40,7 +40,6 @@ open class CheckboxGroup: SelectorGroupHandlerBase { if let selectorModels { 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 @@ -111,7 +110,7 @@ open class CheckboxGroup: SelectorGroupHandlerBase { } extension CheckboxGroup { - public struct CheckboxModel : Surfaceable, Disabling, Initable, FormFieldable, Errorable { + public struct CheckboxModel : Surfaceable, Initable, FormFieldable, Errorable { /// Whether this object is disabled or not public var disabled: Bool diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 46b8bb39..98d2f57b 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -54,17 +54,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { setNeedsUpdate() } } - - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - + /// Whether the View is enabled or not. open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -123,7 +113,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { open func reset() { shouldUpdateView = false surface = .light - disabled = false + isEnabled = true attributes = nil textStyle = .defaultStyle textPosition = .left diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index a6d2ec06..2443bc74 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -43,7 +43,6 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { $0.subTextAttributes = model.subTextAttributes $0.subTextRight = model.subText $0.subTextRightAttributes = model.subTextAttributes - $0.disabled = model.disabled $0.isEnabled = !model.disabled $0.inputId = model.inputId $0.isSelected = model.selected @@ -107,7 +106,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { } extension RadioBoxGroup { - public struct RadioBoxModel: Surfaceable, Initable, Disabling, FormFieldable { + public struct RadioBoxModel: Surfaceable, Initable, FormFieldable { /// Whether this object is disabled or not public var disabled: Bool /// Current Surface and this is used to pass down to child objects that implement Surfacable diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 4b33d5c0..b9f16b5e 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -187,7 +187,6 @@ open class RadioBoxItem: Control, Changeable { //text label textLabel.text = text textLabel.surface = surface - textLabel.disabled = disabled textLabel.isEnabled = isEnabled textLabel.attributes = textAttributes @@ -195,7 +194,6 @@ open class RadioBoxItem: Control, Changeable { if let subText { subTextLabel.text = subText subTextLabel.surface = surface - subTextLabel.disabled = disabled subTextLabel.isEnabled = isEnabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false @@ -211,7 +209,6 @@ open class RadioBoxItem: Control, Changeable { if let subTextRight { 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 863899b8..d16d1835 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -35,7 +35,6 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { if let selectorModels { 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 @@ -115,7 +114,7 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { } extension RadioButtonGroup { - public struct RadioButtonModel: Surfaceable, Disabling, Initable, FormFieldable, Errorable { + public struct RadioButtonModel: Surfaceable, Initable, FormFieldable, Errorable { /// Whether this object is disabled or not public var disabled: Bool diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 1658482d..9f61b4ec 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -176,13 +176,13 @@ open class RadioSwatch: Control { var fillColorBackground: UIColor = .clear if let fillImage { - fillView.image = disabled ? fillImage.image(alpha: disabledAlpha) : fillImage + fillView.image = !isEnabled ? fillImage.image(alpha: disabledAlpha) : fillImage } else { fillView.image = nil if let primary = primaryColor, let secondary = secondaryColor { - let firstColor = disabled ? primary.withAlphaComponent(disabledAlpha) : primary - let secondColor = disabled ? secondary.withAlphaComponent(disabledAlpha) : secondary + let firstColor = !isEnabled ? primary.withAlphaComponent(disabledAlpha) : primary + let secondColor = !isEnabled ? secondary.withAlphaComponent(disabledAlpha) : secondary let gradient = CAGradientLayer() gradientLayer = gradient gradient.frame = fillView.bounds @@ -195,7 +195,7 @@ open class RadioSwatch: Control { } } - fillView.backgroundColor = disabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground + fillView.backgroundColor = !isEnabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground fillView.layer.borderColor = fillBorderColor.cgColor fillView.layer.cornerRadius = fillView.bounds.width * 0.5 fillView.layer.borderWidth = selectorBorderWidth diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 91ab2413..0f455451 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -32,7 +32,6 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo $0.primaryColor = model.primaryColor $0.secondaryColor = model.secondaryColor $0.strikethrough = model.strikethrough - $0.disabled = model.disabled $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId @@ -72,17 +71,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Whether this object is disabled or not - override public var disabled: Bool { - didSet { - for selector in selectorViews { - selector.disabled = disabled - } - collectionView.reloadData() - } - } - - /// Whether this object is disabled or not + /// Whether this object is enabled or not override public var isEnabled: Bool { didSet { for selector in selectorViews { @@ -144,7 +133,6 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo label.textStyle = .bodySmall label.text = selectedHandler?.text ?? " " label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled collectionView.reloadData() } @@ -206,7 +194,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo } extension RadioSwatchGroup { - public struct RadioSwatchModel: Surfaceable, Disabling, Initable { + public struct RadioSwatchModel: Surfaceable, Initable { /// Whether this object is disabled or not public var disabled: Bool = false /// Current Surface and this is used to pass down to child objects that implement Surfacable diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 39c92d4d..0b8db53d 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -163,7 +163,6 @@ open class TabsContainer: View { contentViewWidthConstraint?.isActive = true tabMenu.surface = surface - tabMenu.disabled = disabled tabMenu.isEnabled = isEnabled tabMenu.orientation = orientation tabMenu.borderLine = borderLine diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index dab18d80..933d53ee 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -283,7 +283,7 @@ open class EntryField: Control, Changeable { //dealing with the "Optional" addition to the text if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") { - if !disabled { + if isEnabled { let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2, length: 8, color: VDSColor.elementsSecondaryOnlight) @@ -301,7 +301,6 @@ open class EntryField: Control, Changeable { titleLabel.text = updatedLabelText titleLabel.attributes = attributes titleLabel.surface = surface - titleLabel.disabled = disabled titleLabel.isEnabled = isEnabled } @@ -309,13 +308,12 @@ open class EntryField: Control, Changeable { if showError, let errorText { errorLabel.text = errorText errorLabel.surface = surface - errorLabel.disabled = disabled errorLabel.isEnabled = isEnabled errorLabel.isHidden = false icon.name = .error icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true errorLabel.isHidden = true @@ -327,7 +325,6 @@ open class EntryField: Control, Changeable { if let helperText { helperLabel.text = helperText helperLabel.surface = surface - helperLabel.disabled = disabled helperLabel.isEnabled = isEnabled helperLabel.isHidden = false } else { diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 2fe4d2e9..eb7ca72a 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -165,7 +165,7 @@ open class InputField: EntryField, UITextFieldDelegate { open override func updateView() { super.updateView() - textField.isEnabled = !disabled + textField.isEnabled = isEnabled textField.textColor = textFieldTextColorConfiguration.getColor(self) //show error or success @@ -175,14 +175,13 @@ open class InputField: EntryField, UITextFieldDelegate { } else if showSuccess, let successText { successLabel.text = successText successLabel.surface = surface - successLabel.disabled = disabled successLabel.isEnabled = isEnabled successLabel.isHidden = false errorLabel.isHidden = true icon.name = .checkmarkAlt icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true successLabel.isHidden = true diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index eb7e45e0..6d94399f 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -95,7 +95,7 @@ open class TextArea: EntryField { open override func updateView() { super.updateView() - textView.isEditable = !disabled + textView.isEditable = isEnabled textView.textColor = textViewTextColorConfiguration.getColor(self) //set the width constraints diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 1d9b0599..9f030d90 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -179,6 +179,7 @@ open class Toggle: Control, Changeable { super.reset() shouldUpdateView = false label.reset() + isEnabled = true isOn = false isAnimated = true showText = false @@ -199,7 +200,6 @@ open class Toggle: Control, Changeable { updateLabel() toggleView.surface = surface - toggleView.disabled = disabled toggleView.isEnabled = isEnabled toggleView.isOn = isOn } @@ -235,7 +235,6 @@ open class Toggle: Control, Changeable { label.textStyle = textStyle label.text = statusText label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled switch textPosition { case .left: diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 018c887d..58292cc4 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -215,7 +215,7 @@ open class ToggleView: Control, Changeable { shadowLayer1.backgroundColor = knobColor.cgColor shadowLayer2.backgroundColor = knobColor.cgColor - if disabled || !isAnimated { + if !isEnabled || !isAnimated { toggleView.backgroundColor = toggleColor knobView.backgroundColor = knobColor constrainKnob() diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index d119333e..0555a5a9 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -71,7 +71,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.textPosition = labelTextPosition label.attributes = labelAttributes label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled //add tooltip diff --git a/VDS/Protocols/Disabling.swift b/VDS/Protocols/Disabling.swift index 51a5bb50..12b938a7 100644 --- a/VDS/Protocols/Disabling.swift +++ b/VDS/Protocols/Disabling.swift @@ -7,8 +7,8 @@ import Foundation -/// Any object that can be disabled, which may change the appearance -public protocol Disabling { - /// Whether this object is disabled or not - var disabled: Bool { get set } -} +///// Any object that can be disabled, which may change the appearance +//public protocol Disabling { +// /// Whether this object is disabled or not +// var disabled: Bool { get set } +//} diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index cf5e26dd..f6d878c3 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, Enabling, Surfaceable { +public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surfaceable { /// Set of Subscribers for any Publishers for this Control. var subscribers: Set { get set }