From 38912a4f859a7c07255b89d06552d65335cb5918 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 29 Aug 2019 16:21:30 -0400 Subject: [PATCH] some changes made. More to come. --- MVMCoreUI/Atoms/Views/Label.swift | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 15ec60b2..8ede8588 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -254,16 +254,16 @@ public typealias ActionBlock = () -> () attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) } - case "icon": + case "image": let fontSize = attribute["size"] as? CGFloat ?? label.font.pointSize - let iconName = attribute["iconName"] as? String ?? "externalLink" - let imageURL = attribute["image"] as? String + let imageName = attribute["name"] as? String ?? "externalLink" + let imageURL = attribute["URL"] as? String let imageAttachment: NSTextAttachment if let url = imageURL, let label = label as? Label { imageAttachment = Label.getTextAttachmentFrom(url: url, dimension: fontSize, label: label) } else { - imageAttachment = Label.getTextAttachmentImage(name: iconName, dimension: fontSize) + imageAttachment = Label.getTextAttachmentImage(name: imageName, dimension: fontSize) } let mutableString = NSMutableAttributedString() @@ -382,7 +382,7 @@ public typealias ActionBlock = () -> () // Loop the original attributed string, resize the image attachments. originalAttributedString.enumerateAttribute(.attachment, in: NSRange(location: 0, length: originalAttributedString.length), options: []) { value, range, stop in - if value is NSTextAttachment, let attachment = value as? NSTextAttachment, + if let attachment = value as? NSTextAttachment, let stylerSize = MFStyler.sizeObjectGeneric(forCurrentDevice: attachment.bounds.width)?.getValueBased(onSize: size) { let dimension = round(stylerSize) @@ -471,14 +471,16 @@ public typealias ActionBlock = () -> () let imageAttachment = NSTextAttachment() imageAttachment.bounds = CGRect(x: 0, y: 0, width: dimension, height: dimension) - DispatchQueue.main.async { + DispatchQueue.global(qos: .default).async { guard let url = URL(string: url), let data = try? Data(contentsOf: url) else { return } imageAttachment.image = UIImage(data: data) - label.setNeedsDisplay() + DispatchQueue.main.sync { + label.setNeedsDisplay() + } } return imageAttachment @@ -595,10 +597,9 @@ extension Label { @objc private func textLinkTapped(_ gesture: UITapGestureRecognizer) { for clause in clauses { - guard let range = clause.range else { return } // This determines if we tapped on the desired range of text. - if gesture.didTapAttributedTextInLabel(self, inRange: range) { + if let range = clause.range, gesture.didTapAttributedTextInLabel(self, inRange: range) { clause.performAction() return }