Only require node sizes once per run loop, and only if a node's size has changed

This commit is contained in:
Adlai Holler
2015-11-30 17:20:32 -08:00
parent 9032962353
commit 04d93532bc
4 changed files with 44 additions and 8 deletions

View File

@@ -155,6 +155,7 @@ static BOOL _isInterceptedSelector(SEL sel)
BOOL _asyncDelegateImplementsInsetSection;
BOOL _collectionViewLayoutImplementsInsetSection;
BOOL _asyncDataSourceImplementsConstrainedSizeForNode;
BOOL _queuedNodeSizeUpdate;
ASBatchContext *_batchContext;
@@ -912,10 +913,26 @@ static BOOL _isInterceptedSelector(SEL sel)
#pragma mark - ASCellNodeDelegate
- (void)nodeDidRelayout:(ASCellNode *)node
- (void)nodeDidRelayoutWithSizeChange:(ASCellNode *)node
{
ASDisplayNodeAssertMainThread();
// Cause UICollectionView to requery for the new height of this node
if (_queuedNodeSizeUpdate) {
return;
}
_queuedNodeSizeUpdate = YES;
[self performSelector:@selector(requeryNodeSizes)
withObject:nil
afterDelay:0
inModes:@[ NSRunLoopCommonModes ]];
}
// Cause UICollectionView to requery for the new size of all nodes
- (void)requeryNodeSizes
{
_queuedNodeSizeUpdate = NO;
[super performBatchUpdates:^{} completion:nil];
}