Stub out subclass hooks for section insert/remove/update/moving

This commit is contained in:
Levi McCallum
2015-10-06 12:00:13 -07:00
parent ed7a73361b
commit f9bba315df
3 changed files with 117 additions and 16 deletions

View File

@@ -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<ASCollectionDataControllerSource>)collectionDataSource
{
return (id<ASCollectionDataControllerSource>)self.dataSource;

View File

@@ -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
*/

View File

@@ -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