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?
|
open var molecule: MoleculeViewProtocol?
|
||||||
public let containerHelper = ContainerHelper()
|
public let containerHelper = ContainerHelper()
|
||||||
open var model: CollectionItemModelProtocol?
|
open var model: CollectionItemModelProtocol?
|
||||||
open var widthConstraint: NSLayoutConstraint?
|
|
||||||
|
/// The width, used for establishing columns
|
||||||
|
open var width: CGFloat?
|
||||||
|
|
||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
|
|||||||
open func reset() {
|
open func reset() {
|
||||||
molecule?.reset()
|
molecule?.reset()
|
||||||
backgroundColor = .white
|
backgroundColor = .white
|
||||||
widthConstraint?.isActive = false
|
width = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MoleculeViewProtocol
|
// MARK: - MoleculeViewProtocol
|
||||||
@ -85,12 +87,18 @@ open class CollectionViewCell: UICollectionViewCell, MoleculeViewProtocol, MVMCo
|
|||||||
|
|
||||||
// MARK: - CollectionTemplateItemProtocol
|
// MARK: - CollectionTemplateItemProtocol
|
||||||
public func set(width: CGFloat) {
|
public func set(width: CGFloat) {
|
||||||
if let widthConstraint = widthConstraint {
|
self.width = width
|
||||||
widthConstraint.constant = width
|
|
||||||
widthConstraint.isActive = true
|
|
||||||
} else {
|
|
||||||
widthConstraint = contentView.widthAnchor.constraint(equalToConstant: width)
|
|
||||||
widthConstraint?.isActive = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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