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 arrow = Arrow(frame: .zero)
|
||||||
public let arrowAndLabel2Stack: Stack<StackModel>
|
public let arrowAndLabel2Stack: Stack<StackModel>
|
||||||
let view = MVMCoreUICommonViewsUtility.commonView()
|
let view = MVMCoreUICommonViewsUtility.commonView()
|
||||||
|
public var alignmentConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
//-----------------------------------------------------
|
//-----------------------------------------------------
|
||||||
// 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: .trailing)),
|
arrowAndLabel2Stack = Stack<StackModel>.createStack(with: [(view: arrow, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center)),
|
||||||
(view: rightLabel, model: StackItemModel(horizontalAlignment: .trailing))],
|
(view: rightLabel, model: StackItemModel(horizontalAlignment: .fill, verticalAlignment: .center))],
|
||||||
axis: .horizontal, spacing: 8)
|
axis: .horizontal, spacing: 8)
|
||||||
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
rightLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||||
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
rightLabel.setContentHuggingPriority(UILayoutPriority(rawValue: 900), for: .horizontal)
|
||||||
@ -40,29 +41,35 @@ import Foundation
|
|||||||
// MARK: - View Lifecycle
|
// 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() {
|
override open func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
arrow.pinHeightAndWidth()
|
arrow.pinHeightAndWidth()
|
||||||
arrowAndLabel2Stack.restack()
|
arrowAndLabel2Stack.restack()
|
||||||
|
|
||||||
view.addSubview(eyebrowHeadlineBodyLink)
|
view.addSubview(eyebrowHeadlineBodyLink)
|
||||||
view.addSubview(arrowAndLabel2Stack)
|
view.addSubview(arrowAndLabel2Stack)
|
||||||
contentView.addSubview(view)
|
contentView.addSubview(view)
|
||||||
containerHelper.constrainView(view)
|
containerHelper.constrainView(view)
|
||||||
|
|
||||||
//constraints
|
NSLayoutConstraint.pinViews(leftView: eyebrowHeadlineBodyLink, rightView: arrowAndLabel2Stack, alignTop: false)
|
||||||
arrowAndLabel2Stack.leadingAnchor.constraint(equalTo: eyebrowHeadlineBodyLink.trailingAnchor, constant: PaddingTen).isActive = true
|
alignmentConstraint = view.constraintsAffectingLayout(for: .vertical).first { (layout) -> Bool in
|
||||||
arrowAndLabel2Stack.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
|
return layout.firstAnchor == arrowAndLabel2Stack.centerYAnchor && layout.firstAttribute == .centerY
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func updateView(_ size: CGFloat) {
|
public override func updateView(_ size: CGFloat) {
|
||||||
super.updateView(size)
|
super.updateView(size)
|
||||||
eyebrowHeadlineBodyLink.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]?) {
|
||||||
@ -79,6 +86,8 @@ import Foundation
|
|||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
eyebrowHeadlineBodyLink.reset()
|
||||||
|
arrowAndLabel2Stack.reset()
|
||||||
rightLabel.styleB2(true)
|
rightLabel.styleB2(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import UIKit
|
|||||||
/// For subclasses that want to use a custom accessory view.
|
/// For subclasses that want to use a custom accessory view.
|
||||||
open var customAccessoryView = false
|
open var customAccessoryView = false
|
||||||
|
|
||||||
private var heroAccessoryCenter: CGPoint?
|
public var heroAccessoryCenter: CGPoint?
|
||||||
|
|
||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user