From 1bbad6ca15cd08413da813a45664b25de0cd4dbb Mon Sep 17 00:00:00 2001 From: panxi Date: Tue, 26 Nov 2019 14:14:53 -0500 Subject: [PATCH] fix merge conflict --- MVMCoreUI/Atoms/Views/CaretView.swift | 2 - MVMCoreUI/Atoms/Views/Label.swift | 40 +++++++++---------- .../Atoms/Views/LabelModel/LabelModel.swift | 23 ++--------- 3 files changed, 22 insertions(+), 43 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index 2c4669fe..c02db833 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -155,6 +155,4 @@ extension CaretView: MVMCoreUIViewConstrainingProtocol { open func alignment() -> UIStackView.Alignment { return UIStackView.Alignment.leading; } - - } diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index fb9a18a4..f7d476ec 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -259,47 +259,46 @@ public typealias ActionBlock = () -> () if let attributes = labelModel.attributes, let labelText = text { let attributedString = NSMutableAttributedString(string: labelText, attributes: [NSAttributedString.Key.font: font as UIFont, NSAttributedString.Key.foregroundColor: textColor as UIColor]) - /*for attribute in attributes { - guard let attributeStyle = attribute.type, let location = attribute.location, let length = attribute.length else { continue } - let range = NSRange(location: location, length: length) - switch attributeStyle { - case .underline: + for attribute in attributes { + let range = NSRange(location: attribute.location, length: attribute.length) + switch attribute { + case let underLineAtt as LabelAttributeUnderlineModel: attributedString.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range) - case .strikethrough: + case let strikeAtt as LabelAttributeStrikeThroughModel: attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick.rawValue, range: range) attributedString.addAttribute(.baselineOffset, value: 0, range: range) - case .color: - if let colorHex = attribute.textColor, !colorHex.isEmpty { + case let colorAtt as LabelAttributeColorModel: + if let colorHex = colorAtt.textColor, !colorHex.isEmpty { attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttribute(.foregroundColor, value: UIColor.mfGet(forHex: colorHex), range: range) } - case .image: + case let imageAtt as LabelAttributeImageModel: var fontSize = font.pointSize - if let attributeSize = attribute.size { + if let attributeSize = imageAtt.size { fontSize = attributeSize } - let imageName = attribute.name ?? "externalLink" + let imageName = imageAtt.name ?? "externalLink" let imageAttachment: NSTextAttachment - if let url = attribute.URL { + if let url = imageAtt.URL { imageAttachment = Label.getTextAttachmentFrom(url: url, dimension: fontSize, label: self) } else { imageAttachment = Label.getTextAttachmentImage(name: imageName, dimension: fontSize) } let mutableString = NSMutableAttributedString() mutableString.append(NSAttributedString(attachment: imageAttachment)) - attributedString.insert(mutableString, at: location) - case .font: - if let fontStyle = attribute.style { + attributedString.insert(mutableString, at: imageAtt.location) + case let fontAtt as LabelAttributeFontModel: + if let fontStyle = fontAtt.style { let styles = MFStyler.styleGetAttributedString("0", withStyle: fontStyle) attributedString.removeAttribute(.font, range: range) attributedString.removeAttribute(.foregroundColor, range: range) attributedString.addAttributes(styles.attributes(at: 0, effectiveRange: nil), range: range) } else { - let fontSize = attribute.size + let fontSize = fontAtt.size var font: UIFont? - if let fontName = attribute.name { + if let fontName = fontAtt.name { font = MFFonts.mfFont(withName: fontName, size: fontSize ?? self.font.pointSize) } else if let fontSize = fontSize { font = self.font.withSize(fontSize) @@ -309,20 +308,17 @@ public typealias ActionBlock = () -> () attributedString.addAttribute(.font, value: font, range: range) } } - case .action: + case let actionAtt as LabelAttributeActionModel: addActionAttributes(range: range, string: attributedString) -// if let actionBlock = createActionBlockFor(actionMap: attribute, additionalData: additionalData, delegateObject: delegateObject) { -// appendActionableClause(range: range, actionBlock: actionBlock) -// } default: continue } - }*/ } originalAttributedString = attributedText hero = labelModel.hero } + } @objc public static func setUILabel(_ label: UILabel?, withJSON json: [AnyHashable: Any]?, delegate: DelegateObject?, additionalData: [AnyHashable: Any]?) { diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift index b4c71153..cd1c5d12 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift @@ -60,21 +60,6 @@ import Foundation self.html = try typeContainer.decodeIfPresent(String.self, forKey: .html) self.hero = try typeContainer.decodeIfPresent(Int.self, forKey: .hero) self.makeWholeViewClickable = try typeContainer.decodeIfPresent(Bool.self, forKey: .makeWholeViewClickable) - /*if let atts = self.attributes { - for attribute in atts { - switch attribute.type { - case "font": - let afont = attribute as? LabelAttributeFontModel - print("font length\(afont!.length), \(String(describing: afont?.name))") - case "color": - let afont = attribute as? LabelAttributeColorModel - print("font length\(afont!.length), \(String(describing: afont?.textColor))") - default: - print("attribute") - } - - } - } */ } public func encode(to encoder: Encoder) throws { @@ -88,10 +73,10 @@ import Foundation try container.encodeIfPresent(fontName, forKey: .fontName) try container.encodeIfPresent(fontSize, forKey: .fontSize) try container.encodeIfPresent(textAlignment, forKey: .textAlignment) -// var attributeContainer = container.nestedUnkeyedContainer(forKey: .attributes) -// try attributes?.forEach({ (attributeModel) in -// try attributeContainer.encode(attributeModel) -// }) + var attributeContainer = container.nestedUnkeyedContainer(forKey: .attributes) + try attributes?.forEach({ (attributeModel) in + try attributeContainer.encode(attributeModel) + }) try container.encodeIfPresent(html, forKey: .html) try container.encodeIfPresent(hero, forKey: .hero) try container.encodeIfPresent(makeWholeViewClickable, forKey: .makeWholeViewClickable)