@@ -787,18 +787,21 @@ public final class MagazineLayout: UICollectionViewLayout {
787787 return
788788 }
789789
790- // If our layout direction is `bottomToTop`, allow changes to the bottom content inset to
791- // automatically adjust the content offset. `UICollectionView` behaves this way by default when
792- // the top content inset changes, so this adds the same behavior to the bottom.
793- let bottomContentInset = contentInset. bottom
790+ // If our layout direction is `bottomToTop`, allow changes to the top and bottom content insets
791+ // to automatically adjust the content offset. `UICollectionView` behaves this way by default
792+ // when the top content inset changes, so this adds the same behavior to the bottom.
794793 if
795794 case . bottomToTop = verticalLayoutDirection,
796- let previousBottomContentInset,
797- previousBottomContentInset != bottomContentInset
795+ let previousContentInset
798796 {
799- context. contentOffsetAdjustment. y = bottomContentInset - previousBottomContentInset
797+ if previousContentInset. top != contentInset. top {
798+ context. contentOffsetAdjustment. y += contentInset. top - previousContentInset. top
799+ }
800+ if previousContentInset. bottom != contentInset. bottom {
801+ context. contentOffsetAdjustment. y += contentInset. bottom - previousContentInset. bottom
802+ }
800803 }
801- previousBottomContentInset = bottomContentInset
804+ previousContentInset = contentInset
802805
803806 let shouldInvalidateLayoutMetrics = !context. invalidateEverything &&
804807 !context. invalidateDataSourceCounts
@@ -912,7 +915,7 @@ public final class MagazineLayout: UICollectionViewLayout {
912915 private var isPerformingAnimatedBoundsChange = false
913916 private var targetContentOffsetAnchor : TargetContentOffsetAnchor ?
914917 private var stagedContentOffsetAdjustment : CGPoint ?
915- private var previousBottomContentInset : CGFloat ?
918+ private var previousContentInset : UIEdgeInsets ?
916919
917920 // Used to provide the model state with the current visible bounds for the sole purpose of
918921 // supporting pinned headers and footers.
0 commit comments