From b96b48787c97d2f4ba66462d92126354a4d67b52 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 20 Feb 2020 14:49:25 -0500 Subject: [PATCH 01/10] beginning arrow molecule --- MVMCoreUI.xcodeproj/project.pbxproj | 8 ++++ MVMCoreUI/Atoms/Views/Arrow.swift | 21 ++++++++++ MVMCoreUI/Atoms/Views/ArrowModel.swift | 54 ++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 MVMCoreUI/Atoms/Views/Arrow.swift create mode 100644 MVMCoreUI/Atoms/Views/ArrowModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 281a0672..a9f666c3 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -94,6 +94,8 @@ 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; }; 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; }; 0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; }; + 0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB423FF18D2004C5109 /* Arrow.swift */; }; + 0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */; }; 31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; }; 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; }; 5248BFEC23F12E350059236A /* ListThreeColumnPlanDataDivider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5248BFEA23F12E350059236A /* ListThreeColumnPlanDataDivider.swift */; }; @@ -420,6 +422,8 @@ 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = ""; }; 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = ""; }; 0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = ""; }; + 0AE98BB423FF18D2004C5109 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = ""; }; + 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowModel.swift; sourceTree = ""; }; 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = ""; }; 31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = ""; }; 5248BFEA23F12E350059236A /* ListThreeColumnPlanDataDivider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListThreeColumnPlanDataDivider.swift; sourceTree = ""; }; @@ -1283,6 +1287,8 @@ 0AA33B392398524F0067DD0F /* Toggle.swift */, D260105423CEA7DC00764D80 /* MVMCoreUISwitch+Model.swift */, 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, + 0AE98BB423FF18D2004C5109 /* Arrow.swift */, + 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */, ); path = Views; sourceTree = ""; @@ -1785,6 +1791,7 @@ D224798A2314445E003FCCF9 /* LabelToggle.swift in Sources */, D22D1F47220496A30077CEC0 /* MVMCoreUISwitch.m in Sources */, C695A67F23C9830600BFB94E /* UnOrderedListModel.swift in Sources */, + 0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */, 017BEB4223620AD20024EF95 /* FormModelProtocol.swift in Sources */, 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */, D29DF28C21E7AC2B003B2FB9 /* ViewConstrainingView.m in Sources */, @@ -1808,6 +1815,7 @@ 01EB369323609801006832FA /* HeaderModel.swift in Sources */, D2E1FADF2268B8E700AEFD8C /* ThreeLayerTableViewController.swift in Sources */, 0A21DB83235DFBC500C160A2 /* MdnEntryField.swift in Sources */, + 0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */, D28A837D23CCA86A00DFE4FC /* TabsListItemModel.swift in Sources */, 012A88C6238DA34000FE3DA1 /* ModuleMoleculeModel.swift in Sources */, 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */, diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift new file mode 100644 index 00000000..f2e98abb --- /dev/null +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -0,0 +1,21 @@ +// +// Arrow.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 2/20/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +class Arrow: View { + + /* + // Only override draw() if you perform custom drawing. + // An empty implementation adversely affects performance during animation. + override func draw(_ rect: CGRect) { + // Drawing code + } + */ + +} diff --git a/MVMCoreUI/Atoms/Views/ArrowModel.swift b/MVMCoreUI/Atoms/Views/ArrowModel.swift new file mode 100644 index 00000000..00e85cfb --- /dev/null +++ b/MVMCoreUI/Atoms/Views/ArrowModel.swift @@ -0,0 +1,54 @@ +// +// ArrowModel.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 2/20/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +open class ArrowModel: MoleculeModelProtocol { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + public static var identifier: String = "arrow" + public var backgroundColor: Color? + + public var color: Color = Color(uiColor: .mfLighterGray()) + public var direction: Bool? + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case moleculeName + case backgroundColor + case color + case direction + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) { + self.color = color + } + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + direction = try typeContainer.decodeIfPresent(Bool.self, forKey: .direction) + + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encode(color, forKey: .color) + try container.encode(direction, forKey: .direction) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + } +} From 73bd5ebafc5596c18cf9fd48ac766209c6c7b103 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 26 Feb 2020 13:36:02 -0500 Subject: [PATCH 02/10] wipppp --- MVMCoreUI/Atoms/Views/Arrow.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index f2e98abb..2103d73f 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -8,14 +8,16 @@ import UIKit -class Arrow: View { +open class Arrow: View { - /* - // Only override draw() if you perform custom drawing. - // An empty implementation adversely affects performance during animation. - override func draw(_ rect: CGRect) { - // Drawing code + + open override func setupView() { + super.setupView() } - */ + //MARK: - MVMCoreMoleculeViewProtocol + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + guard let progressBarModel = model as? ArrowModel else { return } + + } } From 10e4711c9075d003db0d497803d553779ff2a357 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 26 Feb 2020 13:44:17 -0500 Subject: [PATCH 03/10] wipppp --- MVMCoreUI/Atoms/Views/Arrow.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 2103d73f..96f2bb9a 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -9,15 +9,24 @@ import UIKit open class Arrow: View { - + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + //-------------------------------------------------- + // MARK: - Lifecycle + //-------------------------------------------------- open override func setupView() { super.setupView() } - - //MARK: - MVMCoreMoleculeViewProtocol + + //-------------------------------------------------- + // MARK: - MVMCoreMoleculeViewProtocol + //-------------------------------------------------- + public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let progressBarModel = model as? ArrowModel else { return } - + guard let model = model as? ArrowModel else { return } + } } From b6af3ced00202d9ec31ad62981792b048615a010 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 10:12:43 -0500 Subject: [PATCH 04/10] latest state --- MVMCoreUI/Atoms/Views/Arrow.swift | 66 +++++++++++++++++++ MVMCoreUI/Atoms/Views/ArrowModel.swift | 10 +-- .../OtherHandlers/MoleculeObjectMapping.swift | 1 + 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 96f2bb9a..59e6f6f9 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -13,12 +13,72 @@ open class Arrow: View { // MARK: - Properties //-------------------------------------------------- + var arrowLayer = CAShapeLayer() + var lineWidth: CGFloat = 1 + var color: UIColor = .black + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- open override func setupView() { super.setupView() + + heightAnchor.constraint(equalToConstant: 12).isActive = true + widthAnchor.constraint(equalToConstant: 12).isActive = true + + drawShapeLayer() + isOpaque = false + layer.addSublayer(arrowLayer) + arrowLayer.strokeEnd = 1 + } + + override open func layoutSubviews() { + super.layoutSubviews() + + drawShapeLayer() +// layer.cornerRadius = isRound ? cornerRadiusValue : 0 + } + + //-------------------------------------------------- + // MARK: - Drawing + //-------------------------------------------------- + + private func drawShapeLayer() { + + arrowLayer.frame = bounds + arrowLayer.strokeColor = color.cgColor + arrowLayer.fillColor = UIColor.clear.cgColor + arrowLayer.path = arrowPath() + arrowLayer.lineJoin = .miter + arrowLayer.lineCap = .butt + arrowLayer.lineWidth = lineWidth + } + + private func arrowPath() -> CGPath { + + let length = max(bounds.size.height, bounds.size.width) - 1 +// let xInsetLeft = length * 0.25 +// let yInsetTop = length * 0.3 +// let innerWidth = length - (xInsetLeft + length * 0.25) // + Right X Inset +// let innerHeight = length - (yInsetTop + length * 0.35) // + Bottom Y Inset + + var startPoint = CGPoint(x: length * 0.5, y: 1) + let pivotPoint = CGPoint(x: length, y: length * 0.5) + var endPoint = CGPoint(x: length * 0.5, y: length) + + let bezierPath = UIBezierPath() + bezierPath.move(to: startPoint) + bezierPath.addLine(to: pivotPoint) + bezierPath.addLine(to: endPoint) + + startPoint = CGPoint(x: 1, y: length * 0.5) + endPoint = CGPoint(x: length, y: length * 0.5) + + bezierPath.move(to: startPoint) + bezierPath.addLine(to: pivotPoint) + + return bezierPath.cgPath } //-------------------------------------------------- @@ -28,5 +88,11 @@ open class Arrow: View { public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { guard let model = model as? ArrowModel else { return } + arrowLayer.transform = CATransform3DIdentity + + if let degrees = model.direction { + let radians = CGFloat(degrees * Double.pi / 180) + arrowLayer.transform = CATransform3DMakeRotation(-radians, 0.0, 0.0, 1.0) + } } } diff --git a/MVMCoreUI/Atoms/Views/ArrowModel.swift b/MVMCoreUI/Atoms/Views/ArrowModel.swift index 00e85cfb..62bf5c05 100644 --- a/MVMCoreUI/Atoms/Views/ArrowModel.swift +++ b/MVMCoreUI/Atoms/Views/ArrowModel.swift @@ -16,8 +16,8 @@ open class ArrowModel: MoleculeModelProtocol { public static var identifier: String = "arrow" public var backgroundColor: Color? - public var color: Color = Color(uiColor: .mfLighterGray()) - public var direction: Bool? + public var color: Color = Color(uiColor: .mvmBlack) + public var direction: Double? //-------------------------------------------------- // MARK: - Keys @@ -28,6 +28,7 @@ open class ArrowModel: MoleculeModelProtocol { case backgroundColor case color case direction + case size } //-------------------------------------------------- @@ -36,12 +37,13 @@ open class ArrowModel: MoleculeModelProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) { self.color = color } - backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - direction = try typeContainer.decodeIfPresent(Bool.self, forKey: .direction) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + direction = try typeContainer.decodeIfPresent(Double.self, forKey: .direction) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index ac7375d7..8cabfa3f 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -50,6 +50,7 @@ import Foundation MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Toggle.self, viewModelClass: ToggleModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CheckboxLabel.self, viewModelClass: CheckboxLabelModel.self) + MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Arrow.self, viewModelClass: ArrowModel.self) // Horizontal Combination Molecules MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self) From 5640129cdfe779595c8a130f4165372303694496 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 11:44:24 -0500 Subject: [PATCH 05/10] working state of arrow --- MVMCoreUI/Atoms/Views/Arrow.swift | 66 +++++++++++--------------- MVMCoreUI/Atoms/Views/ArrowModel.swift | 21 +++++--- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 59e6f6f9..7e1a510a 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -14,8 +14,10 @@ open class Arrow: View { //-------------------------------------------------- var arrowLayer = CAShapeLayer() - var lineWidth: CGFloat = 1 - var color: UIColor = .black + + public var arrowModel: ArrowModel? { + return model as? ArrowModel + } //-------------------------------------------------- // MARK: - Lifecycle @@ -24,8 +26,8 @@ open class Arrow: View { open override func setupView() { super.setupView() - heightAnchor.constraint(equalToConstant: 12).isActive = true - widthAnchor.constraint(equalToConstant: 12).isActive = true + heightAnchor.constraint(equalToConstant: 40).isActive = true + widthAnchor.constraint(equalToConstant: 40).isActive = true drawShapeLayer() isOpaque = false @@ -33,66 +35,54 @@ open class Arrow: View { arrowLayer.strokeEnd = 1 } - override open func layoutSubviews() { - super.layoutSubviews() - - drawShapeLayer() -// layer.cornerRadius = isRound ? cornerRadiusValue : 0 - } - //-------------------------------------------------- // MARK: - Drawing //-------------------------------------------------- + open override func draw(_ rect: CGRect) { + super.draw(rect) + + arrowLayer.transform = CATransform3DIdentity + drawShapeLayer() + + if let degrees = arrowModel?.degrees { + let radians = CGFloat(degrees * Float.pi / 180) + arrowLayer.transform = CATransform3DMakeRotation(-radians, 0.0, 0.0, 1.0) + } + } + private func drawShapeLayer() { arrowLayer.frame = bounds - arrowLayer.strokeColor = color.cgColor + arrowLayer.strokeColor = arrowModel?.color.cgColor arrowLayer.fillColor = UIColor.clear.cgColor arrowLayer.path = arrowPath() arrowLayer.lineJoin = .miter arrowLayer.lineCap = .butt - arrowLayer.lineWidth = lineWidth + arrowLayer.lineWidth = arrowModel?.lineWidth ?? 1 } private func arrowPath() -> CGPath { - let length = max(bounds.size.height, bounds.size.width) - 1 -// let xInsetLeft = length * 0.25 -// let yInsetTop = length * 0.3 -// let innerWidth = length - (xInsetLeft + length * 0.25) // + Right X Inset -// let innerHeight = length - (yInsetTop + length * 0.35) // + Bottom Y Inset + let length = max(bounds.size.height, bounds.size.width) + let inset = (arrowModel?.lineWidth ?? 1) / 2 + let midLength = length / 2 - var startPoint = CGPoint(x: length * 0.5, y: 1) - let pivotPoint = CGPoint(x: length, y: length * 0.5) - var endPoint = CGPoint(x: length * 0.5, y: length) + var startPoint = CGPoint(x: midLength, y: inset) + let pivotPoint = CGPoint(x: length - inset, y: midLength) + var endPoint = CGPoint(x: midLength, y: length - inset) let bezierPath = UIBezierPath() bezierPath.move(to: startPoint) bezierPath.addLine(to: pivotPoint) bezierPath.addLine(to: endPoint) - startPoint = CGPoint(x: 1, y: length * 0.5) - endPoint = CGPoint(x: length, y: length * 0.5) + startPoint = CGPoint(x: inset, y: midLength) + endPoint = CGPoint(x: length - inset, y: midLength) bezierPath.move(to: startPoint) bezierPath.addLine(to: pivotPoint) return bezierPath.cgPath } - - //-------------------------------------------------- - // MARK: - MVMCoreMoleculeViewProtocol - //-------------------------------------------------- - - public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - guard let model = model as? ArrowModel else { return } - - arrowLayer.transform = CATransform3DIdentity - - if let degrees = model.direction { - let radians = CGFloat(degrees * Double.pi / 180) - arrowLayer.transform = CATransform3DMakeRotation(-radians, 0.0, 0.0, 1.0) - } - } } diff --git a/MVMCoreUI/Atoms/Views/ArrowModel.swift b/MVMCoreUI/Atoms/Views/ArrowModel.swift index 62bf5c05..926a9ea7 100644 --- a/MVMCoreUI/Atoms/Views/ArrowModel.swift +++ b/MVMCoreUI/Atoms/Views/ArrowModel.swift @@ -17,7 +17,8 @@ open class ArrowModel: MoleculeModelProtocol { public var backgroundColor: Color? public var color: Color = Color(uiColor: .mvmBlack) - public var direction: Double? + public var degrees: Float = 0 + public var lineWidth: CGFloat = 1 //-------------------------------------------------- // MARK: - Keys @@ -27,8 +28,9 @@ open class ArrowModel: MoleculeModelProtocol { case moleculeName case backgroundColor case color - case direction + case degrees case size + case lineWidth } //-------------------------------------------------- @@ -37,20 +39,27 @@ open class ArrowModel: MoleculeModelProtocol { required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) { self.color = color } - backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - direction = try typeContainer.decodeIfPresent(Double.self, forKey: .direction) + if let degrees = try typeContainer.decodeIfPresent(Float.self, forKey: .degrees) { + self.degrees = degrees + } + + if let lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) { + self.lineWidth = lineWidth + } } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(moleculeName, forKey: .moleculeName) - try container.encode(color, forKey: .color) - try container.encode(direction, forKey: .direction) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + try container.encode(color, forKey: .color) + try container.encode(degrees, forKey: .degrees) + try container.encodeIfPresent(backgroundColor, forKey: .lineWidth) } } From 78673b824ecc128b7ba89db36dbc87f0fc556048 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 11:46:17 -0500 Subject: [PATCH 06/10] removed test code --- MVMCoreUI/Atoms/Views/Arrow.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 7e1a510a..7ae112cc 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -26,9 +26,6 @@ open class Arrow: View { open override func setupView() { super.setupView() - heightAnchor.constraint(equalToConstant: 40).isActive = true - widthAnchor.constraint(equalToConstant: 40).isActive = true - drawShapeLayer() isOpaque = false layer.addSublayer(arrowLayer) From 1ee8c244cd15a3f704658b6eea17ea7a108e0837 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 11:57:10 -0500 Subject: [PATCH 07/10] merging --- MVMCoreUI/Atoms/Views/Arrow.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 7ae112cc..e59b4022 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -26,6 +26,9 @@ open class Arrow: View { open override func setupView() { super.setupView() + heightAnchor.constraint(equalToConstant: 12).isActive = true + widthAnchor.constraint(equalToConstant: 12).isActive = true + drawShapeLayer() isOpaque = false layer.addSublayer(arrowLayer) From c2baebe4831eb84e14dfde88b5572050aa85192a Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 12:00:45 -0500 Subject: [PATCH 08/10] removed testing code --- MVMCoreUI/Atoms/Views/Arrow.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index e59b4022..7ae112cc 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -26,9 +26,6 @@ open class Arrow: View { open override func setupView() { super.setupView() - heightAnchor.constraint(equalToConstant: 12).isActive = true - widthAnchor.constraint(equalToConstant: 12).isActive = true - drawShapeLayer() isOpaque = false layer.addSublayer(arrowLayer) From 6c92652f01cad6a7c618425f3da4b7072c294bff Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 12:31:47 -0500 Subject: [PATCH 09/10] moved files --- MVMCoreUI.xcodeproj/project.pbxproj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index f33d39b2..5c92c180 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -94,10 +94,10 @@ 0ABD136D237CAD1E0081388D /* DateDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */; }; 0ABD1371237DB0450081388D /* ItemDropdownEntryField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */; }; 0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.swift */; }; - 0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB423FF18D2004C5109 /* Arrow.swift */; }; - 0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */; }; 0AE98BAF23FEF956004C5109 /* ExternalLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BAE23FEF956004C5109 /* ExternalLink.swift */; }; 0AE98BB323FF0934004C5109 /* ExternalLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB223FF0934004C5109 /* ExternalLinkModel.swift */; }; + 0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB423FF18D2004C5109 /* Arrow.swift */; }; + 0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */; }; 31BE15CB23D8924D00452370 /* CheckboxLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */; }; 31BE15CC23D8924D00452370 /* CheckboxModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31BE15CA23D8924C00452370 /* CheckboxModel.swift */; }; 522679C123FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */; }; @@ -435,10 +435,10 @@ 0ABD136C237CAD1E0081388D /* DateDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateDropdownEntryField.swift; sourceTree = ""; }; 0ABD1370237DB0450081388D /* ItemDropdownEntryField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemDropdownEntryField.swift; sourceTree = ""; }; 0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = ""; }; - 0AE98BB423FF18D2004C5109 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = ""; }; - 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowModel.swift; sourceTree = ""; }; 0AE98BAE23FEF956004C5109 /* ExternalLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalLink.swift; sourceTree = ""; }; 0AE98BB223FF0934004C5109 /* ExternalLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalLinkModel.swift; sourceTree = ""; }; + 0AE98BB423FF18D2004C5109 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = ""; }; + 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowModel.swift; sourceTree = ""; }; 31BE15C923D8924C00452370 /* CheckboxLabelModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxLabelModel.swift; sourceTree = ""; }; 31BE15CA23D8924C00452370 /* CheckboxModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckboxModel.swift; sourceTree = ""; }; 522679BF23FE886900906CBA /* ListLeftVariableCheckboxAllTextAndLinks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListLeftVariableCheckboxAllTextAndLinks.swift; sourceTree = ""; }; @@ -1341,8 +1341,8 @@ 0AA33B392398524F0067DD0F /* Toggle.swift */, D260105423CEA7DC00764D80 /* MVMCoreUISwitch+Model.swift */, 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, - 0AE98BB423FF18D2004C5109 /* Arrow.swift */, 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */, + 0AE98BB423FF18D2004C5109 /* Arrow.swift */, ); path = Views; sourceTree = ""; From e7b7012708b9f69150938871606d82cd78172188 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 27 Feb 2020 13:00:39 -0500 Subject: [PATCH 10/10] constraint convenience --- MVMCoreUI/Atoms/Views/Arrow.swift | 15 +++++++++++++++ MVMCoreUI/Atoms/Views/ArrowModel.swift | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/MVMCoreUI/Atoms/Views/Arrow.swift b/MVMCoreUI/Atoms/Views/Arrow.swift index 7ae112cc..e932dd60 100644 --- a/MVMCoreUI/Atoms/Views/Arrow.swift +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -19,6 +19,21 @@ open class Arrow: View { return model as? ArrowModel } + //-------------------------------------------------- + // MARK: - Constraints + //-------------------------------------------------- + + public var heightConstraint: NSLayoutConstraint? + public var widthConstraint: NSLayoutConstraint? + + public func pinHeightAndWidth(constant: CGFloat = 12) { + + heightConstraint = heightAnchor.constraint(equalToConstant: constant) + widthConstraint = widthAnchor.constraint(equalToConstant: constant) + heightConstraint?.isActive = true + widthConstraint?.isActive = true + } + //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- diff --git a/MVMCoreUI/Atoms/Views/ArrowModel.swift b/MVMCoreUI/Atoms/Views/ArrowModel.swift index 926a9ea7..2547f8d1 100644 --- a/MVMCoreUI/Atoms/Views/ArrowModel.swift +++ b/MVMCoreUI/Atoms/Views/ArrowModel.swift @@ -20,6 +20,9 @@ open class ArrowModel: MoleculeModelProtocol { public var degrees: Float = 0 public var lineWidth: CGFloat = 1 + public var height: CGFloat = 12 + public var width: CGFloat = 12 + //-------------------------------------------------- // MARK: - Keys //-------------------------------------------------- @@ -31,6 +34,8 @@ open class ArrowModel: MoleculeModelProtocol { case degrees case size case lineWidth + case height + case width } //-------------------------------------------------- @@ -52,6 +57,14 @@ open class ArrowModel: MoleculeModelProtocol { if let lineWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .lineWidth) { self.lineWidth = lineWidth } + + if let height = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .height) { + self.lineWidth = height + } + + if let width = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .width) { + self.width = width + } } public func encode(to encoder: Encoder) throws { @@ -61,5 +74,7 @@ open class ArrowModel: MoleculeModelProtocol { try container.encode(color, forKey: .color) try container.encode(degrees, forKey: .degrees) try container.encodeIfPresent(backgroundColor, forKey: .lineWidth) + try container.encode(width, forKey: .width) + try container.encode(height, forKey: .height) } }