diff --git a/AsyncDisplayKit/Details/ASCollectionDataController.mm b/AsyncDisplayKit/Details/ASCollectionDataController.mm index 1f94ee5e5f..d3c91d6f7d 100644 --- a/AsyncDisplayKit/Details/ASCollectionDataController.mm +++ b/AsyncDisplayKit/Details/ASCollectionDataController.mm @@ -28,6 +28,11 @@ NSMutableDictionary *_pendingIndexPaths; } +- (void)willPerformInitialDataLoading +{ + // TODO: Implement +} + - (void)prepareForReloadData { _pendingNodes = [NSMutableDictionary dictionary]; @@ -71,13 +76,29 @@ }]; } -- (ASSizeRange)constrainedSizeForNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath +- (void)prepareInsertSections:(NSIndexSet *)sections { - if ([kind isEqualToString:ASDataControllerRowNodeKind]) { - return [super constrainedSizeForNodeOfKind:kind atIndexPath:indexPath]; - } else { - return [self.collectionDataSource dataController:self constrainedSizeForSupplementaryNodeOfKind:kind atIndexPath:indexPath]; - } + // TODO: Implement +} + +- (void)willInsertSections:(NSIndexSet *)sections +{ + // TODO: Implement +} + +- (void)willDeleteSections:(NSIndexSet *)sections +{ + // TODO: Implement +} + +- (void)willReloadSections:(NSIndexSet *)sections +{ + // TODO: Implement +} + +- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection +{ + // TODO: Implement } - (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableNodes:(NSMutableArray *)nodes mutableIndexPaths:(NSMutableArray *)indexPaths @@ -94,12 +115,27 @@ } } +#pragma mark - Sizing query + +- (ASSizeRange)constrainedSizeForNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath +{ + if ([kind isEqualToString:ASDataControllerRowNodeKind]) { + return [super constrainedSizeForNodeOfKind:kind atIndexPath:indexPath]; + } else { + return [self.collectionDataSource dataController:self constrainedSizeForSupplementaryNodeOfKind:kind atIndexPath:indexPath]; + } +} + +#pragma mark - External supplementary store querying + - (ASDisplayNode *)supplementaryNodeOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { ASDisplayNodeAssertMainThread(); return [self completedNodesOfKind:kind][indexPath.section][indexPath.item]; } +#pragma mark - Private Helpers + - (id)collectionDataSource { return (id)self.dataSource; diff --git a/AsyncDisplayKit/Details/ASDataController+Subclasses.h b/AsyncDisplayKit/Details/ASDataController+Subclasses.h index d1ae9507cd..ea0d711f53 100644 --- a/AsyncDisplayKit/Details/ASDataController+Subclasses.h +++ b/AsyncDisplayKit/Details/ASDataController+Subclasses.h @@ -25,6 +25,8 @@ */ - (void)accessDataSourceWithBlock:(dispatch_block_t)block; +- (void)willPerformInitialDataLoading; + /** * An opportunity for a subclass to access the data source before entering into the editing queue */ @@ -37,6 +39,18 @@ */ - (void)willReloadData; +- (void)prepareInsertSections:(NSIndexSet *)sections; + +- (void)willInsertSections:(NSIndexSet *)sections; + +- (void)willDeleteSections:(NSIndexSet *)sections; + +- (void)prepareForReloadSections:(NSIndexSet *)sections; + +- (void)willReloadSections:(NSIndexSet *)sections; + +- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection; + /** * Provides a collection of index paths for nodes of the given kind that are currently in the editing store */ diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index 5a73c0200c..89eab8b8e4 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -334,6 +334,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; [self performEditCommandWithBlock:^{ ASDisplayNodeAssertMainThread(); [self accessDataSourceWithBlock:^{ + [self willPerformInitialDataLoading]; + NSMutableArray *indexPaths = [NSMutableArray array]; NSUInteger sectionNum = [_dataSource numberOfSectionsInDataController:self]; @@ -404,6 +406,13 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; }]; } +#pragma mark - Initial & Reload Data Hooks (Subclass API) + +- (void)willPerformInitialDataLoading +{ + // Implemented by subclasses +} + - (void)prepareForReloadData { // Implemented by subclasses @@ -538,7 +547,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; #pragma mark - Section Editing (External API) -- (void)insertSections:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions +- (void)insertSections:(NSIndexSet *)sections withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions { [self performEditCommandWithBlock:^{ ASDisplayNodeAssertMainThread(); @@ -546,41 +555,47 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; [_editingTransactionQueue waitUntilAllOperationsAreFinished]; [self accessDataSourceWithBlock:^{ + [self prepareInsertSections:sections]; + NSMutableArray *updatedNodes = [NSMutableArray array]; NSMutableArray *updatedIndexPaths = [NSMutableArray array]; - [self _populateFromDataSourceWithSectionIndexSet:indexSet mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths]; + [self _populateFromDataSourceWithSectionIndexSet:sections mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths]; // Measure nodes whose views are loaded before we leave the main thread [self _layoutNodesWithMainThreadAffinity:updatedNodes atIndexPaths:updatedIndexPaths]; [_editingTransactionQueue addOperationWithBlock:^{ + [self willInsertSections:sections]; + LOG(@"Edit Transaction - insertSections: %@", indexSet); - NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:indexSet.count]; - for (NSUInteger i = 0; i < indexSet.count; i++) { + NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:sections.count]; + for (NSUInteger i = 0; i < sections.count; i++) { [sectionArray addObject:[NSMutableArray array]]; } - [self _insertSections:sectionArray atIndexSet:indexSet withAnimationOptions:animationOptions]; + [self _insertSections:sectionArray atIndexSet:sections withAnimationOptions:animationOptions]; [self _batchLayoutNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOptions]; }]; }]; }]; } -- (void)deleteSections:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions +- (void)deleteSections:(NSIndexSet *)sections withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions { [self performEditCommandWithBlock:^{ ASDisplayNodeAssertMainThread(); - LOG(@"Edit Command - deleteSections: %@", indexSet); + LOG(@"Edit Command - deleteSections: %@", sections); [_editingTransactionQueue waitUntilAllOperationsAreFinished]; [_editingTransactionQueue addOperationWithBlock:^{ + [self willDeleteSections:sections]; + // remove elements - LOG(@"Edit Transaction - deleteSections: %@", indexSet); - NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet(_editingNodes[ASDataControllerRowNodeKind], indexSet); + LOG(@"Edit Transaction - deleteSections: %@", sections); + NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet(_editingNodes[ASDataControllerRowNodeKind], sections); [self _deleteNodesAtIndexPaths:indexPaths withAnimationOptions:animationOptions]; - [self _deleteSectionsAtIndexSet:indexSet withAnimationOptions:animationOptions]; + [self _deleteSectionsAtIndexSet:sections withAnimationOptions:animationOptions]; }]; }]; } @@ -594,6 +609,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; [_editingTransactionQueue waitUntilAllOperationsAreFinished]; [self accessDataSourceWithBlock:^{ + [self prepareForReloadSections:sections]; + NSMutableArray *updatedNodes = [NSMutableArray array]; NSMutableArray *updatedIndexPaths = [NSMutableArray array]; [self _populateFromDataSourceWithSectionIndexSet:sections mutableNodes:updatedNodes mutableIndexPaths:updatedIndexPaths]; @@ -628,6 +645,8 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; [_editingTransactionQueue waitUntilAllOperationsAreFinished]; [_editingTransactionQueue addOperationWithBlock:^{ + [self willMoveSection:section toSection:newSection]; + // remove elements LOG(@"Edit Transaction - moveSection"); @@ -649,6 +668,38 @@ static void *kASSizingQueueContext = &kASSizingQueueContext; }]; } +#pragma mark - Section Insertion Hooks (Subclass API) + +- (void)prepareInsertSections:(NSIndexSet *)sections +{ + // Implemented by subclass +} + +- (void)willInsertSections:(NSIndexSet *)sections +{ + // Implemented by subclass +} + +- (void)willDeleteSections:(NSIndexSet *)sections +{ + // Implemented by subclass +} + +- (void)prepareForReloadSections:(NSIndexSet *)sections +{ + // Implemented by subclass +} + +- (void)willReloadSections:(NSIndexSet *)sections +{ + // Implemented by subclass +} + +- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection +{ + // Implemented by subclass +} + #pragma mark - Row Editing (External API) - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions