Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions MagazineLayout/LayoutCore/ModelState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ final class ModelState {
return nil
}

func isItemHeightSettled(indexPath: IndexPath) -> Bool {
let item = sectionModels(for: .afterUpdates)[indexPath.section].itemModel(
atIndex: indexPath.item)
switch item.sizeMode.heightMode {
case .static:
return true
case .dynamicAndStretchToTallestItemInRow, .dynamic(_):
return item.preferredHeight != nil
}
}

func itemModelHeightModeDuringPreferredAttributesCheck(
at indexPath: IndexPath)
-> MagazineLayoutItemHeightMode?
Expand Down
6 changes: 5 additions & 1 deletion MagazineLayout/Public/MagazineLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,11 @@ public final class MagazineLayout: UICollectionViewLayout {
}
visibleItemLocationFramePairs.sort { $0.elementLocation < $1.elementLocation }

let firstVisibleItemLocationFramePair = visibleItemLocationFramePairs.first
let firstVisibleItemLocationFramePair = visibleItemLocationFramePairs.first {
// When scrolling up, only calculate a a target content offset based on visible, already-sized
// cells. Otherwise, scrolling will be jumpy.
modelState.isItemHeightSettled(indexPath: $0.elementLocation.indexPath)
}
let lastVisibleItemLocationFramePair = visibleItemLocationFramePairs.last

guard
Expand Down