From 20bc8448ee584ac024d3a2561784eed58fdb8c2b Mon Sep 17 00:00:00 2001 From: czuria1 Date: Mon, 20 Jul 2020 15:59:06 -0700 Subject: [PATCH] Fix wrong layout on iPad modal presentation --- CardParts/src/Classes/CardsViewController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CardParts/src/Classes/CardsViewController.swift b/CardParts/src/Classes/CardsViewController.swift index 394b9ed9..3d8888e8 100644 --- a/CardParts/src/Classes/CardsViewController.swift +++ b/CardParts/src/Classes/CardsViewController.swift @@ -86,6 +86,11 @@ open class CardsViewController : UIViewController, UICollectionViewDataSource, U view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[collectionView]|", options: [], metrics: nil, views: ["collectionView" : collectionView!])) view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[collectionView]|", options: [], metrics: nil, views: ["collectionView" : collectionView!])) + // immediate layout pass to ensure collection view layout reflects the latest frame size + cardCellWidth.distinctUntilChanged().asObservable().subscribe(onNext: { [weak self] _ in + self?.invalidateLayout() + }).disposed(by: bag) + let newValue = view.bounds.width.rounded() - (cardCellMargins.left + cardCellMargins.right) if newValue != cardCellWidth.value { cardCellWidth.accept(newValue) @@ -94,7 +99,6 @@ open class CardsViewController : UIViewController, UICollectionViewDataSource, U open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { cardCellWidth.accept(size.width.rounded() - (cardCellMargins.left + cardCellMargins.right)) - invalidateLayout() } // functionality that happens when the view appears