fix centering logic
This commit is contained in:
parent
c4824a7b01
commit
c89929648f
@ -18,13 +18,14 @@ import Foundation
|
||||
public let arrow = Arrow(frame: .zero)
|
||||
public let arrowAndLabel2Stack: Stack<StackModel>
|
||||
let view = MVMCoreUICommonViewsUtility.commonView()
|
||||
public var alignmentConstraint: NSLayoutConstraint?
|
||||
|
||||
//-----------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//-----------------------------------------------------
|
||||
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
arrowAndLabel2Stack = Stack<StackModel>.createStack(with: [(view: arrow, model: StackItemModel(horizontalAlignment: .trailing)),
|
||||
(view: rightLabel, model: StackItemModel(horizontalAlignment: .trailing))],
|
||||
arrowAndLabel2Stack = Stack<StackModel>.createStack(with: [(view: arrow, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center)),
|
||||
(view: rightLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center))],
|
||||
axis: .horizontal, spacing: 8)
|
||||
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||
@ -40,29 +41,35 @@ import Foundation
|
||||
// MARK: - View Lifecycle
|
||||
//-----------------------------------------------------
|
||||
|
||||
public override func alignAccessoryToHero() {
|
||||
super.alignAccessoryToHero()
|
||||
|
||||
// Aligns the center of the right side to the headline.
|
||||
if let heroCenter = heroAccessoryCenter {
|
||||
let convertedPoint = view.convert(heroCenter, from: self)
|
||||
alignmentConstraint?.constant = convertedPoint.y - view.bounds.midY
|
||||
}
|
||||
}
|
||||
|
||||
override open func setupView() {
|
||||
super.setupView()
|
||||
arrow.pinHeightAndWidth()
|
||||
arrowAndLabel2Stack.restack()
|
||||
|
||||
view.addSubview(eyebrowHeadlineBodyLink)
|
||||
view.addSubview(arrowAndLabel2Stack)
|
||||
contentView.addSubview(view)
|
||||
containerHelper.constrainView(view)
|
||||
|
||||
//constraints
|
||||
arrowAndLabel2Stack.leadingAnchor.constraint(equalTo: eyebrowHeadlineBodyLink.trailingAnchor, constant: PaddingTen).isActive = true
|
||||
arrowAndLabel2Stack.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
||||
arrowAndLabel2Stack.topAnchor.constraint(equalTo: view.topAnchor, constant: PaddingTwo).isActive = true
|
||||
|
||||
eyebrowHeadlineBodyLink.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
|
||||
eyebrowHeadlineBodyLink.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
|
||||
eyebrowHeadlineBodyLink.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
|
||||
NSLayoutConstraint.pinViews(leftView: eyebrowHeadlineBodyLink, rightView: arrowAndLabel2Stack, alignTop: false)
|
||||
alignmentConstraint = view.constraintsAffectingLayout(for: .vertical).first { (layout) -> Bool in
|
||||
return layout.firstAnchor == arrowAndLabel2Stack.centerYAnchor && layout.firstAttribute == .centerY
|
||||
}
|
||||
}
|
||||
|
||||
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]?) {
|
||||
@ -79,6 +86,8 @@ import Foundation
|
||||
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
eyebrowHeadlineBodyLink.reset()
|
||||
arrowAndLabel2Stack.reset()
|
||||
rightLabel.styleB2(true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import UIKit
|
||||
/// For subclasses that want to use a custom accessory view.
|
||||
open var customAccessoryView = false
|
||||
|
||||
private var heroAccessoryCenter: CGPoint?
|
||||
public var heroAccessoryCenter: CGPoint?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user