1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Stop album view jumping occasionally

This commit is contained in:
Daniel Barber 2019-03-31 18:08:43 -04:00
parent 0fb1831ffd
commit fc99c59d53
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 13 additions and 4 deletions

View File

@ -46,6 +46,10 @@ class AlbumViewController: NSViewController,
override func viewWillLayout() {
super.viewWillLayout()
if let layout = albumCollectionView.collectionViewLayout as? AlbumViewLayout {
layout.saveScrollPosition()
}
albumCollectionView.collectionViewLayout?.invalidateLayout()
}

View File

@ -36,10 +36,6 @@ class AlbumViewLayout: NSCollectionViewFlowLayout {
var divider: CGFloat = 1
var itemWidth: CGFloat = 0
if let scrollView = collectionView.enclosingScrollView {
scrollPosition = scrollView.documentVisibleRect.minY / collectionView.bounds.height
}
repeat {
let totalPaddingWidth = sectionInset.left + sectionInset.right
let totalGutterWidth = (divider - 1) * (minimumInteritemSpacing)
@ -52,6 +48,15 @@ class AlbumViewLayout: NSCollectionViewFlowLayout {
itemSize = NSSize(width: itemWidth, height: itemHeight)
}
func saveScrollPosition() {
guard let collectionView = collectionView
else { return }
if let scrollView = collectionView.enclosingScrollView {
scrollPosition = scrollView.documentVisibleRect.minY / collectionView.bounds.height
}
}
func setScrollPosition() {
guard let collectionView = collectionView
else { return }