Merge pull request #793 from nguyenhuy/ImproveCellNodeRelayout

ASCellNode delegate to automatically resize in table & collection when -setNeedsLayout called.
This commit is contained in:
appleguy
2015-11-01 11:11:32 -08:00
17 changed files with 116 additions and 97 deletions

View File

@@ -12,7 +12,6 @@
#import "ASCollectionViewLayoutController.h"
#import "ASRangeController.h"
#import "ASCollectionDataController.h"
#import "ASDisplayNodeInternal.h"
#import "ASBatchFetching.h"
#import "UICollectionViewLayout+ASConvenience.h"
#import "ASInternalHelpers.h"
@@ -131,7 +130,7 @@ static BOOL _isInterceptedSelector(SEL sel)
#pragma mark -
#pragma mark ASCollectionView.
@interface ASCollectionView () <ASRangeControllerDelegate, ASDataControllerSource> {
@interface ASCollectionView () <ASRangeControllerDelegate, ASDataControllerSource, ASCellNodeDelegate> {
_ASCollectionViewProxy *_proxyDataSource;
_ASCollectionViewProxy *_proxyDelegate;
@@ -269,7 +268,7 @@ static BOOL _isInterceptedSelector(SEL sel)
- (void)reloadDataWithCompletion:(void (^)())completion
{
ASDisplayNodeAssert(self.asyncDelegate, @"ASCollectionView's asyncDelegate property must be set.");
ASDisplayNodePerformBlockOnMainThread(^{
ASPerformBlockOnMainThread(^{
_superIsPendingDataLoad = YES;
[super reloadData];
});
@@ -458,14 +457,6 @@ static BOOL _isInterceptedSelector(SEL sel)
[_dataController reloadRowsAtIndexPaths:indexPaths withAnimationOptions:kASCollectionViewAnimationNone];
}
- (void)relayoutItemAtIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNodeAssertMainThread();
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
[node setNeedsLayout];
[super reloadItemsAtIndexPaths:@[indexPath]];
}
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
{
ASDisplayNodeAssertMainThread();
@@ -664,6 +655,7 @@ static BOOL _isInterceptedSelector(SEL sel)
{
ASCellNode *node = [_asyncDataSource collectionView:self nodeForItemAtIndexPath:indexPath];
ASDisplayNodeAssert([node isKindOfClass:ASCellNode.class], @"invalid node class, expected ASCellNode");
node.delegate = self;
return node;
}
@@ -895,4 +887,15 @@ static BOOL _isInterceptedSelector(SEL sel)
}
}
#pragma mark - ASCellNodeDelegate
- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation
{
ASDisplayNodeAssertMainThread();
NSIndexPath *indexPath = [self indexPathForNode:node];
if (indexPath != nil) {
[super reloadItemsAtIndexPaths:@[indexPath]];
}
}
@end