diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index d8fdebc0..da572062 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -96,6 +96,8 @@ 0AE14F64238315D2005417F8 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE14F63238315D2005417F8 /* TextField.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,6 +437,8 @@ 0AE14F63238315D2005417F8 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.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 = ""; }; @@ -1337,6 +1341,8 @@ 0AA33B392398524F0067DD0F /* Toggle.swift */, D260105423CEA7DC00764D80 /* MVMCoreUISwitch+Model.swift */, 012CA99D2385A2D3003F810F /* MFView+ModelExtension.swift */, + 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */, + 0AE98BB423FF18D2004C5109 /* Arrow.swift */, ); path = Views; sourceTree = ""; @@ -1851,6 +1857,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 */, D2D90B442404789000DD6EC9 /* MoleculeContainerProtocol.swift in Sources */, 012A88DB238ED45900FE3DA1 /* CarouselModel.swift in Sources */, @@ -1875,6 +1882,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..e932dd60 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/Arrow.swift @@ -0,0 +1,100 @@ +// +// Arrow.swift +// MVMCoreUI +// +// Created by Kevin Christiano on 2/20/20. +// Copyright © 2020 Verizon Wireless. All rights reserved. +// + +import UIKit + +open class Arrow: View { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + var arrowLayer = CAShapeLayer() + + public var arrowModel: ArrowModel? { + 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 + //-------------------------------------------------- + + open override func setupView() { + super.setupView() + + drawShapeLayer() + isOpaque = false + layer.addSublayer(arrowLayer) + arrowLayer.strokeEnd = 1 + } + + //-------------------------------------------------- + // 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 = arrowModel?.color.cgColor + arrowLayer.fillColor = UIColor.clear.cgColor + arrowLayer.path = arrowPath() + arrowLayer.lineJoin = .miter + arrowLayer.lineCap = .butt + arrowLayer.lineWidth = arrowModel?.lineWidth ?? 1 + } + + private func arrowPath() -> CGPath { + + let length = max(bounds.size.height, bounds.size.width) + let inset = (arrowModel?.lineWidth ?? 1) / 2 + let midLength = length / 2 + + 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: inset, y: midLength) + endPoint = CGPoint(x: length - inset, y: midLength) + + bezierPath.move(to: startPoint) + bezierPath.addLine(to: pivotPoint) + + return bezierPath.cgPath + } +} diff --git a/MVMCoreUI/Atoms/Views/ArrowModel.swift b/MVMCoreUI/Atoms/Views/ArrowModel.swift new file mode 100644 index 00000000..2547f8d1 --- /dev/null +++ b/MVMCoreUI/Atoms/Views/ArrowModel.swift @@ -0,0 +1,80 @@ +// +// 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: .mvmBlack) + public var degrees: Float = 0 + public var lineWidth: CGFloat = 1 + + public var height: CGFloat = 12 + public var width: CGFloat = 12 + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case moleculeName + case backgroundColor + case color + case degrees + case size + case lineWidth + case height + case width + } + + //-------------------------------------------------- + // MARK: - Codec + //-------------------------------------------------- + + 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 + } + + 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 + } + + 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 { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(moleculeName, forKey: .moleculeName) + try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) + 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) + } +} diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 25ebe9b3..b65c248e 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -51,6 +51,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)