Skip to content

Commit

Permalink
Fix crash in prepare() because isReordering is set even during scroll…
Browse files Browse the repository at this point in the history
… invalidations.
  • Loading branch information
kyleve committed Jul 27, 2021
1 parent 1a71aa9 commit 49056c0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ListableUI/Sources/Layout/CollectionViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ final class CollectionViewLayout : UICollectionViewLayout
let context = context as! InvalidationContext

// Handle Moved Items

self.isReordering = context.interactiveMoveAction != nil


if let action = context.interactiveMoveAction {

switch action {
Expand Down Expand Up @@ -229,6 +227,8 @@ final class CollectionViewLayout : UICollectionViewLayout
previousPosition: CGPoint
) -> UICollectionViewLayoutInvalidationContext
{
self.isReordering = true

let context = super.invalidationContext(
forInteractivelyMovingItems: targetIndexPaths,
withTargetPosition: targetPosition,
Expand All @@ -254,6 +254,8 @@ final class CollectionViewLayout : UICollectionViewLayout
movementCancelled: Bool
) -> UICollectionViewLayoutInvalidationContext
{
self.isReordering = false

let context = super.invalidationContextForEndingInteractiveMovementOfItems(
toFinalIndexPaths: indexPaths,
previousIndexPaths: previousIndexPaths,
Expand Down Expand Up @@ -392,8 +394,12 @@ final class CollectionViewLayout : UICollectionViewLayout

switch self.neededLayoutType {
case .none: return true
case .relayout: self.performLayout()
case .rebuild: self.performRebuild(andLayout: shouldLayout)
case .relayout:
print("prepare: relayout")
self.performLayout()
case .rebuild:
print("prepare: rebuild")
self.performRebuild(andLayout: shouldLayout)
}

return true
Expand Down

0 comments on commit 49056c0

Please sign in to comment.