Add support to move supplementary nodes with section position changes

This commit is contained in:
Levi McCallum
2015-10-06 12:17:11 -07:00
parent 9235ce5ac2
commit 3f0092435a
3 changed files with 19 additions and 6 deletions

View File

@@ -141,7 +141,20 @@
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
{
// TODO: Implement
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]);
NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths);
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
// update the section of indexpaths
NSIndexPath *sectionIndexPath = [[NSIndexPath alloc] initWithIndex:newSection];
NSMutableArray *updatedIndexPaths = [[NSMutableArray alloc] initWithCapacity:indexPaths.count];
[indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
[updatedIndexPaths addObject:[sectionIndexPath indexPathByAddingIndex:[indexPath indexAtPosition:indexPath.length - 1]]];
}];
[self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil];
}];
}
- (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableNodes:(NSMutableArray *)nodes mutableIndexPaths:(NSMutableArray *)indexPaths

View File

@@ -59,12 +59,12 @@
/**
* Read-only access to the underlying editing nodes of the given kind
*/
- (NSArray *)editingNodesOfKind:(NSString *)kind;
- (NSMutableArray *)editingNodesOfKind:(NSString *)kind;
/**
* Read only access to the underlying completed nodes of the given kind
*/
- (NSArray *)completedNodesOfKind:(NSString *)kind;
- (NSMutableArray *)completedNodesOfKind:(NSString *)kind;
/**
* Measure and layout the given nodes in optimized batches, constraining each to a given size in `constrainedSizeForNodeOfKind:atIndexPath:`.

View File

@@ -849,12 +849,12 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
return _editingNodes[kind] != nil ? ASIndexPathsForMultidimensionalArray(_editingNodes[kind]) : [NSArray array];
}
- (NSArray *)editingNodesOfKind:(NSString *)kind
- (NSMutableArray *)editingNodesOfKind:(NSString *)kind
{
return _editingNodes[kind] != nil ? _editingNodes[kind] : [NSArray array];
return _editingNodes[kind] != nil ? _editingNodes[kind] : [NSMutableArray array];
}
- (NSArray *)completedNodesOfKind:(NSString *)kind
- (NSMutableArray *)completedNodesOfKind:(NSString *)kind
{
return _completedNodes[kind];
}