Image stretch fix
New convenience function for set/gone/restack
This commit is contained in:
parent
ee1d847a41
commit
be0c9b8742
@ -15,11 +15,12 @@ import Foundation
|
||||
public let body = Label.createLabelRegularBodySmall(true)
|
||||
public let body2 = Label.createLabelRegularBodySmall(true)
|
||||
public let button = PillButton(frame: .zero)
|
||||
public let rightImageView = MFLoadImageView(pinnedEdges: .all)
|
||||
public let rightImageView = MFLoadImageView()
|
||||
public var stack: Stack<StackModel>
|
||||
|
||||
// MARK: - Initializers
|
||||
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
rightImageView.addSizeConstraintsForAspectRatio = true
|
||||
rightImageView.heightAnchor.constraint(equalToConstant: 116.0).isActive = true
|
||||
rightImageView.widthAnchor.constraint(equalToConstant: 116.0).isActive = true
|
||||
verticalStack = Stack<StackModel>.createStack(with: [(view: eyebrow, model: StackItemModel(horizontalAlignment: .leading)),
|
||||
@ -50,11 +51,12 @@ import Foundation
|
||||
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
|
||||
super.set(with: model, delegateObject, additionalData)
|
||||
guard let model = model as? ListDeviceComplexButtonMediumModel else { return }
|
||||
eyebrow.setOptional(with: model.eyebrow, delegateObject, additionalData)
|
||||
headline.setOptional(with: model.headline, delegateObject, additionalData)
|
||||
body.setOptional(with: model.body, delegateObject, additionalData)
|
||||
body2.setOptional(with: model.body2, delegateObject, additionalData)
|
||||
button.set(with: model.button, delegateObject, additionalData)
|
||||
verticalStack.updateContainedMolecules(with: [model.eyebrow,
|
||||
model.headline,
|
||||
model.body,
|
||||
model.body2,
|
||||
model.button],
|
||||
delegateObject, additionalData)
|
||||
rightImageView.set(with: model.image, delegateObject, additionalData)
|
||||
}
|
||||
|
||||
|
||||
@ -62,6 +62,32 @@ open class Stack<T>: Container where T: (StackModelProtocol & MoleculeModelProto
|
||||
}
|
||||
}
|
||||
|
||||
/// A convenience function for when the stackItems are containers and we want to update them based on the contained molecules models. If model is nil, stackItem is set to gone. Restacks if necessary.
|
||||
open func updateContainedMolecules(with models: [MoleculeModelProtocol?], _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
||||
guard var stackModel = stackModel else { return }
|
||||
var needsRestack = false
|
||||
for (index, item) in stackItems.enumerated() {
|
||||
guard let container = item as? UIView & ContainerProtocol,
|
||||
let contained = container.view as? MoleculeViewProtocol else {
|
||||
continue
|
||||
}
|
||||
if let model = models[index] {
|
||||
contained.set(with: model, delegateObject, additionalData)
|
||||
if stackModel.molecules[index].gone {
|
||||
stackModel.molecules[index].gone = false
|
||||
needsRestack = true
|
||||
}
|
||||
} else if !stackModel.molecules[index].gone {
|
||||
stackModel.molecules[index].gone = true
|
||||
needsRestack = true
|
||||
}
|
||||
}
|
||||
|
||||
if needsRestack {
|
||||
restack()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
//--------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user