Adds trampoline for inserting and deletion of nodes

Currently measurement always needs to happen on the main thread if implicit hierarchy management is enabled as adding and removing from nodes needs to happen on the main thread. We now will trampoline to the main thread to do the insertion and deletion of nodes.

This also resolves the issue that can occur if a node is already loaded deep in the layout hierarchy in the layout that the node is transforming to. Before insertion or deletion is happening we need to crawl the layout hierarchy to check that though.
This commit is contained in:
Michael Schneider
2016-06-28 16:41:57 -07:00
parent a77a6eaaf5
commit 01fed69b26
7 changed files with 206 additions and 20 deletions

View File

@@ -18,10 +18,37 @@
#import "ASLayout.h"
#import <vector>
#import <queue>
#import "NSArray+Diffing.h"
#import "ASEqualityHelpers.h"
/**
* Search the whole layout stack if at least one layout has a layoutable object that can not be layed out asynchronous.
* This can be the case for example if a node was already loaded
*/
static BOOL ASLayoutCanTransitionAsynchronous(ASLayout *layout) {
// Queue used to keep track of sublayouts while traversing this layout in a BFS fashion.
std::queue<ASLayout *> queue;
queue.push(layout);
while (!queue.empty()) {
layout = queue.front();
queue.pop();
if (layout.layoutableObject.canLayoutAsynchronous == NO) {
return NO;
}
// Add all sublayouts to process in next step
for (int i = 0; i < layout.sublayouts.count; i++) {
queue.push(layout.sublayouts[0]);
}
}
return YES;
}
@implementation ASLayoutTransition {
ASDN::RecursiveMutex _propertyLock;
BOOL _calculatedSubnodeOperations;
@@ -44,6 +71,18 @@
return self;
}
- (BOOL)canTransitionAsynchronous
{
ASDN::MutexLocker l(_propertyLock);
return ASLayoutCanTransitionAsynchronous(_pendingLayout);
}
- (void)applySubnodeTransition
{
[self applySubnodeInsertions];
[self applySubnodeRemovals];
}
- (void)applySubnodeInsertions
{
ASDN::MutexLocker l(_propertyLock);