Skip to content

Commit

Permalink
Fix attempt (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryankeller committed Mar 22, 2024
1 parent b838d83 commit 8b41fe5
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions MagazineLayout/Public/MagazineLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,17 +612,14 @@ public final class MagazineLayout: UICollectionViewLayout {
let invalidationContext = super.invalidationContext(
forBoundsChange: newBounds) as! MagazineLayoutInvalidationContext

invalidationContext.contentSizeAdjustment = CGSize(
width: newBounds.width - currentCollectionView.bounds.width,
height: newBounds.height - currentCollectionView.bounds.height)
invalidationContext.invalidateLayoutMetrics = false

// If our layout direction is bottom to top we want to adjust scroll position relative to the
// bottom
if case .bottomToTop = verticalLayoutDirection {
invalidationContext.contentOffsetAdjustment = CGPoint(
x: 0.0,
y: currentCollectionView.bounds.height - newBounds.height + contentInset.bottom)
y: max(currentCollectionView.bounds.height - newBounds.height + contentInset.bottom, 0))
}

return invalidationContext
Expand Down Expand Up @@ -790,14 +787,11 @@ public final class MagazineLayout: UICollectionViewLayout {

// Checking `cachedCollectionViewWidth != collectionView?.bounds.size.width` is necessary
// because the collection view's width can change without a `contentSizeAdjustment` occurring.
let isContentWidthAdjustmentZero = context.contentSizeAdjustment.width.isEqual(
to: 0,
threshold: 1 / scale)
let isSameWidth = collectionView?.bounds.size.width.isEqual(
to: cachedCollectionViewWidth ?? -.greatestFiniteMagnitude,
threshold: 1 / scale)
?? false
if !isContentWidthAdjustmentZero || !isSameWidth {
if !isSameWidth {
prepareActions.formUnion([.updateLayoutMetrics, .cachePreviousWidth])
}

Expand Down

0 comments on commit 8b41fe5

Please sign in to comment.