Skip to content

Commit 62d7173

Browse files
committed
Spread
1 parent a367890 commit 62d7173

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

ListableUI/Sources/ListView/ListView.swift

+17-8
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ public final class ListView : UIView
537537
guard let toIndexPath = self.storage.allContent.firstIndexPathForItem(with: item) else {
538538
return false
539539
}
540-
540+
541+
// If user is performing this in a `UIView.performWithoutAnimation` block, respect that and don't animate, regardless of what the animated parameter is.
542+
let shouldAnimate = animated && UIView.areAnimationsEnabled
543+
541544
return self.preparePresentationStateForScroll(to: toIndexPath) {
542545

543546
/// `preparePresentationStateForScroll(to:)` is asynchronous in some
@@ -557,9 +560,6 @@ public final class ListView : UIView
557560
return
558561
}
559562

560-
// If user is performing this in a `UIView.performWithoutAnimation` block, respect that and don't animate, regardless of what the animated parameter is.
561-
let shouldAnimate = animated && UIView.areAnimationsEnabled
562-
563563
let sectionHeader = self.collectionViewLayout.layout.content.sections[toIndexPath.section].header
564564

565565
// Prevent the item from appearing underneath a sticky section header.
@@ -690,9 +690,12 @@ public final class ListView : UIView
690690

691691
// The rect we scroll to must have an area – an empty rect will result in no scrolling.
692692
let rect = CGRect(origin: .zero, size: CGSize(width: 1.0, height: 1.0))
693-
693+
694+
// If user is performing this in a `UIView.performWithoutAnimation` block, respect that and don't animate, regardless of what the animated parameter is.
695+
let shouldAnimate = animated && UIView.areAnimationsEnabled
696+
694697
return self.preparePresentationStateForScroll(to: IndexPath(item: 0, section: 0)) {
695-
self.collectionView.scrollRectToVisible(rect, animated: animated)
698+
self.collectionView.scrollRectToVisible(rect, animated: shouldAnimate)
696699
}
697700
}
698701

@@ -708,6 +711,9 @@ public final class ListView : UIView
708711
return false
709712
}
710713

714+
// If user is performing this in a `UIView.performWithoutAnimation` block, respect that and don't animate, regardless of what the animated parameter is.
715+
let shouldAnimate = animated && UIView.areAnimationsEnabled
716+
711717
// Perform scrolling.
712718

713719
return self.preparePresentationStateForScroll(to: toIndexPath) {
@@ -721,7 +727,7 @@ public final class ListView : UIView
721727
let contentOffsetY = contentHeight - contentFrameHeight - self.collectionView.adjustedContentInset.top
722728
let contentOffset = CGPoint(x: self.collectionView.contentOffset.x, y: contentOffsetY)
723729

724-
self.collectionView.setContentOffset(contentOffset, animated: animated)
730+
self.collectionView.setContentOffset(contentOffset, animated: shouldAnimate)
725731
}
726732
}
727733

@@ -1274,6 +1280,9 @@ public final class ListView : UIView
12741280
return
12751281
}
12761282

1283+
// If user is performing this in a `UIView.performWithoutAnimation` block, respect that and don't animate, regardless of what the animated parameter is.
1284+
let shouldAnimate = animated && UIView.areAnimationsEnabled
1285+
12771286
let topInset = collectionView.adjustedContentInset.top
12781287
let contentFrameHeight = collectionView.visibleContentFrame.height
12791288
let adjustedOriginY = targetFrame.origin.y - topInset
@@ -1298,7 +1307,7 @@ public final class ListView : UIView
12981307

12991308
resultOffset.y = max(resultOffset.y, -topInset)
13001309

1301-
self.collectionView.setContentOffset(resultOffset, animated: animated)
1310+
self.collectionView.setContentOffset(resultOffset, animated: shouldAnimate)
13021311
}
13031312

13041313
private func preparePresentationStateForScroll(to toIndexPath: IndexPath, scroll: @escaping () -> Void) -> Bool {

Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "https://github.com/square/Blueprint",
77
"state" : {
8-
"revision" : "93ccf388f656db030750ac2a895dc80205e5ae20",
9-
"version" : "4.0.0"
8+
"revision" : "976cdea520ce0f8404124b7e4780c46dc2d98212",
9+
"version" : "5.2.0"
1010
}
1111
}
1212
],

0 commit comments

Comments
 (0)