[ASRelativeLayoutSpec] Fix ASRelatativeLayoutSpec behavior for ASRelativeLayoutSpecPositionStart (#2393)

* Fix ASRelatativeLayoutSpec behavior for ASRelativeLayoutSpecPositionStart

* Add updated images for snapshot tests
This commit is contained in:
Michael Schneider
2016-10-18 12:00:01 -07:00
committed by Adlai Holler
parent 5a8d0037ec
commit ba80b83695
35 changed files with 55 additions and 55 deletions

View File

@@ -54,31 +54,21 @@
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{
// If we have a finite size in any direction, pass this so that the child can
// resolve percentages against it. Otherwise pass ASLayoutElementParentDimensionUndefined
// as the size will depend on the content
// TODO: layout: isValidForLayout() call should not be necessary if INFINITY is used
// If we have a finite size in any direction, pass this so that the child can resolve percentages against it.
// Otherwise pass ASLayoutElementParentDimensionUndefined as the size will depend on the content
CGSize size = {
isinf(constrainedSize.max.width) || !ASPointsValidForLayout(constrainedSize.max.width) ? ASLayoutElementParentDimensionUndefined : constrainedSize.max.width,
isinf(constrainedSize.max.height) || !ASPointsValidForLayout(constrainedSize.max.height) ? ASLayoutElementParentDimensionUndefined : constrainedSize.max.height
ASPointsValidForSize(constrainedSize.max.width) == NO ? ASLayoutElementParentDimensionUndefined : constrainedSize.max.width,
ASPointsValidForSize(constrainedSize.max.height) == NO ? ASLayoutElementParentDimensionUndefined : constrainedSize.max.height
};
BOOL reduceWidth = (_horizontalPosition & ASRelativeLayoutSpecPositionCenter) != 0 ||
(_horizontalPosition & ASRelativeLayoutSpecPositionEnd) != 0;
BOOL reduceHeight = (_verticalPosition & ASRelativeLayoutSpecPositionCenter) != 0 ||
(_verticalPosition & ASRelativeLayoutSpecPositionEnd) != 0;
// Layout the child
const CGSize minChildSize = {
reduceWidth ? 0 : constrainedSize.min.width,
reduceHeight ? 0 : constrainedSize.min.height,
(_horizontalPosition != ASRelativeLayoutSpecPositionNone) ? 0 : constrainedSize.min.width,
(_verticalPosition != ASRelativeLayoutSpecPositionNone) ? 0 : constrainedSize.min.height,
};
ASLayout *sublayout = [self.child layoutThatFits:ASSizeRangeMake(minChildSize, constrainedSize.max) parentSize:size];
// If we have an undetermined height or width, use the child size to define the layout
// size
// If we have an undetermined height or width, use the child size to define the layout size
size = ASSizeRangeClamp(constrainedSize, {
isfinite(size.width) == NO ? sublayout.size.width : size.width,
isfinite(size.height) == NO ? sublayout.size.height : size.height
@@ -104,9 +94,9 @@
- (CGFloat)proportionOfAxisForAxisPosition:(ASRelativeLayoutSpecPosition)position
{
if ((position & ASRelativeLayoutSpecPositionCenter) != 0) {
if (position == ASRelativeLayoutSpecPositionCenter) {
return 0.5f;
} else if ((position & ASRelativeLayoutSpecPositionEnd) != 0) {
} else if (position == ASRelativeLayoutSpecPositionEnd) {
return 1.0f;
} else {
return 0.0f;