diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 35862574..cf1a9100 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -44,17 +44,12 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab open var surface: Surface = .light { didSet { setNeedsUpdate() } } /// Control is disabled or not - open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } } - - open override var state: UIControl.State { - get { - var state = super.state - if disabled { - state.insert(.disabled) - } else { - state.remove(.disabled) + open var disabled: Bool { + get { !isEnabled } + set { + if !isEnabled != newValue { + isEnabled = !newValue } - return state } } @@ -85,14 +80,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab } /// Override to deal with setNeedsUpdate() - open override var isEnabled: Bool { - get { !disabled } - set { - if disabled != !newValue { - disabled = !newValue - } - } - } + open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } //-------------------------------------------------- // MARK: - Initializers diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index 5ec0ba11..e85e9117 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -270,7 +270,7 @@ open class SelectorItemBase: Control, Errorable, } open override func updateAccessibilityLabel() { - if !accessibilityTraits.contains(.notEnabled) && disabled { + if !accessibilityTraits.contains(.notEnabled) && !isEnabled { accessibilityTraits.insert(.notEnabled) } else { accessibilityTraits.remove(.notEnabled) diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index 08bb2b34..b130b56a 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -34,7 +34,16 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable { open var surface: Surface = .light { didSet { setNeedsUpdate() } } /// Whether this object is disabled or not - open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } } + open var disabled: Bool { + get { !isEnabled } + set { + if !isEnabled != newValue { + isEnabled = !newValue + } + } + } + + open var isEnabled: Bool = true { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } //-------------------------------------------------- // MARK: - Initializers diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index b5fbc3e5..b11d7f9a 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -55,8 +55,6 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab open var surface: Surface = .light { didSet { setNeedsUpdate() }} - open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } } - open var userInfo = [String: Primitive]() public var touchUpInsideCount: Int = 0 @@ -80,28 +78,18 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab } } - /// Override to deal with setNeedsUpdate() - open override var isEnabled: Bool { - get { !disabled } + /// Whether this object is disabled or not + open var disabled: Bool { + get { !isEnabled } set { - if disabled != !newValue { - disabled = !newValue + if !isEnabled != newValue { + isEnabled = !newValue } } } - open override var state: UIControl.State { - get { - var state = super.state - if disabled { - state.insert(.disabled) - } else { - state.remove(.disabled) - } - return state - } - } - + open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open var textStyle: TextStyle { .defaultStyle } open var textColor: UIColor { .black } @@ -171,7 +159,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab } open func updateAccessibilityLabel() { - if !accessibilityTraits.contains(.notEnabled) && disabled { + if !accessibilityTraits.contains(.notEnabled) && !isEnabled { accessibilityTraits.insert(.notEnabled) } else { accessibilityTraits.remove(.notEnabled) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 0ca91cd0..7cd75b47 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -29,8 +29,6 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { open var surface: Surface = .light { didSet { setNeedsUpdate() }} - open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } } - open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} open var textStyle: TextStyle = .defaultStyle { didSet { setNeedsUpdate() }} @@ -46,6 +44,18 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { } } + /// Whether this object is disabled or not + open var disabled: Bool { + get { !isEnabled } + set { + if !isEnabled != newValue { + isEnabled = !newValue + } + } + } + + open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + //-------------------------------------------------- // MARK: - Configuration Properties //-------------------------------------------------- diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 09dfc3e2..2b2f409b 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -248,7 +248,7 @@ open class RadioBoxItem: Control, Changeable { } open override func updateAccessibilityLabel() { - if !accessibilityTraits.contains(.notEnabled) && disabled { + if !accessibilityTraits.contains(.notEnabled) && !isEnabled { accessibilityTraits.insert(.notEnabled) } else { accessibilityTraits.remove(.notEnabled) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 52f559cd..6b4f8ea8 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -312,7 +312,7 @@ open class Toggle: Control, Changeable { } open override func updateAccessibilityLabel() { - if !accessibilityTraits.contains(.notEnabled) && disabled { + if !accessibilityTraits.contains(.notEnabled) && !isEnabled { accessibilityTraits.insert(.notEnabled) } else { accessibilityTraits.remove(.notEnabled) diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index cfde49fb..4d5a291f 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -166,7 +166,7 @@ open class Tooltip: Control, TooltipLaunchable { } open override func updateAccessibilityLabel() { - if !accessibilityTraits.contains(.notEnabled) && disabled { + if !accessibilityTraits.contains(.notEnabled) && !isEnabled { accessibilityTraits.insert(.notEnabled) } else { accessibilityTraits.remove(.notEnabled)