From 592e0a9591b114af0b81f017f1ecdf097017e172 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 1 Oct 2020 09:03:48 -0400 Subject: [PATCH] move logic up --- .../Atomic/Atoms/Views/Label/Label.swift | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index fe6b31eb..a5bf5f5e 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -251,6 +251,23 @@ public typealias ActionBlock = () -> () attributedText = nil originalAttributedString = nil text = labelModel.text + + /* + * 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 #available(iOS 13, *) { + // Case where no attributes are set in the model but attributedText has a value. + if attributedText != nil, let text = text { + let attributedString = NSMutableAttributedString(string: text) + attributedString.addAttribute(.underlineStyle, value: 0, range: NSRange(location: 0, length: text.count)) + attributedText = attributedString + } + } + hero = labelModel.hero Label.setLabel(self, withHTML: labelModel.html) isAccessibilityElement = hasText @@ -366,22 +383,6 @@ public typealias ActionBlock = () -> () attributedText = attributedString originalAttributedString = attributedText } - - /* - * 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 #available(iOS 13, *) { - // Case where no attributes are set in the model but attributedText has a value. - if labelModel.attributes == nil && attributedText != nil, let text = text { - let attributedString = NSMutableAttributedString(string: text) - attributedString.addAttribute(.underlineStyle, value: 0, range: NSRange(location: 0, length: text.count)) - attributedText = attributedString - } - } } @objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) {