Don't measure range managed nodes automatically in the layout pass

This commit is contained in:
Michael Schneider
2016-09-07 15:17:20 +02:00
committed by Adlai Holler
parent 48991eec4e
commit a0ed3add1c
2 changed files with 3 additions and 26 deletions

View File

@@ -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 {

View File

@@ -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
{