mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-22 19:13:55 +08:00
Don't measure range managed nodes automatically in the layout pass
This commit is contained in:
committed by
Adlai Holler
parent
48991eec4e
commit
a0ed3add1c
@@ -1342,17 +1342,19 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
||||
|
||||
- (void)measureNodeWithBoundsIfNecessary:(CGRect)bounds
|
||||
{
|
||||
BOOL supportsRangeManagedInterfaceState = NO;
|
||||
BOOL hasDirtyLayout = NO;
|
||||
CGSize calculatedLayoutSize = CGSizeZero;
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
supportsRangeManagedInterfaceState = [self supportsRangeManagedInterfaceState];
|
||||
hasDirtyLayout = [self _hasDirtyLayout];
|
||||
calculatedLayoutSize = _calculatedLayout.size;
|
||||
}
|
||||
|
||||
// If no measure pass happened or the bounds changed between layout passes we manually trigger a measurement pass
|
||||
// for the node using a size range equal to whatever bounds were provided to the node
|
||||
if (hasDirtyLayout || CGSizeEqualToSize(calculatedLayoutSize, bounds.size) == NO) {
|
||||
if (supportsRangeManagedInterfaceState == NO && (hasDirtyLayout || CGSizeEqualToSize(calculatedLayoutSize, bounds.size) == NO)) {
|
||||
if (CGRectEqualToRect(bounds, CGRectZero)) {
|
||||
LOG(@"Warning: No size given for node before node was trying to layout itself: %@. Please provide a frame for the node.", self);
|
||||
} else {
|
||||
|
||||
@@ -43,31 +43,6 @@
|
||||
ASXCTAssertEqualSizes(buttonNode.calculatedSize, nodeSize, @"Automatic measurement pass should have happened in layout pass");
|
||||
}
|
||||
|
||||
- (void)testMeasureOnLayoutIfNotHappenedBeforeForRangeManagedNodes
|
||||
{
|
||||
CGSize nodeSize = CGSizeMake(100, 100);
|
||||
|
||||
ASStaticSizeDisplayNode *displayNode = [ASStaticSizeDisplayNode new];
|
||||
displayNode.staticSize = nodeSize;
|
||||
|
||||
ASButtonNode *buttonNode = [ASButtonNode new];
|
||||
[displayNode addSubnode:buttonNode];
|
||||
|
||||
[displayNode enterHierarchyState:ASHierarchyStateRangeManaged];
|
||||
|
||||
displayNode.frame = {.size = nodeSize};
|
||||
buttonNode.frame = {.size = nodeSize};
|
||||
|
||||
ASXCTAssertEqualSizes(displayNode.calculatedSize, CGSizeZero, @"Calculated size before measurement and layout should be 0");
|
||||
ASXCTAssertEqualSizes(buttonNode.calculatedSize, CGSizeZero, @"Calculated size before measurement and layout should be 0");
|
||||
|
||||
// Trigger layout pass without a maeasurment pass before
|
||||
[displayNode.view layoutIfNeeded];
|
||||
|
||||
ASXCTAssertEqualSizes(displayNode.calculatedSize, nodeSize, @"Automatic measurement pass should have happened in layout pass");
|
||||
ASXCTAssertEqualSizes(buttonNode.calculatedSize, nodeSize, @"Automatic measurement pass should have happened in layout pass");
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
- (void)testNotAllowAddingSubnodesInLayoutSpecThatFits
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user