Do not measure the view if it is hidden.

Summary: If views are hidden on screen, we don't want to bother including them in layout calculations.

Reviewed By: rnystrom

Differential Revision: D4022992

fbshipit-source-id: 2e93eb911f26223f305ef7ce788f86d050b83e4a
This commit is contained in:
Dustin Shahidehpour
2016-10-14 14:22:49 -07:00
committed by Facebook Github Bot
parent 89440f630f
commit 05ba3a2565
2 changed files with 23 additions and 2 deletions

View File

@@ -16,11 +16,24 @@
@implementation CSSLayoutTests
- (void)testSmoke
- (void)testHiddenViewsAreNotMeasured
{
const CGSize firstSize = CGSizeMake(100, 100);
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view css_setUsesFlexbox:YES];
XCTAssertTrue([view css_usesFlexbox]);
[view css_setWidth:firstSize.width];
[view css_setHeight:firstSize.height];
[view css_applyLayout];
XCTAssertTrue(CGSizeEqualToSize(firstSize, view.frame.size));
const CGSize newSize = CGSizeMake(200, 200);
[view css_setWidth:newSize.width];
[view css_setHeight:newSize.height];
view.hidden = YES;
[view css_applyLayout];
XCTAssertFalse(CGSizeEqualToSize(newSize, view.frame.size));
}
@end

View File

@@ -226,6 +226,10 @@ static void _updateFrameRecursive(UIView *view);
@end
static void _attachNodesRecursive(UIView *view) {
if (view.isHidden) {
return;
}
CSSNodeRef node = [view cssNode];
const BOOL usesFlexbox = [view css_usesFlexbox];
const BOOL isLeaf = !usesFlexbox || view.subviews.count == 0;
@@ -258,6 +262,10 @@ static void _attachNodesRecursive(UIView *view) {
}
static void _updateFrameRecursive(UIView *view) {
if (view.isHidden) {
return;
}
CSSNodeRef node = [view cssNode];
const BOOL usesFlexbox = [view css_usesFlexbox];
const BOOL isLeaf = !usesFlexbox || view.subviews.count == 0;