Simpler stack logic

This commit is contained in:
Pfeil, Scott Robert 2020-04-18 18:08:13 -04:00
parent c89929648f
commit 4d7740854d

View File

@ -14,22 +14,24 @@ import Foundation
// MARK: - Outlets // MARK: - Outlets
//----------------------------------------------------- //-----------------------------------------------------
public let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink(frame: .zero) public let eyebrowHeadlineBodyLink = EyebrowHeadlineBodyLink(frame: .zero)
public let rightLabel = Label.commonLabelB2(true)
public let arrow = Arrow(frame: .zero) public let arrow = Arrow(frame: .zero)
public let arrowAndLabel2Stack: Stack<StackModel> public let rightLabel = Label.commonLabelB2(true)
let view = MVMCoreUICommonViewsUtility.commonView() private let stack: Stack<StackModel>
public var alignmentConstraint: NSLayoutConstraint? private let arrowStackItem: StackItem
private let rightLabelStackItem: StackItem
//----------------------------------------------------- //-----------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//----------------------------------------------------- //-----------------------------------------------------
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
arrowAndLabel2Stack = Stack<StackModel>.createStack(with: [(view: arrow, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center)), let stackModel = StackModel(molecules: [StackItemModel(horizontalAlignment: .leading),
(view: rightLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center))], StackItemModel(horizontalAlignment: .fill),
axis: .horizontal, spacing: 8) StackItemModel(spacing: 8, horizontalAlignment: .fill)],
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal) axis: .horizontal)
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal) arrowStackItem = StackItem(andContain: arrow)
rightLabel.numberOfLines = 1 rightLabelStackItem = StackItem(andContain: rightLabel)
let stackItems = [StackItem(andContain: eyebrowHeadlineBodyLink), arrowStackItem, rightLabelStackItem]
stack = Stack<StackModel>(with: stackModel, stackItems: stackItems)
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
} }
@ -44,32 +46,24 @@ import Foundation
public override func alignAccessoryToHero() { public override func alignAccessoryToHero() {
super.alignAccessoryToHero() super.alignAccessoryToHero()
// Aligns the center of the right side to the headline. // Aligns the center of the right side items to the headline.
if let heroCenter = heroAccessoryCenter { if let heroCenter = heroAccessoryCenter {
let convertedPoint = view.convert(heroCenter, from: self) let convertedPoint = stack.convert(heroCenter, from: self)
alignmentConstraint?.constant = convertedPoint.y - view.bounds.midY arrowStackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - stack.bounds.midY
rightLabelStackItem.containerHelper.alignCenterVerticalConstraint?.constant = convertedPoint.y - stack.bounds.midY
} }
} }
override open func setupView() { override open func setupView() {
super.setupView() super.setupView()
arrow.pinHeightAndWidth() rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
arrowAndLabel2Stack.restack() rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal)
view.addSubview(eyebrowHeadlineBodyLink) rightLabel.numberOfLines = 1
view.addSubview(arrowAndLabel2Stack)
contentView.addSubview(view)
containerHelper.constrainView(view)
NSLayoutConstraint.pinViews(leftView: eyebrowHeadlineBodyLink, rightView: arrowAndLabel2Stack, alignTop: false) arrow.pinHeightAndWidth()
alignmentConstraint = view.constraintsAffectingLayout(for: .vertical).first { (layout) -> Bool in
return layout.firstAnchor == arrowAndLabel2Stack.centerYAnchor && layout.firstAttribute == .centerY addMolecule(stack)
} stack.restack()
}
public override func updateView(_ size: CGFloat) {
super.updateView(size)
eyebrowHeadlineBodyLink.updateView(size)
arrowAndLabel2Stack.updateView(size)
} }
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) { open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
@ -83,12 +77,5 @@ import Foundation
open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? { open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
return 121 return 121
} }
open override func reset() {
super.reset()
eyebrowHeadlineBodyLink.reset()
arrowAndLabel2Stack.reset()
rightLabel.styleB2(true)
}
} }