Remove threading assumption in ASDisplayNode measureWithSizeRange:"

This commit is contained in:
Huy Nguyen 2016-03-03 00:26:25 -08:00
parent 5e49cc4382
commit f59eb98749

View File

@ -610,12 +610,20 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
- (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
{
return [self measureWithSizeRange:constrainedSize completion:^{
void (^manageSubnodesBlock)() = ^void() {
if (self.usesImplicitHierarchyManagement) {
[self __implicitlyInsertSubnodes];
[self __implicitlyRemoveSubnodes];
}
[self __completeLayoutCalculation];
};
return [self measureWithSizeRange:constrainedSize completion:^{
if (!self.isNodeLoaded) {
manageSubnodesBlock();
} else {
ASPerformBlockOnMainThread(manageSubnodesBlock);
}
}];
}
@ -696,18 +704,15 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
- (void)__completeLayoutCalculation
{
ASDN::MutexLocker l(_propertyLock);
_insertedSubnodes = nil;
_removedSubnodes = nil;
_previousLayout = nil;
[self calculatedLayoutDidChange];
// we generate placeholders at measureWithSizeRange: time so that a node is guaranteed
// to have a placeholder ready to go. Also, if a node has no size it should not have a placeholder
[self __initPlaceholder];
}
- (void)__initPlaceholder
{
if (self.placeholderEnabled && [self _displaysAsynchronously] &&
_layout.size.width > 0.0 && _layout.size.height > 0.0) {
if (!_placeholderImage) {
@ -803,6 +808,7 @@ static inline void filterNodesInLayoutAtIndexesWithIntersectingNodes(
- (void)__implicitlyInsertSubnodes
{
ASDN::MutexLocker l(_propertyLock);
for (NSInteger i = 0; i < [_insertedSubnodes count]; i++) {
NSInteger p = _insertedSubnodePositions[i];
[self insertSubnode:_insertedSubnodes[i] atIndex:p];
@ -811,6 +817,7 @@ static inline void filterNodesInLayoutAtIndexesWithIntersectingNodes(
- (void)__implicitlyRemoveSubnodes
{
ASDN::MutexLocker l(_propertyLock);
for (NSInteger i = 0; i < [_removedSubnodes count]; i++) {
[_removedSubnodes[i] removeFromSupernode];
}