update collection for sizing properly
This commit is contained in:
parent
79b3b9b0c5
commit
03abdd3a91
@ -10,6 +10,11 @@ import Foundation
|
||||
|
||||
open class CollectionView: UICollectionView, MVMCoreViewProtocol {
|
||||
|
||||
/// A block that gets called on tableview frame changes
|
||||
public var frameChangeAction: (() -> Void)?
|
||||
|
||||
private var previousFrame = CGRect.zero
|
||||
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
private func initialSetup() {
|
||||
@ -29,6 +34,14 @@ open class CollectionView: UICollectionView, MVMCoreViewProtocol {
|
||||
initialSetup()
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
if frame != previousFrame {
|
||||
frameChangeAction?()
|
||||
}
|
||||
previousFrame = frame
|
||||
}
|
||||
|
||||
public func updateView(_ size: CGFloat) {
|
||||
for cell in visibleCells {
|
||||
(cell as? MVMCoreViewProtocol)?.updateView(size)
|
||||
|
||||
@ -11,7 +11,7 @@ import Foundation
|
||||
/// A base view controller with a collection view.
|
||||
@objc open class ProgrammaticCollectionViewController: ScrollingViewController {
|
||||
|
||||
public var collectionView: UICollectionView?
|
||||
public var collectionView: CollectionView?
|
||||
public var topConstraint: NSLayoutConstraint?
|
||||
public var bottomConstraint: NSLayoutConstraint?
|
||||
|
||||
@ -49,7 +49,7 @@ import Foundation
|
||||
}
|
||||
|
||||
/// Creates the collection view.
|
||||
open func createCollectionView() -> UICollectionView {
|
||||
open func createCollectionView() -> CollectionView {
|
||||
let collection = CollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout())
|
||||
collection.dataSource = self
|
||||
collection.delegate = self
|
||||
|
||||
@ -22,7 +22,7 @@ import Foundation
|
||||
|
||||
/// Updates the padding for flexible space (header or footer)
|
||||
private func updateFlexibleSpace() {
|
||||
guard false,let collectionView = collectionView else { return }
|
||||
guard let collectionView = collectionView else { return }
|
||||
|
||||
let minimumSpace: CGFloat = minimumFillSpace()
|
||||
var currentSpace: CGFloat = 0
|
||||
@ -126,6 +126,10 @@ import Foundation
|
||||
override open func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
collectionView?.frameChangeAction = { [weak self] in
|
||||
self?.invalidateCollectionLayout()
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Spacing
|
||||
|
||||
Loading…
Reference in New Issue
Block a user