mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-20 13:19:16 +00:00
[ASRangeController] Don't bother asking UIKit for the visible index paths if view is zero-sized, as it triggers a reloadData.
This commit is contained in:
parent
aab2ecc26e
commit
0e460ca00a
@ -867,7 +867,10 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
- (NSArray *)visibleNodeIndexPathsForRangeController:(ASRangeController *)rangeController
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
return [self indexPathsForVisibleItems];
|
||||
// Calling visibleNodeIndexPathsForRangeController: will trigger UIKit to call reloadData if it never has, which can result
|
||||
// in incorrect layout if performed at zero size. We can use the fact that nothing can be visible at zero size to return fast.
|
||||
BOOL isZeroSized = CGRectEqualToRect(self.bounds, CGRectZero);
|
||||
return isZeroSized ? @[] : [self indexPathsForVisibleItems];
|
||||
}
|
||||
|
||||
- (CGSize)viewportSizeForRangeController:(ASRangeController *)rangeController
|
||||
|
||||
@ -718,6 +718,12 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
|
||||
// Calling indexPathsForVisibleRows will trigger UIKit to call reloadData if it never has, which can result
|
||||
// in incorrect layout if performed at zero size. We can use the fact that nothing can be visible at zero size to return fast.
|
||||
if (CGRectEqualToRect(self.bounds, CGRectZero)) {
|
||||
return @[];
|
||||
}
|
||||
|
||||
NSArray *visibleIndexPaths = self.indexPathsForVisibleRows;
|
||||
|
||||
if (_pendingVisibleIndexPath) {
|
||||
|
||||
@ -149,6 +149,17 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
|
||||
return;
|
||||
}
|
||||
|
||||
// allNodes is a 2D array: it contains arrays for each section, each containing nodes.
|
||||
NSArray<NSArray *> *allNodes = [_dataSource completedNodes];
|
||||
NSUInteger numberOfSections = [allNodes count];
|
||||
|
||||
if (_allPreviousIndexPaths.count == 0 && allNodes.count == 0) {
|
||||
// In certain cases, such as on app suspend, an update may be triggered before we've loaded anything.
|
||||
// For example, an ASCollectionNode inside another scrollable area will not load content until it has entered
|
||||
// the display range, but the object may have been allocated by a cell and added to the set of active range controllers.
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Consider if we need to use this codepath, or can rely on something more similar to the data & display ranges
|
||||
// Example: ... = [_layoutController indexPathsForScrolling:_scrollDirection rangeType:ASLayoutRangeTypeVisible];
|
||||
NSArray<NSIndexPath *> *visibleNodePaths = [_dataSource visibleNodeIndexPathsForRangeController:self];
|
||||
@ -165,10 +176,6 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
|
||||
[_layoutController setVisibleNodeIndexPaths:visibleNodePaths];
|
||||
}
|
||||
|
||||
// allNodes is a 2D array: it contains arrays for each section, each containing nodes.
|
||||
NSArray<NSArray *> *allNodes = [_dataSource completedNodes];
|
||||
NSUInteger numberOfSections = [allNodes count];
|
||||
|
||||
NSArray<ASDisplayNode *> *currentSectionNodes = nil;
|
||||
NSInteger currentSectionIndex = -1; // Set to -1 so we don't match any indexPath.section on the first iteration.
|
||||
NSUInteger numberOfNodesInSection = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user