Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong layout on iPad modal presentation when the view controller frame is changed #254

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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