mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
[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:
parent
e0ada479a0
commit
965fe05c11
@ -642,7 +642,8 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
if (! [self shouldMeasureWithSizeRange:constrainedSize]) {
|
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];
|
[self cancelLayoutTransitionsInProgress];
|
||||||
@ -659,6 +660,7 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
[self _completePendingLayoutTransition];
|
[self _completePendingLayoutTransition];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASDisplayNodeAssertNotNil(newLayout, @"-[ASDisplayNode measureWithSizeRange:] newLayout should not be nil! %@", self);
|
||||||
return newLayout;
|
return newLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2071,6 +2073,8 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
|
|||||||
|
|
||||||
layoutSpec.isMutable = NO;
|
layoutSpec.isMutable = NO;
|
||||||
ASLayout *layout = [layoutSpec measureWithSizeRange:constrainedSize];
|
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.
|
// Make sure layoutableObject of the root layout is `self`, so that the flattened layout will be structurally correct.
|
||||||
BOOL isFinalLayoutable = (layout.layoutableObject != self);
|
BOOL isFinalLayoutable = (layout.layoutableObject != self);
|
||||||
if (isFinalLayoutable) {
|
if (isFinalLayoutable) {
|
||||||
|
|||||||
@ -28,7 +28,9 @@ static ASLayout *crossChildLayout(const id<ASLayoutable> child,
|
|||||||
// stretched children will have a cross dimension of at least crossMin
|
// stretched children will have a cross dimension of at least crossMin
|
||||||
const CGFloat childCrossMin = alignItems == ASStackLayoutAlignItemsStretch ? crossMin : 0;
|
const CGFloat childCrossMin = alignItems == ASStackLayoutAlignItemsStretch ? crossMin : 0;
|
||||||
const ASSizeRange childSizeRange = directionSizeRange(style.direction, stackMin, stackMax, childCrossMin, crossMax);
|
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];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user