From 6b7bb180fc408b7da8497c51f34311125f56354b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Mon, 13 Jan 2020 21:15:21 -0500 Subject: [PATCH] corner labels temporary --- MVMCoreUI.xcodeproj/project.pbxproj | 4 ++ MVMCoreUI/Atoms/Views/DashLine.swift | 1 - .../LeftRightViews/CornerLabels.swift | 18 +++++++ .../LeftRightViews/CornerLabelsModel.swift | 52 +++++++++++++++++++ .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 MVMCoreUI/Molecules/LeftRightViews/CornerLabelsModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 017a5a78..8536e6be 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -148,6 +148,7 @@ D28A838B23CCDA6B00DFE4FC /* ButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838A23CCDA6B00DFE4FC /* ButtonModel.swift */; }; D28A838D23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */; }; D28A838F23CCDEDE00DFE4FC /* TwoButtonViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A838E23CCDEDE00DFE4FC /* TwoButtonViewModel.swift */; }; + D28A839123CD4FD400DFE4FC /* CornerLabelsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D28A839023CD4FD400DFE4FC /* CornerLabelsModel.swift */; }; D296E14722A5984C0051EBE7 /* MVMCoreUIViewConstrainingProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; D29770C821F7C4AE00B2F0D0 /* TopLabelsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */; }; D29770C921F7C4AE00B2F0D0 /* TopLabelsView.h in Headers */ = {isa = PBXBuildFile; fileRef = D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -414,6 +415,7 @@ D28A838A23CCDA6B00DFE4FC /* ButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonModel.swift; sourceTree = ""; }; D28A838C23CCDCC200DFE4FC /* PrimaryButton+MoleculeProtocolExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PrimaryButton+MoleculeProtocolExtension.swift"; sourceTree = ""; }; D28A838E23CCDEDE00DFE4FC /* TwoButtonViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoButtonViewModel.swift; sourceTree = ""; }; + D28A839023CD4FD400DFE4FC /* CornerLabelsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CornerLabelsModel.swift; sourceTree = ""; }; D296E14622A597490051EBE7 /* MVMCoreUIViewConstrainingProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIViewConstrainingProtocol.h; sourceTree = ""; }; D29770C621F7C4AE00B2F0D0 /* TopLabelsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TopLabelsView.m; sourceTree = ""; }; D29770C721F7C4AE00B2F0D0 /* TopLabelsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLabelsView.h; sourceTree = ""; }; @@ -775,6 +777,7 @@ D224798F2316A99F003FCCF9 /* LeftRightViews */ = { isa = PBXGroup; children = ( + D28A839023CD4FD400DFE4FC /* CornerLabelsModel.swift */, 01509D902327ECE600EF99AA /* CornerLabels.swift */, D224798823142BF2003FCCF9 /* SwitchMolecules */, ); @@ -1550,6 +1553,7 @@ 011B58F423A2CCC80085F53C /* DropDownModel.swift in Sources */, D28A838523CCCA8900DFE4FC /* ScrollerModel.swift in Sources */, D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */, + D28A839123CD4FD400DFE4FC /* CornerLabelsModel.swift in Sources */, 012A88F123985E0100FE3DA1 /* Color.swift in Sources */, 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index edd59574..de4d6d4a 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -37,7 +37,6 @@ open class DashLine: View { required public init?(coder: NSCoder) { super.init(coder: coder) - fatalError("DashLine xib not supported") } //------------------------------------------------------ diff --git a/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift b/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift index 9b7dc062..bde3ab6f 100644 --- a/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift +++ b/MVMCoreUI/Molecules/LeftRightViews/CornerLabels.swift @@ -178,3 +178,21 @@ import UIKit return 34 } } + +extension CornerLabels: MoleculeViewProtocol { + public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + guard let model = model as? CornerLabelsModel, + let data = try? model.encode(using: JSONEncoder()), + let json = try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.init()) as? [AnyHashable: Any] else { + return + } + self.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) +// topLeftLabel.setWithModel(model.topLeftLabel, delegateObject, additionalData) +// topRightLabel.setWithModel(model.topRightLabel, delegateObject, additionalData) +// bottomLeftLabel.setWithModel(model.bottomLeftLabel, delegateObject, additionalData) +// bottomRightLabel.setWithModel(model.bottomRightLabel, delegateObject, additionalData) +// +// topLabelToMoleculeConstraint?.constant = (molecule != nil && (topLeftLabel.hasText || topRightLabel.hasText)) ? spaceAboveMolecule : 0 +// bottomLabelToMoleculeConstraint?.constant = (molecule != nil && (bottomLeftLabel.hasText || bottomRightLabel.hasText)) ? spaceBelowMolecule : 0 + } +} diff --git a/MVMCoreUI/Molecules/LeftRightViews/CornerLabelsModel.swift b/MVMCoreUI/Molecules/LeftRightViews/CornerLabelsModel.swift new file mode 100644 index 00000000..c61bd408 --- /dev/null +++ b/MVMCoreUI/Molecules/LeftRightViews/CornerLabelsModel.swift @@ -0,0 +1,52 @@ +// +// CornerLabelsModel.swift +// MVMCoreUI +// +// Created by Scott Pfeil on 1/13/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +public class CornerLabelsModel: MoleculeProtocol { + public static var identifier: String = "cornerLabels" + public var backgroundColor: Color? + public var topLeftLabel: LabelModel? + public var topRightLabel: LabelModel? + public var bottomLeftLabel: LabelModel? + public var bottomRightLabel: LabelModel? + public var molecule: MoleculeProtocol + + init(with molecule: MoleculeProtocol) { + self.molecule = molecule + } + + enum CodingKeys: String, CodingKey { + case backgroundColor + case topLeftLabel + case topRightLabel + case bottomLeftLabel + case bottomRightLabel + case molecule + } + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + topLeftLabel = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .topLeftLabel) + topRightLabel = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .topRightLabel) + bottomLeftLabel = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .bottomLeftLabel) + bottomRightLabel = try typeContainer.decodeIfPresent(LabelModel.self, forKey: .bottomRightLabel) + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encodeModelIfPresent(molecule, forKey: .molecule) + try container.encodeIfPresent(topLeftLabel, forKey: .topLeftLabel) + try container.encodeIfPresent(topRightLabel, forKey: .topRightLabel) + try container.encodeIfPresent(bottomLeftLabel, forKey: .bottomLeftLabel) + try container.encodeIfPresent(bottomRightLabel, forKey: .bottomRightLabel) + } +} diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 21895f3d..53d14e44 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -23,6 +23,7 @@ import Foundation ModelRegistry.register(ImageViewModel.self) ModelRegistry.register(TabsModel.self) ModelRegistry.register(ScrollerModel.self) + ModelRegistry.register(CornerLabelsModel.self) // buttons ModelRegistry.register(LineModel.self) ModelRegistry.register(ButtonModel.self)