From 547b03ac1cd5e47f400e34b22f00f9e1d8c03cfd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 14 Mar 2024 18:42:33 -0500 Subject: [PATCH 1/2] fixed issue with attributedText setting not working correctly Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index db9804d0..fd77dc7e 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -108,14 +108,14 @@ open class Label: UILabel, ViewProtocol, UserInfoable { // MARK: - Public Properties //-------------------------------------------------- /// Key of whether or not updateView() is called in setNeedsUpdate() - open var shouldUpdateView: Bool = true + open var shouldUpdateView: Bool = true /// Will determine if a scaled font should be used for the font. open var useScaledFont: Bool = false { didSet { setNeedsUpdate() }} open var surface: Surface = .light { didSet { setNeedsUpdate() }} - /// Array of LabelAttributeModel objects used in rendering the text. + /// Array of LabelAttributeModel objects used in rendering the text. open var attributes: [any LabelAttributeModel]? { didSet { setNeedsUpdate() }} /// TextStyle used on the this label. @@ -135,20 +135,18 @@ open class Label: UILabel, ViewProtocol, UserInfoable { /// Text that will be used in the label. private var _text: String! override open var text: String! { - get { _text } - set { + didSet { + _text = text textSetMode = .text - _text = newValue - styleText(newValue) + setNeedsUpdate() } } ///AttributedText that will be used in the label. override open var attributedText: NSAttributedString? { - get { super.attributedText } - set { + didSet { textSetMode = .attributedText - styleAttributedText(newValue) + setNeedsUpdate() } } @@ -306,7 +304,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { lineBreakMode: lineBreakMode) applyAttributes(mutableText) - + // Set attributed text to match typography super.attributedText = mutableText } @@ -322,7 +320,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { let mutableText = NSMutableAttributedString(attributedString: newValue) applyAttributes(mutableText) - + // Modify attributed text to match typography super.attributedText = mutableText } @@ -424,3 +422,5 @@ open class Label: UILabel, ViewProtocol, UserInfoable { } } } + + From 60f71a7709733f9304de0082c1fd3d859b95150d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 14 Mar 2024 18:49:21 -0500 Subject: [PATCH 2/2] added string empty checks. Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index fd77dc7e..955d9604 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -286,7 +286,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { private func styleText(_ newValue: String!) { defer { invalidateIntrinsicContentSize() } - guard let newValue else { + guard let newValue, !newValue.isEmpty else { // We don't need to use attributed text super.attributedText = nil super.text = newValue @@ -311,7 +311,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { private func styleAttributedText(_ newValue: NSAttributedString?) { defer { invalidateIntrinsicContentSize() } - guard let newValue = newValue else { + guard let newValue, !newValue.string.isEmpty else { // We don't need any additional styling super.attributedText = newValue return