isEnabled workaround until I can figure something else out.

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-05-28 11:39:41 -05:00
parent 8e0287c8fd
commit f8289788ee

View File

@ -141,7 +141,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
setNeedsUpdate()
}
}
///AttributedText that will be used in the label.
override open var attributedText: NSAttributedString? {
didSet {
@ -169,7 +169,16 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
}
/// Whether the View is enabled or not.
open override var isEnabled: Bool { didSet { setNeedsUpdate() } }
/// Since the UILabel itselfs draws a different color for the "disabled state", I have to track
/// local variable to deal with color and always enforce this UILabel is always enabled.
private var _fakeIsEnabled: Bool = true
open override var isEnabled: Bool {
get { true }
set {
_fakeIsEnabled = newValue
setNeedsUpdate()
}
}
//--------------------------------------------------
// MARK: - Configuration Properties
@ -282,7 +291,21 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
styleAttributedText(attributedText)
}
}
private struct FakeEnabled: Enabling, Surfaceable {
var surface: Surface
var isEnabled: Bool
}
/// Var to deal with the UILabel.isEnabled property causing issues with
/// textColor when it is false, I am now using a struct to draw and manage
/// colors instead of this class itself and this class will always be enabled
private var _textColor: UIColor {
let fake = FakeEnabled(surface: surface, isEnabled: _fakeIsEnabled)
return textColorConfiguration.getColor(fake)
}
private func styleText(_ newValue: String!) {
defer { invalidateIntrinsicContentSize() }
guard let newValue, !newValue.isEmpty else {
@ -293,15 +316,13 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
}
accessibilityCustomActions = []
//create the primary string
let mutableText = NSMutableAttributedString.mutableText(for: newValue,
textStyle: textStyle,
useScaledFont: useScaledFont,
textColor: textColorConfiguration.getColor(self),
textColor: _textColor,
alignment: textAlignment,
lineBreakMode: lineBreakMode)
applyAttributes(mutableText)
// Set attributed text to match typography