rolled back change.
This commit is contained in:
parent
f7058e0a3f
commit
0c11ded577
@ -9,13 +9,20 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
open class Stack<T>: Container where T: StackModelProtocol {
|
open class Stack<T>: Container where T: StackModelProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
var contentView: UIView = MVMCoreUICommonViewsUtility.commonView()
|
var contentView: UIView = MVMCoreUICommonViewsUtility.commonView()
|
||||||
var stackModel: T? {
|
var stackModel: T? {
|
||||||
get { return model as? T }
|
get { return model as? T }
|
||||||
}
|
}
|
||||||
var stackItems: [UIView] = []
|
var stackItems: [UIView] = []
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func pinView(_ view: UIView, toView: UIView, attribute: NSLayoutConstraint.Attribute, relation: NSLayoutConstraint.Relation, priority: UILayoutPriority, constant: CGFloat) {
|
public func pinView(_ view: UIView, toView: UIView, attribute: NSLayoutConstraint.Attribute, relation: NSLayoutConstraint.Relation, priority: UILayoutPriority, constant: CGFloat) {
|
||||||
let constraint = NSLayoutConstraint(item: view, attribute: attribute, relatedBy: relation, toItem: toView, attribute: attribute, multiplier: 1.0, constant: constant)
|
let constraint = NSLayoutConstraint(item: view, attribute: attribute, relatedBy: relation, toItem: toView, attribute: attribute, multiplier: 1.0, constant: constant)
|
||||||
constraint.priority = priority
|
constraint.priority = priority
|
||||||
@ -46,7 +53,10 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Inits
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializers
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override init(frame: CGRect) {
|
public override init(frame: CGRect) {
|
||||||
super.init(frame: frame)
|
super.init(frame: frame)
|
||||||
}
|
}
|
||||||
@ -60,7 +70,10 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - MFViewProtocol
|
// MARK: - MFViewProtocol
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override func setupView() {
|
public override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
guard contentView.superview == nil else { return }
|
guard contentView.superview == nil else { return }
|
||||||
@ -80,7 +93,10 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtocol
|
// MARK: - MVMCoreUIMoleculeViewProtocol
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public override func reset() {
|
public override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
@ -157,7 +173,9 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
return modules.count > 0 ? modules : nil
|
return modules.count > 0 ? modules : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - Subclassables
|
// MARK: - Subclassables
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Can be subclassed to create views when we get stack item models and have no views yet
|
/// Can be subclassed to create views when we get stack item models and have no views yet
|
||||||
func createStackItemsFromModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { }
|
func createStackItemsFromModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { }
|
||||||
@ -170,7 +188,10 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
// MARK: - Adding to stack
|
// MARK: - Adding to stack
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Gets the percent modifier. This value is used to help properly calculate percent for stack items when spacing is involved.
|
/// Gets the percent modifier. This value is used to help properly calculate percent for stack items when spacing is involved.
|
||||||
private func getTotalSpace() -> CGFloat {
|
private func getTotalSpace() -> CGFloat {
|
||||||
guard let stackModel = stackModel else { return 0.0 }
|
guard let stackModel = stackModel else { return 0.0 }
|
||||||
@ -213,13 +234,15 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
if stackModel.axis == .vertical {
|
if stackModel.axis == .vertical {
|
||||||
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 !model.gone }) {
|
} else if let previousView = stackItems.last(where: { item in
|
||||||
|
return !model.gone
|
||||||
|
}) {
|
||||||
view.topAnchor.constraint(equalTo: previousView.bottomAnchor, constant: spacing).isActive = true
|
view.topAnchor.constraint(equalTo: previousView.bottomAnchor, constant: spacing).isActive = true
|
||||||
}
|
}
|
||||||
pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: 0)
|
pinView(view, toView: contentView, attribute: .leading, relation: .equal, priority: .required, constant: 0)
|
||||||
pinView(contentView, toView: view, attribute: .trailing, relation: .equal, priority: .required, constant: 0)
|
pinView(contentView, toView: view, attribute: .trailing, relation: .equal, priority: .required, constant: 0)
|
||||||
if let percent = model.percent {
|
if let percent = model.percent {
|
||||||
let multiplier = CGFloat(percent)/100.0
|
let multiplier = CGFloat(percent) / 100.0
|
||||||
let constant = multiplier * totalSpacing
|
let constant = multiplier * totalSpacing
|
||||||
view.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: multiplier, constant: -constant).isActive = true
|
view.heightAnchor.constraint(equalTo: contentView.heightAnchor, multiplier: multiplier, constant: -constant).isActive = true
|
||||||
}
|
}
|
||||||
@ -230,7 +253,9 @@ open class Stack<T>: Container where T: StackModelProtocol {
|
|||||||
if first {
|
if first {
|
||||||
// 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 !model.gone }) {
|
} else if let previousView = stackItems.last(where: { item in
|
||||||
|
return !model.gone
|
||||||
|
}) {
|
||||||
view.leftAnchor.constraint(equalTo: previousView.rightAnchor, constant: spacing).isActive = true
|
view.leftAnchor.constraint(equalTo: previousView.rightAnchor, constant: spacing).isActive = true
|
||||||
}
|
}
|
||||||
pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: 0)
|
pinView(view, toView: contentView, attribute: .top, relation: .equal, priority: .required, constant: 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user