Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit ada553c

Browse files
author
Adlai Holler
authored
Avoid Measuring Cell Nodes with Empty Size Range (#3000)
* Always avoid measuring cell nodes with empty bounds * Be lenient * Add required assertion comment * Avoid importing non-modular header publicly
1 parent b33cced commit ada553c

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ - (void)batchLayoutNodesFromContexts:(NSArray<ASIndexedNodeContext *> *)contexts
173173
*/
174174
- (void)_layoutNode:(ASCellNode *)node withConstrainedSize:(ASSizeRange)constrainedSize
175175
{
176+
ASDisplayNodeAssert(ASSizeRangeHasSignificantArea(constrainedSize), @"Attempt to layout cell node with invalid size range %@", NSStringFromASSizeRange(constrainedSize));
177+
176178
CGRect frame = CGRectZero;
177179
frame.size = [node layoutThatFits:constrainedSize].size;
178180
node.frame = frame;
@@ -214,7 +216,12 @@ - (void)_batchLayoutAndInsertNodesFromContexts:(NSArray<ASIndexedNodeContext *>
214216
node = [[ASCellNode alloc] init]; // Fallback to avoid crash for production apps.
215217
}
216218

217-
[self _layoutNode:node withConstrainedSize:context.constrainedSize];
219+
// Layout the node if the size range is valid.
220+
ASSizeRange sizeRange = context.constrainedSize;
221+
if (ASSizeRangeHasSignificantArea(sizeRange)) {
222+
[self _layoutNode:node withConstrainedSize:sizeRange];
223+
}
224+
218225
#if AS_MEASURE_AVOIDED_DATACONTROLLER_WORK
219226
[ASDataController _didLayoutNode];
220227
#endif
@@ -893,7 +900,9 @@ - (void)_relayoutNodesOfKind:(NSString *)kind
893900
RETURN_IF_NO_DATASOURCE();
894901
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:sectionIndex];
895902
ASSizeRange constrainedSize = [self constrainedSizeForNodeOfKind:kind atIndexPath:indexPath];
896-
[self _layoutNode:node withConstrainedSize:constrainedSize];
903+
if (ASSizeRangeHasSignificantArea(constrainedSize)) {
904+
[self _layoutNode:node withConstrainedSize:constrainedSize];
905+
}
897906
rowIndex += 1;
898907
}
899908
sectionIndex += 1;

AsyncDisplayKit/Layout/ASDimension.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ extern ASSizeRange const ASSizeRangeZero;
211211
*/
212212
extern ASSizeRange const ASSizeRangeUnconstrained;
213213

214+
/**
215+
* Returns whether a size range has > 0.1 max width and max height.
216+
*/
217+
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT BOOL ASSizeRangeHasSignificantArea(ASSizeRange sizeRange)
218+
{
219+
static CGFloat const limit = 0.1;
220+
return (sizeRange.max.width > limit && sizeRange.max.height > limit);
221+
}
222+
214223
/**
215224
* Creates an ASSizeRange with provided min and max size.
216225
*/

0 commit comments

Comments
 (0)