fixed issues with disabled state overwriting layers.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-06-07 15:26:13 -05:00
parent d8595d2815
commit 9093131f1d
5 changed files with 44 additions and 52 deletions

View File

@ -43,7 +43,19 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
open var surface: Surface = .light { didSet { setNeedsUpdate() } } open var surface: Surface = .light { didSet { setNeedsUpdate() } }
/// Control is disabled or not /// Control is disabled or not
open var disabled: Bool = false { didSet { isEnabled = !disabled } } 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)
}
return state
}
}
/// Override for isSelected to handle setNeedsUpdate() on changes /// Override for isSelected to handle setNeedsUpdate() on changes
open override var isSelected: Bool { didSet { setNeedsUpdate() } } open override var isSelected: Bool { didSet { setNeedsUpdate() } }
@ -71,18 +83,18 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
} }
} }
/// Override to deal with setNeedsUpdate() // /// Override to deal with setNeedsUpdate()
open override var isEnabled: Bool { // open override var isEnabled: Bool {
get { !disabled } // get { !disabled }
set { // set {
if disabled != !newValue { // if disabled != !newValue {
disabled = !newValue // disabled = !newValue
} // }
isUserInteractionEnabled = isEnabled // isUserInteractionEnabled = isEnabled
setNeedsUpdate() // setNeedsUpdate()
} // }
} // }
//
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------

View File

@ -45,6 +45,8 @@ open class SelectorBase: Control, SelectorControlable {
var state = super.state var state = super.state
if showError { if showError {
state.insert(.error) state.insert(.error)
} else {
state.remove(.error)
} }
return state return state
} }

View File

@ -33,19 +33,7 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
open var surface: Surface = .light { didSet { setNeedsUpdate() } } open var surface: Surface = .light { didSet { setNeedsUpdate() } }
/// Control is disabled or not /// Control is disabled or not
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } }
/// Override to deal with setNeedsUpdate()
open var isEnabled: Bool {
get { !disabled }
set {
if disabled != !newValue {
disabled = !newValue
}
isUserInteractionEnabled = isEnabled
setNeedsUpdate()
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers

View File

@ -55,7 +55,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
open var surface: Surface = .light { didSet { setNeedsUpdate() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } }
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()
@ -80,21 +80,22 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
} }
} }
open override var state: UIControl.State {
get {
var state = super.state
if disabled {
state.insert(.disabled)
} else {
state.remove(.disabled)
}
return state
}
}
open var textStyle: TextStyle { .defaultStyle } open var textStyle: TextStyle { .defaultStyle }
open var textColor: UIColor { .black } open var textColor: UIColor { .black }
open override var isEnabled: Bool {
get { !disabled }
set {
if disabled != !newValue {
disabled = !newValue
}
isUserInteractionEnabled = isEnabled
setNeedsUpdate()
}
}
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------

View File

@ -29,7 +29,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
open var surface: Surface = .light { didSet { setNeedsUpdate() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }}
open var disabled: Bool = false { didSet { isEnabled = !disabled } } open var disabled: Bool = false { didSet { setNeedsUpdate(); isUserInteractionEnabled = !disabled } }
open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }}
@ -39,17 +39,6 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
open var userInfo = [String: Primitive]() open var userInfo = [String: Primitive]()
open override var isEnabled: Bool {
get { !disabled }
set {
if disabled != !newValue {
disabled = !newValue
}
isUserInteractionEnabled = isEnabled
setNeedsUpdate()
}
}
override open var text: String? { override open var text: String? {
didSet { didSet {
attributes = nil attributes = nil