Skip to content

Commit

Permalink
Diff subnodes instead of sublayouts
Browse files Browse the repository at this point in the history
  • Loading branch information
wiseoldduck committed Jul 12, 2018
1 parent 0c949c4 commit 067aa85
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Source/Private/ASLayoutTransition.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ @implementation ASLayoutTransition {
NSArray<ASDisplayNode *> *_insertedSubnodes;
NSArray<ASDisplayNode *> *_removedSubnodes;
std::vector<NSUInteger> _insertedSubnodePositions;
std::vector<NSUInteger> _removedSubnodePositions;
std::vector<std::pair<ASDisplayNode *, NSUInteger>> _subnodeMoves;
}

Expand Down Expand Up @@ -179,7 +178,7 @@ - (void)calculateSubnodeOperationsIfNeeded
// IGListDiff completes in linear time O(m+n), so use it if we have it:
IGListIndexSetResult *result = IGListDiff(previousLayout.sublayouts, pendingLayout.sublayouts, IGListDiffEquality);
_insertedSubnodePositions = findNodesInLayoutAtIndexes(pendingLayout, result.inserts, &_insertedSubnodes);
_removedSubnodePositions = findNodesInLayoutAtIndexes(previousLayout, result.deletes, &_removedSubnodes);
findNodesInLayoutAtIndexes(previousLayout, result.deletes, &_removedSubnodes);
for (IGListMoveIndex *move in result.moves) {
_subnodeMoves.push_back(std::make_pair(previousLayout.sublayouts[move.from].layoutElement, move.to));
}
Expand All @@ -192,16 +191,15 @@ - (void)calculateSubnodeOperationsIfNeeded
#else
NSIndexSet *insertions, *deletions;
NSArray<NSIndexPath *> *moves;
[previousLayout.sublayouts asdk_diffWithArray:pendingLayout.sublayouts
NSArray<ASDisplayNode *> *previousNodes = [previousLayout.sublayouts valueForKey:@"layoutElement"];
NSArray<ASDisplayNode *> *pendingNodes = [pendingLayout.sublayouts valueForKey:@"layoutElement"];
[previousNodes asdk_diffWithArray:pendingNodes
insertions:&insertions
deletions:&deletions
moves:&moves];

_insertedSubnodePositions = findNodesInLayoutAtIndexes(pendingLayout, insertions, &_insertedSubnodes);
_removedSubnodePositions = findNodesInLayoutAtIndexesWithFilteredNodes(previousLayout,
deletions,
_insertedSubnodes,
&_removedSubnodes);
_removedSubnodes = [previousNodes objectsAtIndexes:deletions];
// These should arrive sorted in ascending order of move destinations.
for (NSIndexPath *move in moves) {
_subnodeMoves.push_back(std::make_pair(previousLayout.sublayouts[([move indexAtPosition:0])].layoutElement,
Expand All @@ -212,7 +210,6 @@ - (void)calculateSubnodeOperationsIfNeeded
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [pendingLayout.sublayouts count])];
_insertedSubnodePositions = findNodesInLayoutAtIndexes(pendingLayout, indexes, &_insertedSubnodes);
_removedSubnodes = nil;
_removedSubnodePositions.clear();
}
_calculatedSubnodeOperations = YES;
}
Expand Down

0 comments on commit 067aa85

Please sign in to comment.