Only throw if ASLayoutElement style width or height are ASDimensionUnitFraction (#2484)

This commit is contained in:
Michael Schneider
2016-10-26 17:17:09 -07:00
committed by Adlai Holler
parent 627d146a5a
commit eb6cf0689d
2 changed files with 5 additions and 3 deletions

View File

@@ -257,12 +257,12 @@ do {\
- (CGSize)preferredSize
{
ASDN::MutexLocker l(__instanceLock__);
if (_size.width.unit != ASDimensionUnitPoints) {
if (_size.width.unit == ASDimensionUnitFraction) {
NSCAssert(NO, @"Cannot get preferredSize of element with fractional width. Width: %@.", NSStringFromASDimension(_size.width));
return CGSizeZero;
}
if (_size.height.unit != ASDimensionUnitPoints) {
if (_size.height.unit == ASDimensionUnitFraction) {
NSCAssert(NO, @"Cannot get preferredSize of element with fractional height. Height: %@.", NSStringFromASDimension(_size.height));
return CGSizeZero;
}

View File

@@ -58,6 +58,8 @@
{
ASLayoutElementStyle *style = [ASLayoutElementStyle new];
ASXCTAssertEqualSizes(style.preferredSize, CGSizeZero);
CGSize size = CGSizeMake(100, 100);
style.preferredSize = size;
@@ -78,7 +80,7 @@
{
ASLayoutElementStyle *style = [ASLayoutElementStyle new];
XCTAssertThrows(style.preferredSize);
XCTAssertNoThrow(style.preferredSize);
style.width = ASDimensionMake(ASDimensionUnitFraction, 0.5);
XCTAssertThrows(style.preferredSize);