diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 1acca2d5..cad40596 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() } } @@ -79,7 +69,12 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { } /// Whether the Control is enabled or not. - open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open override var isEnabled: Bool { + didSet { + setNeedsUpdate() + //isUserInteractionEnabled = isEnabled + } + } //-------------------------------------------------- // MARK: - Initializers @@ -140,7 +135,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 5a08d9a4..5d858bde 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -27,22 +27,11 @@ 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 - handler.isEnabled = isEnabled - } + selectorViews.forEach { $0.isEnabled = isEnabled } } } diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index 9d90507f..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,7 @@ open class SelectorItemBase: Control, Errorable, selectorView.showError = showError selectorView.isSelected = isSelected selectorView.isHighlighted = isHighlighted - selectorView.disabled = disabled + selectorView.isEnabled = isEnabled selectorView.surface = surface } diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index 8f1e40a3..4697f88b 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -44,7 +44,7 @@ open class View: UIView, ViewProtocol, UserInfoable { } /// Whether the View is enabled or not. - open var isEnabled: Bool = true { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open var isEnabled: Bool = true { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Initializers @@ -101,7 +101,7 @@ open class View: UIView, ViewProtocol, UserInfoable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } } diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 8142b4da..58772cd4 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -85,7 +85,7 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab } /// Whether the Control is enabled or not. - open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open override var isEnabled: Bool { didSet { setNeedsUpdate() } } open var textStyle: TextStyle { .defaultStyle } 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 763a18ab..56e0c0aa 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -40,7 +40,7 @@ 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 $0.value = model.value diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 437eea9d..e552bb2e 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -56,7 +56,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { } /// Whether the View is enabled or not. - open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open override var isEnabled: Bool { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Configuration Properties diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 209a5769..19bdfd61 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -43,7 +43,7 @@ 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 } diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 4298f827..29842ad2 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -35,7 +35,7 @@ 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 $0.value = model.value 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 6ee3e4b9..83789f04 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -32,7 +32,7 @@ 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 $0.value = model.value @@ -72,14 +72,13 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo // MARK: - Overrides //-------------------------------------------------- /// Whether this object is disabled or not - override public var disabled: Bool { + override public var isEnabled: Bool { didSet { - for selector in selectorViews { - selector.disabled = disabled - } + selectorViews.forEach { $0.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 { @@ -151,7 +150,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..0b8db53d 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -163,7 +163,7 @@ open class TabsContainer: View { contentViewWidthConstraint?.isActive = true 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 f581d54a..426e0fa8 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) @@ -314,7 +314,7 @@ open class EntryField: Control, Changeable { icon.name = .error icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true errorLabel.isHidden = true diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 1a3862ac..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 @@ -181,7 +181,7 @@ open class InputField: EntryField, UITextFieldDelegate { 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 445a8732..61ca1b95 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -199,7 +199,7 @@ open class Toggle: Control, Changeable { updateLabel() toggleView.surface = surface - toggleView.disabled = disabled + toggleView.isEnabled = isEnabled toggleView.isOn = isOn } 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()