making yupdates

This commit is contained in:
Kevin G Christiano 2020-07-14 16:14:37 -04:00
parent 5894387fd1
commit 4a5856f071
4 changed files with 16 additions and 23 deletions

View File

@ -41,9 +41,10 @@ open class OrderTracker: View {
guard let stepModels = stepModels else { return } guard let stepModels = stepModels else { return }
var anchor = topAnchor
var previousStep: Step? var previousStep: Step?
for (i, stepModel) in stepModels.enumerated() { for stepModel in stepModels {
let step = Step() let step = Step()
step.set(with: stepModel, delegateObject, additionalData) step.set(with: stepModel, delegateObject, additionalData)
@ -52,21 +53,14 @@ open class OrderTracker: View {
step.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true step.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
trailingAnchor.constraint(equalTo: step.trailingAnchor).isActive = true trailingAnchor.constraint(equalTo: step.trailingAnchor).isActive = true
step.topAnchor.constraint(equalTo: anchor).isActive = true
if i == 0 { anchor = step.bottomAnchor
step.topAnchor.constraint(equalTo: topAnchor).isActive = true
} else if let previousStep = previousStep {
step.topAnchor.constraint(equalTo: previousStep.bottomAnchor).isActive = true
}
if i == stepModels.count - 1 {
bottomAnchor.constraint(equalTo: step.bottomAnchor).isActive = true
step.imageBottomConstraint?.constant = 0
}
previousStep = step previousStep = step
} }
bottomAnchor.constraint(equalTo: anchor).isActive = true
previousStep?.imageBottomConstraint?.constant = 0
} }
func resetSteps() { func resetSteps() {
@ -90,10 +84,9 @@ open class OrderTracker: View {
else { return } else { return }
context.setLineWidth(1) context.setLineWidth(1)
let firstRect = convert(firstStep.stateImage.frame, from: firstStep.stateImage)
let imageDimension = firstStep.stateImage.bounds.height let imageDimension = firstStep.stateImage.bounds.height
let halfDimension = imageDimension / 2 let halfDimension = imageDimension / 2
let startPoint = CGPoint(x: halfDimension, y: firstRect.size.height - halfDimension) let startPoint = CGPoint(x: halfDimension, y: halfDimension)
let defaultGrey: UIColor = .mvmCoolGray3 let defaultGrey: UIColor = .mvmCoolGray3
context.move(to: startPoint) context.move(to: startPoint)
@ -117,9 +110,8 @@ open class OrderTracker: View {
break break
} }
let nextPoint = CGPoint(x: halfDimension, y: relativeRect.origin.y + halfDimension)
lineColor = (step.state?.color() ?? defaultGrey).cgColor lineColor = (step.state?.color() ?? defaultGrey).cgColor
context.move(to: nextPoint) context.move(to: point)
} }
} }

View File

@ -20,7 +20,7 @@ open class Step: View {
public var stateImage = ImageView() public var stateImage = ImageView()
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Computed Properties // MARK: - Constraints
//-------------------------------------------------- //--------------------------------------------------
public var imageBottomConstraint: NSLayoutConstraint? public var imageBottomConstraint: NSLayoutConstraint?
@ -77,10 +77,10 @@ open class Step: View {
public override func reset() { public override func reset() {
super.reset() super.reset()
headline.text = "" headline.reset()
bodyTop.text = "" bodyTop.reset()
bodyBottom.text = "" bodyBottom.reset()
stateImage.image = nil stateImage.reset()
imageBottomConstraint?.constant = Padding.Ten imageBottomConstraint?.constant = Padding.Ten
} }

View File

@ -87,7 +87,7 @@ open class StepModel: MoleculeModelProtocol {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(headline, forKey: .headline) try container.encode(headline, forKey: .headline)
try container.encodeIfPresent(bodyTop, forKey: .bodyTop) try container.encodeIfPresent(bodyTop, forKey: .bodyTop)
try container.encodeIfPresent(bodyBottom, forKey: .bodyBottom) try container.encodeIfPresent(bodyBottom, forKey: .bodyBottom)
} }

View File

@ -59,6 +59,7 @@ open class ImageView: UIImageView, MoleculeViewProtocol {
} }
open func reset() { open func reset() {
image = nil
backgroundColor = .clear backgroundColor = .clear
} }