mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Prevent calculation of current index path when the collection view is empty
This commit is contained in:
@@ -25,10 +25,8 @@
|
|||||||
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset
|
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset
|
||||||
{
|
{
|
||||||
if (self.currentIndexPath) {
|
if (self.currentIndexPath) {
|
||||||
CGPoint contentOffset = [self _targetContentOffsetForItemAtIndexPath:self.currentIndexPath
|
return [self _targetContentOffsetForItemAtIndexPath:self.currentIndexPath
|
||||||
proposedContentOffset:proposedContentOffset];
|
proposedContentOffset:proposedContentOffset];
|
||||||
self.currentIndexPath = nil;
|
|
||||||
return contentOffset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [super targetContentOffsetForProposedContentOffset:proposedContentOffset];
|
return [super targetContentOffsetForProposedContentOffset:proposedContentOffset];
|
||||||
@@ -43,6 +41,10 @@
|
|||||||
|
|
||||||
- (NSIndexPath *)_indexPathForVisiblyCenteredItem
|
- (NSIndexPath *)_indexPathForVisiblyCenteredItem
|
||||||
{
|
{
|
||||||
|
if ([self _dataSourceIsEmpty]) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
CGRect visibleRect = [self _visibleRect];
|
CGRect visibleRect = [self _visibleRect];
|
||||||
CGFloat visibleXCenter = CGRectGetMidX(visibleRect);
|
CGFloat visibleXCenter = CGRectGetMidX(visibleRect);
|
||||||
NSArray<UICollectionViewLayoutAttributes *> *layoutAttributes = [self layoutAttributesForElementsInRect:visibleRect];
|
NSArray<UICollectionViewLayoutAttributes *> *layoutAttributes = [self layoutAttributesForElementsInRect:visibleRect];
|
||||||
@@ -54,6 +56,18 @@
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)_dataSourceIsEmpty
|
||||||
|
{
|
||||||
|
if ([self.collectionView numberOfSections]) {
|
||||||
|
if ([self.collectionView numberOfItemsInSection:0] == 0) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
- (CGRect)_visibleRect
|
- (CGRect)_visibleRect
|
||||||
{
|
{
|
||||||
CGRect visibleRect;
|
CGRect visibleRect;
|
||||||
|
|||||||
Reference in New Issue
Block a user