latest and greatest.
This commit is contained in:
parent
475d08296b
commit
bb3277e1ba
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
|
|
||||||
open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol {
|
open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUIViewConstrainingProtocol {
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -54,15 +53,16 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI
|
|||||||
public func updateView(_ size: CGFloat) { }
|
public func updateView(_ size: CGFloat) { }
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Functions
|
// MARK: - Methods
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
private func changeCaretColor() {
|
private func changeCaretColor() {
|
||||||
|
|
||||||
setTitleColor(enabledColor, for: .normal)
|
setTitleColor(enabledColor, for: .normal)
|
||||||
setTitleColor(disabledColor, for: .disabled)
|
setTitleColor(disabledColor, for: .disabled)
|
||||||
|
|
||||||
if let rightCaretView = rightView as? CaretView {
|
if let rightCaretView = rightView as? CaretView {
|
||||||
rightCaretView.setLineColor(isEnabled ? enabledColor : disabledColor)
|
rightCaretView.isEnabled = isEnabled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,8 +81,8 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI
|
|||||||
rightView?.translatesAutoresizingMaskIntoConstraints = false
|
rightView?.translatesAutoresizingMaskIntoConstraints = false
|
||||||
addSubview(caretView)
|
addSubview(caretView)
|
||||||
|
|
||||||
NSLayoutConstraint(item: caretView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width).isActive = true
|
caretView.widthAnchor.constraint(equalToConstant: width).isActive = true
|
||||||
NSLayoutConstraint(item: caretView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: height).isActive = true
|
caretView.heightAnchor.constraint(equalToConstant: height).isActive = true
|
||||||
|
|
||||||
let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0)
|
let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0)
|
||||||
caretLabelSpacing.isActive = true
|
caretLabelSpacing.isActive = true
|
||||||
@ -91,6 +91,7 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI
|
|||||||
NSLayoutConstraint(item: caretView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true
|
NSLayoutConstraint(item: caretView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true
|
||||||
NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretView, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
|
NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretView, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
|
||||||
contentHorizontalAlignment = .left
|
contentHorizontalAlignment = .left
|
||||||
|
|
||||||
//set correct color after layout
|
//set correct color after layout
|
||||||
changeCaretColor()
|
changeCaretColor()
|
||||||
}
|
}
|
||||||
@ -135,10 +136,10 @@ open class CaretButton: MFCustomButton, MVMCoreUIMoleculeViewProtocol, MVMCoreUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func alignment() -> UIStackView.Alignment {
|
open func alignment() -> UIStackView.Alignment {
|
||||||
return UIStackView.Alignment.leading;
|
return .leading
|
||||||
}
|
}
|
||||||
|
|
||||||
public class func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
public class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
|
||||||
return 10
|
return 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,6 +71,10 @@ import UIKit
|
|||||||
fatalError("DropdownEntryField does not support xib.")
|
fatalError("DropdownEntryField does not support xib.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Setup
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private func setup() {
|
private func setup() {
|
||||||
|
|
||||||
dropDownCaretLabel.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
dropDownCaretLabel.heightAnchor.constraint(equalToConstant: 40).isActive = true
|
||||||
@ -84,13 +88,15 @@ import UIKit
|
|||||||
|
|
||||||
open override func setupFieldContainerContent(_ container: UIView) {
|
open override func setupFieldContainerContent(_ container: UIView) {
|
||||||
|
|
||||||
let tapOnCarrot = UITapGestureRecognizer(target: self, action: #selector(startEditing))
|
let tapOnCaret = UITapGestureRecognizer(target: self, action: #selector(startEditing))
|
||||||
dropDownCaretLabel.addGestureRecognizer(tapOnCarrot)
|
dropDownCaretLabel.addGestureRecognizer(tapOnCaret)
|
||||||
|
|
||||||
container.addSubview(dropDownCaretLabel)
|
container.addSubview(dropDownCaretLabel)
|
||||||
|
|
||||||
|
textFieldTrailingConstraint?.isActive = false
|
||||||
dropDownCaretLabel.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
|
dropDownCaretLabel.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
|
||||||
dropDownCaretLabel.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 6).isActive = true
|
textFieldTrailingConstraint = dropDownCaretLabel.leadingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 6)
|
||||||
|
textFieldTrailingConstraint?.isActive = true
|
||||||
container.trailingAnchor.constraint(equalTo: dropDownCaretLabel.trailingAnchor, constant: 16).isActive = true
|
container.trailingAnchor.constraint(equalTo: dropDownCaretLabel.trailingAnchor, constant: 16).isActive = true
|
||||||
container.bottomAnchor.constraint(equalTo: dropDownCaretLabel.bottomAnchor).isActive = true
|
container.bottomAnchor.constraint(equalTo: dropDownCaretLabel.bottomAnchor).isActive = true
|
||||||
dropDownCaretWidth = dropDownCaretLabel.widthAnchor.constraint(equalToConstant: 0)
|
dropDownCaretWidth = dropDownCaretLabel.widthAnchor.constraint(equalToConstant: 0)
|
||||||
|
|||||||
@ -67,7 +67,6 @@ import UIKit
|
|||||||
layer.backgroundColor = UIColor.black.cgColor
|
layer.backgroundColor = UIColor.black.cgColor
|
||||||
layer.drawsAsynchronously = true
|
layer.drawsAsynchronously = true
|
||||||
layer.anchorPoint = CGPoint(x: 0.5, y: 1.0);
|
layer.anchorPoint = CGPoint(x: 0.5, y: 1.0);
|
||||||
|
|
||||||
return layer
|
return layer
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@ -145,9 +145,9 @@ import UIKit
|
|||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
textField.heightAnchor.constraint(equalToConstant: 24),
|
textField.heightAnchor.constraint(equalToConstant: 24),
|
||||||
textField.topAnchor.constraint(equalTo: container.topAnchor, constant: 10),
|
textField.topAnchor.constraint(equalTo: container.topAnchor, constant: 12),
|
||||||
textField.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 16),
|
textField.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 16),
|
||||||
container.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 10)])
|
container.bottomAnchor.constraint(equalTo: textField.bottomAnchor, constant: 12)])
|
||||||
|
|
||||||
textFieldTrailingConstraint = container.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 16)
|
textFieldTrailingConstraint = container.trailingAnchor.constraint(equalTo: textField.trailingAnchor, constant: 16)
|
||||||
textFieldTrailingConstraint?.isActive = true
|
textFieldTrailingConstraint?.isActive = true
|
||||||
|
|||||||
@ -12,17 +12,51 @@
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
// Objc can't use float enum.
|
|
||||||
public static let thin: CGFloat = 6.0
|
|
||||||
public static let standard: CGFloat = 2.5
|
|
||||||
public static let thick: CGFloat = 1.5
|
|
||||||
|
|
||||||
public var strokeColor: UIColor = .black
|
public var strokeColor: UIColor = .black
|
||||||
public var lineWidth: CGFloat = 1
|
public var lineWidth: CGFloat = 1
|
||||||
public var direction: Direction = .right
|
public var direction: Direction = .right
|
||||||
|
public var size: CaretSize?
|
||||||
|
|
||||||
private var caretPath: UIBezierPath = UIBezierPath()
|
private var caretPath: UIBezierPath = UIBezierPath()
|
||||||
|
|
||||||
|
public var enabledColor: UIColor = .black
|
||||||
|
public var disabledColor: UIColor = .mfSilver()
|
||||||
|
|
||||||
|
public var isEnabled: Bool = true {
|
||||||
|
didSet {
|
||||||
|
strokeColor = isEnabled ? enabledColor : disabledColor
|
||||||
|
setNeedsDisplay()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
// 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?
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -31,28 +65,31 @@
|
|||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public init() {
|
@objc public convenience init() {
|
||||||
super.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public init(lineWidth: CGFloat) {
|
@objc public convenience init(lineWidth: CGFloat) {
|
||||||
super.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
self.lineWidth = lineWidth
|
self.lineWidth = lineWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Can init with a specific line thickness, scales based on width and height.
|
|
||||||
@objc public init(lineThickness: CGFloat) {
|
|
||||||
super.init(frame: .zero)
|
|
||||||
// self.lineThickness = lineThickness
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc required public init?(coder aDecoder: NSCoder) {
|
@objc required public init?(coder aDecoder: NSCoder) {
|
||||||
super.init(coder: aDecoder)
|
super.init(coder: aDecoder)
|
||||||
fatalError("CaretView xib not supported.")
|
fatalError("CaretView xib not supported.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
// MARK: - Setup
|
||||||
|
//------------------------------------------------------
|
||||||
|
|
||||||
@objc override open func setupView() {
|
@objc override open func setupView() {
|
||||||
|
|
||||||
defaultState()
|
defaultState()
|
||||||
|
|
||||||
|
// Establishing references.
|
||||||
|
heightConstraint = heightAnchor.constraint(equalToConstant: 0)
|
||||||
|
widthConstraint = widthAnchor.constraint(equalToConstant: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -60,7 +97,7 @@
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
/// The direction the caret will be pointing to.
|
/// The direction the caret will be pointing to.
|
||||||
public enum Direction: String {
|
@objc public enum Direction: Int {
|
||||||
case left
|
case left
|
||||||
case right
|
case right
|
||||||
case down
|
case down
|
||||||
@ -73,27 +110,30 @@
|
|||||||
caretPath.removeAllPoints()
|
caretPath.removeAllPoints()
|
||||||
caretPath.lineJoinStyle = .miter
|
caretPath.lineJoinStyle = .miter
|
||||||
caretPath.lineWidth = lineWidth
|
caretPath.lineWidth = lineWidth
|
||||||
|
|
||||||
let inset = lineWidth / 2
|
let inset = lineWidth / 2
|
||||||
|
let halfWidth = frame.size.width / 2
|
||||||
|
let halfHeight = frame.size.height / 2
|
||||||
|
|
||||||
switch direction {
|
switch direction {
|
||||||
case .up:
|
case .up:
|
||||||
caretPath.move(to: CGPoint(x: inset, y: frame.size.height - inset))
|
caretPath.move(to: CGPoint(x: inset, y: frame.size.height - inset))
|
||||||
caretPath.addLine(to: CGPoint(x: frame.size.width / 2, y: inset))
|
caretPath.addLine(to: CGPoint(x: halfWidth, y: lineWidth))
|
||||||
caretPath.addLine(to: CGPoint(x: frame.size.width, y: frame.size.height))
|
caretPath.addLine(to: CGPoint(x: frame.size.width, y: frame.size.height))
|
||||||
|
|
||||||
case .right:
|
case .right:
|
||||||
caretPath.move(to: CGPoint(x: inset, y: inset))
|
caretPath.move(to: CGPoint(x: inset, y: inset))
|
||||||
caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: frame.size.height / 2))
|
caretPath.addLine(to: CGPoint(x: frame.size.width - lineWidth, y: halfHeight))
|
||||||
caretPath.addLine(to: CGPoint(x: inset, y: frame.size.height - inset))
|
caretPath.addLine(to: CGPoint(x: inset, y: frame.size.height - inset))
|
||||||
|
|
||||||
case .down:
|
case .down:
|
||||||
caretPath.move(to: CGPoint(x: inset, y: inset))
|
caretPath.move(to: CGPoint(x: inset, y: inset))
|
||||||
caretPath.addLine(to: CGPoint(x: frame.size.width / 2, y: frame.size.height - inset))
|
caretPath.addLine(to: CGPoint(x: halfWidth, y: frame.size.height - lineWidth))
|
||||||
caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: inset))
|
caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: inset))
|
||||||
|
|
||||||
case .left:
|
case .left:
|
||||||
caretPath.move(to: CGPoint(x: frame.size.width - inset, y: inset))
|
caretPath.move(to: CGPoint(x: frame.size.width - inset, y: inset))
|
||||||
caretPath.addLine(to: CGPoint(x: inset, y: frame.size.height / 2))
|
caretPath.addLine(to: CGPoint(x: lineWidth, y: halfHeight))
|
||||||
caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: frame.size.height - inset))
|
caretPath.addLine(to: CGPoint(x: frame.size.width - inset, y: frame.size.height - inset))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +146,29 @@
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
@objc public func setLineColor(_ color: UIColor) {
|
@objc public func setLineColor(_ color: UIColor) {
|
||||||
|
|
||||||
strokeColor = color
|
strokeColor = color
|
||||||
setNeedsDisplay()
|
setNeedsDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func defaultState() {
|
@objc public func defaultState() {
|
||||||
|
|
||||||
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
isOpaque = false
|
isOpaque = false
|
||||||
isHidden = false
|
isHidden = false
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
strokeColor = .black
|
strokeColor = .black
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Atomization
|
// MARK: - Atomization
|
||||||
@ -127,7 +179,7 @@
|
|||||||
defaultState()
|
defaultState()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
@objc open override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
|
||||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
|
|
||||||
guard let dictionary = json else { return }
|
guard let dictionary = json else { return }
|
||||||
@ -149,11 +201,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func needsToBeConstrained() -> Bool {
|
@objc open override func needsToBeConstrained() -> Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func alignment() -> UIStackView.Alignment {
|
@objc open override func alignment() -> UIStackView.Alignment {
|
||||||
return .leading
|
return .leading
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,12 +51,7 @@ open class DashLine: MFView {
|
|||||||
dashLayer.backgroundColor = UIColor.clear.cgColor
|
dashLayer.backgroundColor = UIColor.clear.cgColor
|
||||||
dashLayer.frame = bounds
|
dashLayer.frame = bounds
|
||||||
|
|
||||||
if let sublayers = layer.sublayers {
|
layer.sublayers?.forEach { $0.removeFromSuperlayer() }
|
||||||
for sublayer in sublayers {
|
|
||||||
sublayer.removeFromSuperlayer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
layer.addSublayer(dashLayer)
|
layer.addSublayer(dashLayer)
|
||||||
|
|
||||||
let path = UIBezierPath()
|
let path = UIBezierPath()
|
||||||
|
|||||||
@ -204,13 +204,17 @@ import UIKit
|
|||||||
// MARK: - Arrow
|
// MARK: - Arrow
|
||||||
/// Adds the standard mvm style caret to the accessory view
|
/// Adds the standard mvm style caret to the accessory view
|
||||||
@objc public func addCaretViewAccessory() {
|
@objc public func addCaretViewAccessory() {
|
||||||
|
|
||||||
guard accessoryView == nil else { return }
|
guard accessoryView == nil else { return }
|
||||||
let width: CGFloat = 6
|
|
||||||
let height: CGFloat = 10
|
caretView = CaretView(lineWidth: 1)
|
||||||
caretView = CaretView(lineThickness: CaretView.thin)
|
caretView?.size = .small
|
||||||
caretView?.frame = CGRect(x: 0, y: 0, width: width, height: height)
|
caretView?.setConstraints()
|
||||||
caretViewWidthSizeObject = MFSizeObject(standardSize: width, standardiPadPortraitSize: 9)
|
|
||||||
caretViewHeightSizeObject = MFSizeObject(standardSize: height, standardiPadPortraitSize: 16)
|
if let size = caretView?.size?.dimensions() {
|
||||||
|
caretViewWidthSizeObject = MFSizeObject(standardSize: size.width, standardiPadPortraitSize: 9)
|
||||||
|
caretViewHeightSizeObject = MFSizeObject(standardSize: size.height, standardiPadPortraitSize: 16)
|
||||||
|
}
|
||||||
accessoryView = caretView
|
accessoryView = caretView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user