Skip to content

Commit

Permalink
Merge pull request #254 from czuria1/master
Browse files Browse the repository at this point in the history
Fix wrong layout on iPad modal presentation when the view controller frame is changed
  • Loading branch information
badrinathvm authored Jul 27, 2020
2 parents 0abbf98 + 20bc844 commit 14b491c
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 14b491c

Please sign in to comment.