Skip to content

Commit

Permalink
Fix wrong layout on iPad modal presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
czuria1 committed Jul 22, 2020
1 parent 0abbf98 commit 20bc844
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CardParts/src/Classes/CardsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 20bc844

Please sign in to comment.