[ASDisplayNode] Ensure that nil can never be returned from -measureWithSizeRange: (#2014)

* [ASDisplayNode] Ensure that nil can never be returned from -measureWithSizeRange:

This can happen in rare cases when multiple relayouts occur while a transition is being measured.

* [ASDisplayNode] Use ternary operator style for nil check.
This commit is contained in:
appleguy 2016-07-30 18:04:08 -07:00 committed by GitHub
parent e0ada479a0
commit 965fe05c11
2 changed files with 8 additions and 2 deletions

View File

@ -642,7 +642,8 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
{
ASDN::MutexLocker l(__instanceLock__);
if (! [self shouldMeasureWithSizeRange:constrainedSize]) {
return _calculatedLayout;
ASDisplayNodeAssertNotNil(_calculatedLayout, @"-[ASDisplayNode measureWithSizeRange:] _layout should not be nil! %@", self);
return _calculatedLayout ? : [ASLayout layoutWithLayoutableObject:self constrainedSizeRange:constrainedSize size:CGSizeZero];
}
[self cancelLayoutTransitionsInProgress];
@ -659,6 +660,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
[self _completePendingLayoutTransition];
}
ASDisplayNodeAssertNotNil(newLayout, @"-[ASDisplayNode measureWithSizeRange:] newLayout should not be nil! %@", self);
return newLayout;
}
@ -2071,6 +2073,8 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
layoutSpec.isMutable = NO;
ASLayout *layout = [layoutSpec measureWithSizeRange:constrainedSize];
ASDisplayNodeAssertNotNil(layout, @"[ASLayoutSpec measureWithSizeRange:] should never return nil! %@, %@", self, layoutSpec);
// Make sure layoutableObject of the root layout is `self`, so that the flattened layout will be structurally correct.
BOOL isFinalLayoutable = (layout.layoutableObject != self);
if (isFinalLayoutable) {

View File

@ -28,7 +28,9 @@ static ASLayout *crossChildLayout(const id<ASLayoutable> child,
// stretched children will have a cross dimension of at least crossMin
const CGFloat childCrossMin = alignItems == ASStackLayoutAlignItemsStretch ? crossMin : 0;
const ASSizeRange childSizeRange = directionSizeRange(style.direction, stackMin, stackMax, childCrossMin, crossMax);
return [child measureWithSizeRange:childSizeRange];
ASLayout *layout = [child measureWithSizeRange:childSizeRange];
ASDisplayNodeCAssertNotNil(layout, @"ASLayout returned from measureWithSizeRange: must not be nil: %@", child);
return layout ? : [ASLayout layoutWithLayoutableObject:child constrainedSizeRange:childSizeRange size:CGSizeZero];
}
/**