From 88eec2bf9ded5e980e119c8d29191125895470e9 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Tue, 5 Nov 2019 09:25:27 -0500 Subject: [PATCH] carrots and windows. --- .../Atoms/TextFields/DropdownEntryField.swift | 10 +-- MVMCoreUI/Atoms/Views/CaretView.swift | 72 +++++++++---------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift index fe5f44b7..4d418ede 100644 --- a/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift +++ b/MVMCoreUI/Atoms/TextFields/DropdownEntryField.swift @@ -18,8 +18,11 @@ import UIKit let caret = CaretView() // caret.size = .medium caret.direction = .down - caret.isHidden = true + caret.lineWidth = 1.5 +// caret.isHidden = true caret.isUserInteractionEnabled = true + caret.heightAnchor.constraint(equalToConstant: 9).isActive = true + caret.widthAnchor.constraint(equalToConstant: 16).isActive = true return caret }() @@ -92,15 +95,14 @@ import UIKit container.addSubview(dropDownCaretView) - dropDownCaretView.heightAnchor.constraint(equalToConstant: 9).isActive = true - dropDownCaretView.widthAnchor.constraint(equalToConstant: 16).isActive = true - textFieldTrailingConstraint?.isActive = false dropDownCaretView.topAnchor.constraint(greaterThanOrEqualTo: container.topAnchor, constant: 13).isActive = true textFieldTrailingConstraint = dropDownCaretView.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 6) textFieldTrailingConstraint?.isActive = true container.trailingAnchor.constraint(equalTo: dropDownCaretView.trailingAnchor, constant: 16).isActive = true container.bottomAnchor.constraint(greaterThanOrEqualTo: dropDownCaretView.bottomAnchor, constant: 13).isActive = true + + dropDownCaretView.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true } //-------------------------------------------------- diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index 4b13d5fa..8d44e343 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -12,13 +12,13 @@ // MARK: - Properties //------------------------------------------------------ + private var caretPath: UIBezierPath = UIBezierPath() public var strokeColor: UIColor = .black public var lineWidth: CGFloat = 1 + public var direction: Direction = .right -// public var size: CaretSize? - - private var caretPath: UIBezierPath = UIBezierPath() - + public var size: CaretSize? + public var enabledColor: UIColor = .black public var disabledColor: UIColor = .mfSilver() @@ -33,29 +33,33 @@ // MARK: - Constraints //------------------------------------------------------ -// public enum CaretSize: String { -// case small -// case medium -// case large -// -// // Dimensions of container; provided by InVision. -// func dimensions() -> CGSize { -// -// switch self { -// case .small: -// return CGSize(width: 6, height: 10) -// -// case .medium: -// return CGSize(width: 9, height: 16) -// -// case .large: -// return CGSize(width: 14, height: 24) -// } -// } -// } - -// public var heightConstraint: NSLayoutConstraint? -// public var widthConstraint: NSLayoutConstraint? + /// Sizes of CaretView are derived from InVision design specs. They are provided for convenience. + public enum CaretSize { + case small(Orientation) + case medium(Orientation) + case large(Orientation) + + /// Orientation based on the longest line of the view + public enum Orientation { + case vertical + case horizontal + } + + // Dimensions of container; provided by InVision. + func dimensions() -> CGSize { + + switch self { + case .small(let o): + return o == .vertical ? CGSize(width: 6, height: 10) : CGSize(width: 10, height: 6) + + case .medium(let o): + return o == .vertical ? CGSize(width: 9, height: 16) : CGSize(width: 16, height: 9) + + case .large(let o): + return o == .vertical ? CGSize(width: 14, height: 24) : CGSize(width: 24, height: 14) + } + } + } //------------------------------------------------------ // MARK: - Initialization @@ -86,10 +90,6 @@ @objc override open func setupView() { defaultState() - - // Establishing references. -// heightConstraint = heightAnchor.constraint(equalToConstant: 0) -// widthConstraint = widthAnchor.constraint(equalToConstant: 0) } //------------------------------------------------------ @@ -162,12 +162,10 @@ @objc public func setConstraints() { -// guard let dimensions = size?.dimensions() else { return } -// -// heightConstraint?.constant = dimensions.height -// heightConstraint?.isActive = true -// widthConstraint?.constant = dimensions.width -// widthConstraint?.isActive = true + guard let dimensions = size?.dimensions() else { return } + + heightAnchor.constraint(equalToConstant: dimensions.height).isActive = true + widthAnchor.constraint(equalToConstant: dimensions.width).isActive = true } //------------------------------------------------------