refactored disabling (disabled) as a helper to get/set isEnabled
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
bc6c783e4e
commit
b919cfd92b
@ -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
|
||||
|
||||
@ -270,7 +270,7 @@ open class SelectorItemBase<Selector: SelectorControlable>: Control, Errorable,
|
||||
}
|
||||
|
||||
open override func updateAccessibilityLabel() {
|
||||
if !accessibilityTraits.contains(.notEnabled) && disabled {
|
||||
if !accessibilityTraits.contains(.notEnabled) && !isEnabled {
|
||||
accessibilityTraits.insert(.notEnabled)
|
||||
} else {
|
||||
accessibilityTraits.remove(.notEnabled)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user