Skip to content

Commit

Permalink
Merge pull request facebookarchive#2627 from maicki/MSFixStackLayoutS…
Browse files Browse the repository at this point in the history
…paceRounding

[ASStackLayoutSpec] Don’t floor space between items for ASStackLayoutJustifyContentSpaceBetween and ASStackLayoutJustifyContentSpaceAround
  • Loading branch information
Adlai Holler authored Nov 18, 2016
2 parents da465bf + bc0443d commit 198ea7a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions AsyncDisplayKit/Private/ASStackPositionedLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ static ASStackPositionedLayout stackedLayout(const ASStackLayoutSpecStyle &style
return stackedLayout(style, violation, unpositionedLayout, constrainedSize);
}
case ASStackLayoutJustifyContentSpaceBetween: {
// Spacing between the items, no spaces at the edges, evenly distributed
const auto numOfSpacings = numOfItems - 1;
return stackedLayout(style, 0, std::floor(violation / numOfSpacings), std::fmod(violation, numOfSpacings), unpositionedLayout, constrainedSize);
return stackedLayout(style, 0, violation / numOfSpacings, 0, unpositionedLayout, constrainedSize);
}
case ASStackLayoutJustifyContentSpaceAround: {
// Spacing between items are twice the spacing on the edges
CGFloat spacingUnit = std::floor(violation / (numOfItems * 2));
CGFloat spacingUnit = violation / (numOfItems * 2);
return stackedLayout(style, spacingUnit, spacingUnit * 2, 0, unpositionedLayout, constrainedSize);
}
}
Expand Down
4 changes: 2 additions & 2 deletions AsyncDisplayKitTests/ASStackLayoutSpecSnapshotTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ - (void)testJustifiedSpaceAroundWithOneChild

- (void)testJustifiedSpaceBetweenWithRemainingSpace
{
// width 301px; height 0-300px; 1px remaining
// width 301px; height 0-300px;
static ASSizeRange kSize = {{301, 0}, {301, 300}};
[self testStackLayoutSpecWithJustify:ASStackLayoutJustifyContentSpaceBetween flexFactor:0 sizeRange:kSize identifier:nil];
}

- (void)testJustifiedSpaceAroundWithRemainingSpace
{
// width 305px; height 0-300px; 5px remaining
// width 305px; height 0-300px;
static ASSizeRange kSize = {{305, 0}, {305, 300}};
[self testStackLayoutSpecWithJustify:ASStackLayoutJustifyContentSpaceAround flexFactor:0 sizeRange:kSize identifier:nil];
}
Expand Down
Binary file modified ...SStackLayoutSpecSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...StackLayoutSpecSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 198ea7a

Please sign in to comment.