Skip to content

Commit 3f00924

Browse files
author
Levi McCallum
committed
Add support to move supplementary nodes with section position changes
1 parent 9235ce5 commit 3f00924

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

AsyncDisplayKit/Details/ASCollectionDataController.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,20 @@ - (void)willReloadSections:(NSIndexSet *)sections
141141

142142
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
143143
{
144-
// TODO: Implement
144+
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
145+
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
146+
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]);
147+
NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths);
148+
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
149+
150+
// update the section of indexpaths
151+
NSIndexPath *sectionIndexPath = [[NSIndexPath alloc] initWithIndex:newSection];
152+
NSMutableArray *updatedIndexPaths = [[NSMutableArray alloc] initWithCapacity:indexPaths.count];
153+
[indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) {
154+
[updatedIndexPaths addObject:[sectionIndexPath indexPathByAddingIndex:[indexPath indexAtPosition:indexPath.length - 1]]];
155+
}];
156+
[self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil];
157+
}];
145158
}
146159

147160
- (void)_populateSupplementaryNodesOfKind:(NSString *)kind withMutableNodes:(NSMutableArray *)nodes mutableIndexPaths:(NSMutableArray *)indexPaths

AsyncDisplayKit/Details/ASDataController+Subclasses.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@
5959
/**
6060
* Read-only access to the underlying editing nodes of the given kind
6161
*/
62-
- (NSArray *)editingNodesOfKind:(NSString *)kind;
62+
- (NSMutableArray *)editingNodesOfKind:(NSString *)kind;
6363

6464
/**
6565
* Read only access to the underlying completed nodes of the given kind
6666
*/
67-
- (NSArray *)completedNodesOfKind:(NSString *)kind;
67+
- (NSMutableArray *)completedNodesOfKind:(NSString *)kind;
6868

6969
/**
7070
* Measure and layout the given nodes in optimized batches, constraining each to a given size in `constrainedSizeForNodeOfKind:atIndexPath:`.

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,12 +849,12 @@ - (NSArray *)indexPathsForEditingNodesOfKind:(NSString *)kind
849849
return _editingNodes[kind] != nil ? ASIndexPathsForMultidimensionalArray(_editingNodes[kind]) : [NSArray array];
850850
}
851851

852-
- (NSArray *)editingNodesOfKind:(NSString *)kind
852+
- (NSMutableArray *)editingNodesOfKind:(NSString *)kind
853853
{
854-
return _editingNodes[kind] != nil ? _editingNodes[kind] : [NSArray array];
854+
return _editingNodes[kind] != nil ? _editingNodes[kind] : [NSMutableArray array];
855855
}
856856

857-
- (NSArray *)completedNodesOfKind:(NSString *)kind
857+
- (NSMutableArray *)completedNodesOfKind:(NSString *)kind
858858
{
859859
return _completedNodes[kind];
860860
}

0 commit comments

Comments
 (0)