Stack fixes
This commit is contained in:
parent
2ec429974a
commit
7be08fe9be
@ -36,22 +36,23 @@ import Foundation
|
|||||||
|
|
||||||
open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?){
|
open override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?){
|
||||||
super.setWithModel(model, delegateObject, additionalData)
|
super.setWithModel(model, delegateObject, additionalData)
|
||||||
guard let model = model as? ListOneColumnFullWidthTextAllTextAndLinksModel else { return}
|
guard let model = model as? ListOneColumnFullWidthTextAllTextAndLinksModel else { return }
|
||||||
eyebrow.setWithModel(model.eyebrow, delegateObject, additionalData)
|
eyebrow.setWithModel(model.eyebrow, delegateObject, additionalData)
|
||||||
headline.setWithModel(model.headline, delegateObject, additionalData)
|
headline.setWithModel(model.headline, delegateObject, additionalData)
|
||||||
subHeadline.setWithModel(model.subHeadline, delegateObject, additionalData)
|
subHeadline.setWithModel(model.subHeadline, delegateObject, additionalData)
|
||||||
body.setWithModel(model.body, delegateObject, additionalData)
|
body.setWithModel(model.body, delegateObject, additionalData)
|
||||||
link.setWithModel(model.link, delegateObject, additionalData)
|
link.setWithModel(model.link, delegateObject, additionalData)
|
||||||
let stackModel = StackModel(molecules: [StackItemModel(spacing: 2, gone: !eyebrow.hasText),
|
let stackModel = StackModel(molecules: [StackItemModel(gone: !eyebrow.hasText),
|
||||||
StackItemModel(spacing: 2, gone: !headline.hasText),
|
StackItemModel(gone: !headline.hasText),
|
||||||
StackItemModel(spacing: 2, gone: !subHeadline.hasText),
|
StackItemModel(gone: !subHeadline.hasText),
|
||||||
StackItemModel(spacing: 2, gone: !body.hasText),
|
StackItemModel(gone: !body.hasText),
|
||||||
StackItemModel(spacing: 2, gone: (link.titleLabel?.text?.count ?? 0) == 0)])
|
StackItemModel(spacing: 2, gone: (link.titleLabel?.text?.count ?? 0) == 0)],
|
||||||
|
spacing: 0)
|
||||||
stack.model = stackModel
|
stack.model = stackModel
|
||||||
stack.restack()
|
stack.restack()
|
||||||
}
|
}
|
||||||
|
|
||||||
open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat?{
|
open override class func estimatedHeight(forRow molecule: MoleculeModelProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
|
||||||
return 90
|
return 90
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -237,7 +237,7 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
if first {
|
if first {
|
||||||
pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: stackModel.useStackSpacingBeforeFirstItem ? spacing : model.spacing ?? 0)
|
pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: stackModel.useStackSpacingBeforeFirstItem ? spacing : model.spacing ?? 0)
|
||||||
} else if let previousView = stackItems.last(where: { item in
|
} else if let previousView = stackItems.last(where: { item in
|
||||||
return !model.gone
|
return item.superview != nil
|
||||||
}) {
|
}) {
|
||||||
view.topAnchor.constraint(equalTo: previousView.bottomAnchor, constant: spacing).isActive = true
|
view.topAnchor.constraint(equalTo: previousView.bottomAnchor, constant: spacing).isActive = true
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
// First horizontal item has no spacing by default unless told otherwise.
|
// First horizontal item has no spacing by default unless told otherwise.
|
||||||
pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: stackModel.useStackSpacingBeforeFirstItem ? spacing : model.spacing ?? 0)
|
pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: stackModel.useStackSpacingBeforeFirstItem ? spacing : model.spacing ?? 0)
|
||||||
} else if let previousView = stackItems.last(where: { item in
|
} else if let previousView = stackItems.last(where: { item in
|
||||||
return !model.gone
|
return item.superview != nil
|
||||||
}) {
|
}) {
|
||||||
view.leftAnchor.constraint(equalTo: previousView.rightAnchor, constant: spacing).isActive = true
|
view.leftAnchor.constraint(equalTo: previousView.rightAnchor, constant: spacing).isActive = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,12 @@ import Foundation
|
|||||||
public var spacing: CGFloat = 16.0
|
public var spacing: CGFloat = 16.0
|
||||||
public var useStackSpacingBeforeFirstItem = false
|
public var useStackSpacingBeforeFirstItem = false
|
||||||
|
|
||||||
public init(molecules: [StackItemModel], axis: NSLayoutConstraint.Axis = .vertical) {
|
public init(molecules: [StackItemModel], axis: NSLayoutConstraint.Axis = .vertical, spacing: CGFloat? = nil) {
|
||||||
self.molecules = molecules
|
self.molecules = molecules
|
||||||
self.axis = axis
|
self.axis = axis
|
||||||
|
if let spacing = spacing {
|
||||||
|
self.spacing = spacing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user