latest state
This commit is contained in:
parent
10e4711c90
commit
b6af3ced00
@ -13,12 +13,72 @@ open class Arrow: View {
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
var arrowLayer = CAShapeLayer()
|
||||||
|
var lineWidth: CGFloat = 1
|
||||||
|
var color: UIColor = .black
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Lifecycle
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.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]?) {
|
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||||
guard let model = model as? ArrowModel else { return }
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,8 @@ open class ArrowModel: MoleculeModelProtocol {
|
|||||||
public static var identifier: String = "arrow"
|
public static var identifier: String = "arrow"
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
|
||||||
public var color: Color = Color(uiColor: .mfLighterGray())
|
public var color: Color = Color(uiColor: .mvmBlack)
|
||||||
public var direction: Bool?
|
public var direction: Double?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Keys
|
// MARK: - Keys
|
||||||
@ -28,6 +28,7 @@ open class ArrowModel: MoleculeModelProtocol {
|
|||||||
case backgroundColor
|
case backgroundColor
|
||||||
case color
|
case color
|
||||||
case direction
|
case direction
|
||||||
|
case size
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -36,12 +37,13 @@ open class ArrowModel: MoleculeModelProtocol {
|
|||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) {
|
if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .color) {
|
||||||
self.color = 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 {
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
|||||||
@ -50,6 +50,7 @@ import Foundation
|
|||||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Toggle.self, viewModelClass: ToggleModel.self)
|
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Toggle.self, viewModelClass: ToggleModel.self)
|
||||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self)
|
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Checkbox.self, viewModelClass: CheckboxModel.self)
|
||||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CheckboxLabel.self, viewModelClass: CheckboxLabelModel.self)
|
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CheckboxLabel.self, viewModelClass: CheckboxLabelModel.self)
|
||||||
|
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Arrow.self, viewModelClass: ArrowModel.self)
|
||||||
|
|
||||||
// Horizontal Combination Molecules
|
// Horizontal Combination Molecules
|
||||||
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self)
|
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: StringAndMoleculeView.self, viewModelClass: StringAndMoleculeModel.self)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user