From dcb5b91e32d28c48b9d8433fcd2033eb3fda451c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 8 Mar 2024 14:03:05 -0600 Subject: [PATCH 1/2] deleted method and refactored atomic label even more Signed-off-by: Matt Bruce --- .../Atomic/Atoms/Views/Label/Label.swift | 34 ++----------------- .../Atomic/Extensions/VDS-TextStyle.swift | 9 ----- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index e7c7e8bc..7d05bc3b 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -46,14 +46,6 @@ public typealias ActionBlock = () -> () return !text.isEmpty || !attributedText.string.isEmpty } - open override var textColor: UIColor! { - didSet { - if let textColor { - textColorConfiguration = SurfaceColorConfiguration(textColor, textColor).eraseToAnyColorable() - } - } - } - //------------------------------------------------------ // MARK: - Convenience Setter For objective-C //------------------------------------------------------ @@ -229,7 +221,6 @@ public typealias ActionBlock = () -> () } if let style = viewModel.fontStyle?.vdsTextStyle() { - font = style.font textStyle = style } else if let fontName = viewModel.fontName { // there is a TextStyle.defaultStyle @@ -237,9 +228,8 @@ public typealias ActionBlock = () -> () if let fontSize { standardFontSize = fontSize } - if let customStyle = style(for: fontName, pointSize: fontSize ?? standardFontSize), customStyle != textStyle { - font = customStyle.font - textStyle = customStyle + if let newFont = UIFont(name: fontName, size: fontSize ?? standardFontSize) { + font = newFont } } @@ -256,26 +246,6 @@ public typealias ActionBlock = () -> () } } - - /// See if the font that is currently set matches a VDS Font and if so grab the matching TextStyle or create custom TextStyle that - /// that the Label will use moving forward. - private func checkforFontChange() { - guard let customStyle = style(for: font.fontName, pointSize: font.pointSize), customStyle != textStyle - else { return } - textStyle = customStyle - } - - private func style(for fontName: String, pointSize: CGFloat) -> TextStyle? { - guard let vdsFont = Font.from(fontName: fontName), - let customStyle = TextStyle.style(from: vdsFont, pointSize: pointSize) - else { return nil } - return customStyle - } - - open override func updateView() { - checkforFontChange() - super.updateView() - } open override func updateAccessibility() { super.updateAccessibility() diff --git a/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift b/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift index f7e5917e..2d24c5a1 100644 --- a/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift +++ b/MVMCoreUI/Atomic/Extensions/VDS-TextStyle.swift @@ -54,12 +54,3 @@ extension VDS.Font { Self.allCases.filter({$0.fontName == fontName }).first } } - -extension VDS.TextStyle { - internal static func style(from font: VDS.Font, pointSize: CGFloat) -> TextStyle? { - guard let first = allCases.filter({$0.fontFace == font && $0.pointSize == pointSize}).first else { - return TextStyle(rawValue: "Custom-TextStyle", fontFace: font, pointSize: pointSize) - } - return first - } -} From b638637af7350307c0b68e64df20d01bda2c53eb Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 8 Mar 2024 14:20:44 -0600 Subject: [PATCH 2/2] removed code and call the code that does the same thing under the hood. Signed-off-by: Matt Bruce --- .../Atomic/Atoms/Views/Label/Label.swift | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 7d05bc3b..0b12b5a9 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -182,29 +182,7 @@ public typealias ActionBlock = () -> () } @objc public func resetAttributeStyle() { - /* - * This is to address a reuse issue with iOS 13 and up. - * Even if you set text & attributedText to nil, the moment you set text with a value, - * attributedText will hold a dirty value from a previously reused cell even if reset() is - * appropriately called. - * Only other reference found of issue: https://www.thetopsites.net/article/58142205.shtml - */ - if let text = text, !text.isEmpty { - - //create the primary string - let mutableText = NSMutableAttributedString.mutableText(for: text, - textStyle: textStyle, - useScaledFont: useScaledFont, - textColor: textColorConfiguration.getColor(self), - alignment: textAlignment, - lineBreakMode: lineBreakMode) - - if let attributes = attributes { - mutableText.apply(attributes: attributes) - } - - self.attributedText = mutableText - } + setNeedsUpdate() } public func viewModelDidUpdate() {