From 9ec661ae3b58dac0ecd7aa8a67a74745a14928b3 Mon Sep 17 00:00:00 2001 From: panxi Date: Fri, 22 Nov 2019 14:31:17 -0500 Subject: [PATCH] add label model --- MVMCoreUI.xcodeproj/project.pbxproj | 24 +++++++ MVMCoreUI/Atoms/Views/Label.swift | 4 +- .../LabelAttributeActionModel.swift | 23 +++++++ .../LabelModel/LabelAttributeColorModel.swift | 35 ++++++++++ .../LabelModel/LabelAttributeFontModel.swift | 33 +++++++++ .../LabelModel/LabelAttributeImageModel.swift | 42 +++++++++++ .../LabelModel/LabelAttributeModel.swift | 53 ++++---------- .../LabelAttributeStrikeThroughModel.swift | 22 ++++++ .../LabelAttributeUnderlineModel.swift | 23 +++++++ .../Atoms/Views/LabelModel/LabelModel.swift | 69 +++++++++++++++++++ ...UIMoleculeMappingObject+ModelMapping.swift | 6 ++ 11 files changed, 294 insertions(+), 40 deletions(-) create mode 100644 MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeActionModel.swift create mode 100644 MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeColorModel.swift create mode 100644 MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift create mode 100644 MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeImageModel.swift create mode 100644 MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeStrikeThroughModel.swift create mode 100644 MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeUnderlineModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 65ff9299..e9c650c8 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -55,6 +55,12 @@ 946EE1BA237B66D80036751F /* ModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* ModelHelper.swift */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; 94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */; }; + 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */; }; + 94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */; }; + 94C2D9A523872C350006CF46 /* LabelAttributeFontModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A423872C350006CF46 /* LabelAttributeFontModel.swift */; }; + 94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A623872DA90006CF46 /* LabelAttributeColorModel.swift */; }; + 94C2D9A923872E5E0006CF46 /* LabelAttributeImageModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A823872E5E0006CF46 /* LabelAttributeImageModel.swift */; }; + 94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */; }; D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; }; D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */; }; D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */; }; @@ -275,6 +281,12 @@ 946EE1B9237B66D80036751F /* ModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelHelper.swift; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = ""; }; + 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeUnderlineModel.swift; sourceTree = ""; }; + 94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeStrikeThroughModel.swift; sourceTree = ""; }; + 94C2D9A423872C350006CF46 /* LabelAttributeFontModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeFontModel.swift; sourceTree = ""; }; + 94C2D9A623872DA90006CF46 /* LabelAttributeColorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeColorModel.swift; sourceTree = ""; }; + 94C2D9A823872E5E0006CF46 /* LabelAttributeImageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeImageModel.swift; sourceTree = ""; }; + 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeActionModel.swift; sourceTree = ""; }; D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = ""; }; D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUINavigationController.m; sourceTree = ""; }; D20A9A5D2243D3E300ADE781 /* TwoButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonView.swift; sourceTree = ""; }; @@ -514,6 +526,12 @@ children = ( 01EB368823609801006832FA /* LabelModel.swift */, 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */, + 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */, + 94C2D9A223872C110006CF46 /* LabelAttributeStrikeThroughModel.swift */, + 94C2D9A423872C350006CF46 /* LabelAttributeFontModel.swift */, + 94C2D9A623872DA90006CF46 /* LabelAttributeColorModel.swift */, + 94C2D9A823872E5E0006CF46 /* LabelAttributeImageModel.swift */, + 94C2D9AA23872EB50006CF46 /* LabelAttributeActionModel.swift */, ); path = LabelModel; sourceTree = ""; @@ -1150,6 +1168,7 @@ DBC4391822442197001AB423 /* CaretView.swift in Sources */, D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */, D29B771022C281F400D6ACE0 /* ModuleMolecule.swift in Sources */, + 94C2D9A923872E5E0006CF46 /* LabelAttributeImageModel.swift in Sources */, DBC4391922442197001AB423 /* DashLine.swift in Sources */, 0A7BAD74232A8DC700FB8E22 /* HeadlineBodyButton.swift in Sources */, D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */, @@ -1184,9 +1203,11 @@ D2A5145F2211DDC100345BFB /* MoleculeStackView.swift in Sources */, D29DF27621E79E81003B2FB9 /* MVMCoreUILoggingHandler.m in Sources */, D29DF24D21E6A177003B2FB9 /* MFTextField.m in Sources */, + 94C2D9AB23872EB50006CF46 /* LabelAttributeActionModel.swift in Sources */, 017BEB4023620A230024EF95 /* TextFieldModel.swift in Sources */, D29DF2A221E7AF4E003B2FB9 /* MVMCoreUIUtility.m in Sources */, D29DF12B21E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.m in Sources */, + 94C2D9A723872DA90006CF46 /* LabelAttributeColorModel.swift in Sources */, D2755D7B23689C7500485468 /* TableViewCell.swift in Sources */, 01EB369223609801006832FA /* MoleculeStackModel.swift in Sources */, D29DF25421E6A177003B2FB9 /* MFMdnTextField.m in Sources */, @@ -1217,6 +1238,7 @@ D29DF18321E69E54003B2FB9 /* SeparatorView.m in Sources */, D29DF17A21E69E1F003B2FB9 /* MFCustomButton.m in Sources */, 017BEB7B236763000024EF95 /* LineModel.swift in Sources */, + 94C2D9A523872C350006CF46 /* LabelAttributeFontModel.swift in Sources */, 017BEB7F23676E870024EF95 /* MVMCoreUIMoleculeMappingObject+ModelMapping.swift in Sources */, D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */, D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */, @@ -1251,6 +1273,7 @@ D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */, 01EB369323609801006832FA /* HeaderModel.swift in Sources */, D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */, + 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */, D20A9A5E2243D3E300ADE781 /* TwoButtonView.swift in Sources */, D2B1E3E522F37D6A0065F95C /* ImageHeadlineBody.swift in Sources */, 943784F6236B77BB006A1E82 /* GraphViewAnimationHandler.swift in Sources */, @@ -1258,6 +1281,7 @@ 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */, D2A5146122121FBF00345BFB /* MoleculeStackTemplate.swift in Sources */, D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */, + 94C2D9A323872C110006CF46 /* LabelAttributeStrikeThroughModel.swift in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Label.swift b/MVMCoreUI/Atoms/Views/Label.swift index 2cd23405..c442fbc1 100644 --- a/MVMCoreUI/Atoms/Views/Label.swift +++ b/MVMCoreUI/Atoms/Views/Label.swift @@ -260,7 +260,7 @@ 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 { + /*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 { @@ -318,7 +318,7 @@ public typealias ActionBlock = () -> () default: continue } - } + }*/ } originalAttributedString = attributedText diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeActionModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeActionModel.swift new file mode 100644 index 00000000..eb5a3cd7 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeActionModel.swift @@ -0,0 +1,23 @@ +// +// LabelAttributeActionModel.swift +// MVMCoreUI +// +// Created by Ryan on 11/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +class LabelAttributeActionModel: LabelAttributeModel { + override public class var identifier: String { + return "action" + } + + required public init(from decoder: Decoder) throws { + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + } +} diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeColorModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeColorModel.swift new file mode 100644 index 00000000..26f1fa54 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeColorModel.swift @@ -0,0 +1,35 @@ +// +// LabelAttributeColorModel.swift +// MVMCoreUI +// +// Created by Ryan on 11/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class LabelAttributeColorModel: LabelAttributeModel { + + override public class var identifier: String { + return "color" + } + + var textColor: String? + + private enum CodingKeys: String, CodingKey { + case textColor + } + + required public init(from decoder: Decoder) throws { + + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor) + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(textColor, forKey: .textColor) + } +} diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift new file mode 100644 index 00000000..992cce53 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeFontModel.swift @@ -0,0 +1,33 @@ +// +// LabelAttributeFontModel.swift +// MVMCoreUI +// +// Created by Ryan on 11/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class LabelAttributeFontModel: LabelAttributeModel { + override public class var identifier: String { + return "font" + } + + var style: String? + + private enum CodingKeys: String, CodingKey { + case style + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(style, forKey: .style) + } +} diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeImageModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeImageModel.swift new file mode 100644 index 00000000..0095a589 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeImageModel.swift @@ -0,0 +1,42 @@ +// +// LabelAttributeImageModel.swift +// MVMCoreUI +// +// Created by Ryan on 11/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +class LabelAttributeImageModel: LabelAttributeModel { + + override public class var identifier: String { + return "image" + } + + var size: CGFloat? + var name: String? + var URL: String? + + private enum CodingKeys: String, CodingKey { + case size + case name + case URL + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) + self.name = try typeContainer.decodeIfPresent(String.self, forKey: .name) + self.URL = try typeContainer.decodeIfPresent(String.self, forKey: .URL) + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(size, forKey: .size) + try container.encodeIfPresent(name, forKey: .name) + try container.encodeIfPresent(URL, forKey: .URL) + } +} diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeModel.swift index e4388ea5..ae2768ab 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeModel.swift @@ -8,57 +8,34 @@ import Foundation -@objcMembers open class LabelAttributeModel: Codable { - enum ModelType: String, Codable { - case underline - case strikethrough - case color - case image - case font - case action +@objcMembers open class LabelAttributeModel: Model { + + public class var identifier: String { + return "" } - var type: ModelType? - var location: Int? - var length: Int? - var textColor: String? - var style: String? - var size: CGFloat? - var name: String? - var URL: String? + var type: String + var location: Int + var length: Int - enum CodingKeys: String, CodingKey { + private enum CodingKeys: String, CodingKey { case type case location case length - case textColor - case style - case size - case name - case URL } required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - self.type = try typeContainer.decodeIfPresent(ModelType.self, forKey: .type) - self.location = try typeContainer.decodeIfPresent(Int.self, forKey: .location) - self.length = try typeContainer.decodeIfPresent(Int.self, forKey: .length) - self.textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor) - self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) - self.size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) - self.name = try typeContainer.decodeIfPresent(String.self, forKey: .name) - self.URL = try typeContainer.decodeIfPresent(String.self, forKey: .URL) + self.type = try typeContainer.decode(String.self, forKey: .type) + self.location = try typeContainer.decode(Int.self, forKey: .location) + self.length = try typeContainer.decode(Int.self, forKey: .length) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeIfPresent(type, forKey: .type) - try container.encodeIfPresent(location, forKey: .location) - try container.encodeIfPresent(length, forKey: .length) - try container.encodeIfPresent(textColor, forKey: .textColor) - try container.encodeIfPresent(style, forKey: .style) - try container.encodeIfPresent(size, forKey: .size) - try container.encodeIfPresent(name, forKey: .name) - try container.encodeIfPresent(URL, forKey: .URL) + try container.encode(type, forKey: .type) + try container.encode(location, forKey: .location) + try container.encode(length, forKey: .length) } + } diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeStrikeThroughModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeStrikeThroughModel.swift new file mode 100644 index 00000000..f69e966d --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeStrikeThroughModel.swift @@ -0,0 +1,22 @@ +// +// LabelAttributeStrikeThroughModel.swift +// MVMCoreUI +// +// Created by Ryan on 11/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class LabelAttributeStrikeThroughModel: LabelAttributeModel { + override public class var identifier: String { + return "strikethrough" + } + required public init(from decoder: Decoder) throws { + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + } +} diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeUnderlineModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeUnderlineModel.swift new file mode 100644 index 00000000..d052686d --- /dev/null +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelAttributeUnderlineModel.swift @@ -0,0 +1,23 @@ +// +// LabelAttributeUnderlineModel.swift +// MVMCoreUI +// +// Created by Ryan on 11/21/19. +// Copyright © 2019 Verizon Wireless. All rights reserved. +// + +import UIKit + +@objcMembers public class LabelAttributeUnderlineModel: LabelAttributeModel { + override public class var identifier: String { + return "underline" + } + + required public init(from decoder: Decoder) throws { + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + } +} diff --git a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift index 376166ed..e47a395f 100644 --- a/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift +++ b/MVMCoreUI/Atoms/Views/LabelModel/LabelModel.swift @@ -24,4 +24,73 @@ import Foundation public var html: String? public var hero: Int? public var makeWholeViewClickable: Bool? + + enum CodingKeys: String, CodingKey { + case moleculeName + case text + case accessibilityText + case textColor + case backgroundColor + case fontStyle + case fontName + case fontSize + case textAlignment + case attributes + case html + case hero + case makeWholeViewClickable + } + + enum AttributeTypeKey: String, CodingKey { + case type + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + self.moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName) + self.text = try typeContainer.decode(String.self, forKey: .text) + self.accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText) + self.textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor) + self.backgroundColor = try typeContainer.decodeIfPresent(String.self, forKey: .backgroundColor) + self.fontStyle = try typeContainer.decodeIfPresent(String.self, forKey: .fontStyle) + self.fontName = try typeContainer.decodeIfPresent(String.self, forKey: .fontName) + self.fontSize = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .fontSize) + self.textAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .textAlignment) + do { + var attributesContainer = try typeContainer.nestedUnkeyedContainer(forKey: .attributes) + var attributes = [LabelAttributeModel]() + while !attributesContainer.isAtEnd { + guard let attmodel = try attributesContainer.decodeUnKeyedIfPresent(LabelAttributeModel.self, typeCodingKey: AttributeTypeKey.type) else { + continue + } + attributes.append(attmodel) + } + self.attributes = attributes + } catch { + print("no attributes") + } + 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) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(moleculeName, forKey: .moleculeName) + try container.encode(text, forKey: .moleculeName) + try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) + try container.encodeIfPresent(textColor, forKey: .textColor) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeIfPresent(fontStyle, forKey: .fontStyle) + 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) +// }) + try container.encodeIfPresent(html, forKey: .html) + try container.encodeIfPresent(hero, forKey: .hero) + try container.encodeIfPresent(makeWholeViewClickable, forKey: .makeWholeViewClickable) + } } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift index 1efebf77..0dfbae0a 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUIMoleculeMappingObject+ModelMapping.swift @@ -23,5 +23,11 @@ import Foundation ModelRegistry.register(CaretViewModel.self) ModelRegistry.register(DashLineModel.self) ModelRegistry.register(ImageViewModel.self) + ModelRegistry.register(LabelAttributeFontModel.self) + ModelRegistry.register(LabelAttributeColorModel.self) + ModelRegistry.register(LabelAttributeImageModel.self) + ModelRegistry.register(LabelAttributeUnderlineModel.self) + ModelRegistry.register(LabelAttributeStrikeThroughModel.self) + ModelRegistry.register(LabelAttributeActionModel.self) } }