Feedback push
This commit is contained in:
parent
57a5dbb064
commit
185efa547e
@ -15,7 +15,9 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
|
||||
open var molecule: MoleculeViewProtocol?
|
||||
public let containerHelper = ContainerHelper()
|
||||
open var model: CollectionItemModelProtocol?
|
||||
open var widthConstraint: NSLayoutConstraint?
|
||||
|
||||
/// The width, used for establishing columns
|
||||
open var width: CGFloat?
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
@ -57,7 +59,7 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
|
||||
open func reset() {
|
||||
molecule?.reset()
|
||||
backgroundColor = .white
|
||||
widthConstraint?.isActive = false
|
||||
width = nil
|
||||
}
|
||||
|
||||
// MARK: - MoleculeViewProtocol
|
||||
@ -85,12 +87,18 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
|
||||
|
||||
// MARK: - CollectionTemplateItemProtocol
|
||||
public func set(width: CGFloat) {
|
||||
if let widthConstraint = widthConstraint {
|
||||
widthConstraint.constant = width
|
||||
widthConstraint.isActive = true
|
||||
} else {
|
||||
widthConstraint = contentView.widthAnchor.constraint(equalToConstant: width)
|
||||
widthConstraint?.isActive = true
|
||||
}
|
||||
self.width = width
|
||||
}
|
||||
|
||||
// Column logic, set width.
|
||||
override open func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
let autoLayoutAttributes = super.preferredLayoutAttributesFitting(layoutAttributes)
|
||||
guard let width = width else { return autoLayoutAttributes }
|
||||
|
||||
let targetSize = CGSize(width: width, height: 0)
|
||||
let newSize = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: UILayoutPriority.required, verticalFittingPriority: UILayoutPriority.defaultLow)
|
||||
let newFrame = CGRect(origin: autoLayoutAttributes.frame.origin, size: newSize)
|
||||
autoLayoutAttributes.frame = newFrame
|
||||
return autoLayoutAttributes
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user