File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,17 @@ final class ModelState {
105105 return nil
106106 }
107107
108+ func isItemHeightSettled( indexPath: IndexPath ) -> Bool {
109+ let item = sectionModels ( for: . afterUpdates) [ indexPath. section] . itemModel (
110+ atIndex: indexPath. item)
111+ switch item. sizeMode. heightMode {
112+ case . static:
113+ return true
114+ case . dynamicAndStretchToTallestItemInRow, . dynamic( _) :
115+ return item. preferredHeight != nil
116+ }
117+ }
118+
108119 func itemModelHeightModeDuringPreferredAttributesCheck(
109120 at indexPath: IndexPath )
110121 -> MagazineLayoutItemHeightMode ?
Original file line number Diff line number Diff line change @@ -1294,7 +1294,11 @@ public final class MagazineLayout: UICollectionViewLayout {
12941294 }
12951295 visibleItemLocationFramePairs. sort { $0. elementLocation < $1. elementLocation }
12961296
1297- let firstVisibleItemLocationFramePair = visibleItemLocationFramePairs. first
1297+ let firstVisibleItemLocationFramePair = visibleItemLocationFramePairs. first {
1298+ // When scrolling up, only calculate a a target content offset based on visible, already-sized
1299+ // cells. Otherwise, scrolling will be jumpy.
1300+ modelState. isItemHeightSettled ( indexPath: $0. elementLocation. indexPath)
1301+ }
12981302 let lastVisibleItemLocationFramePair = visibleItemLocationFramePairs. last
12991303
13001304 guard
You can’t perform that action at this time.
0 commit comments