Skip to content

Commit

Permalink
Fix scroll node in yoga (#1435)
Browse files Browse the repository at this point in the history
* fix SIMULATE_WEB_RESPONSE not imported #449

* Fix to make rangeMode update in right time

* remove uncessary assert

* Fix collection cell editing bug for iOS 9 & 10

* Revert "Fix collection cell editing bug for iOS 9 & 10"

This reverts commit 06e18a1.

* Fix child not fit to full scroll node's bounds when flex_grow = 1.0 is used on child
  • Loading branch information
wsdwsd0829 authored and Adlai-Holler committed Apr 2, 2019
1 parent 442317b commit d970dc3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Source/ASScrollNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
if (ASPointsValidForLayout(selfSize.height) == NO) {
selfSize.height = _contentCalculatedSizeFromLayout.height;
}

// The side effect for layout with CGFLOAT_MAX is that the min-height/width on the child of
// ScrollNode may not be applied correctly. Resulting in the contentSize less than the
// scrollNode's bounds which may not be what the child want (e.g. The child want to fill
// ScrollNode's bounds). In that case we need to give it a chance to layout with ScrollNode's
// bound in case children want to fill the ScrollNode's bound.
if ((ASScrollDirectionContainsVerticalDirection(_scrollableDirections) &&
layout.size.height < selfSize.height) ||
(ASScrollDirectionContainsHorizontalDirection(_scrollableDirections) &&
layout.size.width < selfSize.width)) {
layout = [super calculateLayoutThatFits:constrainedSize
restrictedToSize:size
relativeToParentSize:parentSize];
}

// Don't provide a position, as that should be set by the parent.
layout = [ASLayout layoutWithLayoutElement:self
size:selfSize
Expand Down
34 changes: 34 additions & 0 deletions Tests/ASScrollNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,40 @@ - (void)testAutomaticallyManagesContentSizeWithSizeRangeSmallerThanParentSize
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}

- (void)testAutomaticallyManagesContentSizeWithSizeRangeSmallerThanParentSizeFillContainer
{
CGSize subnodeSize = CGSizeMake(100, 200);
CGSize parentSize = CGSizeMake(100, 500);
ASSizeRange sizeRange = ASSizeRangeMake(CGSizeMake(100, 200), CGSizeMake(100, 200));

self.subnode.style.flexGrow = 1.0;
self.subnode.style.minHeight = ASDimensionMake(ASDimensionUnitPoints, 50.0);
self.subnode.style.width = ASDimensionMake(ASDimensionUnitPoints, 100.0);
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];

ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, sizeRange.max);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}

// It's expected that the contentSize is 100x100 when ScrollNode's bounds is 100x200, which currently
// not the case for LayoutSepc but work in Yoga.
- (void)disable_testAutomaticallyManagesContentSizeWithSizeRangeSmallerThanParentSizeKeepChildSize
{
CGSize subnodeSize = CGSizeMake(100, 100);
CGSize parentSize = CGSizeMake(100, 200);
ASSizeRange sizeRange = ASSizeRangeMake(CGSizeMake(100, 200), CGSizeMake(100, 200));

self.subnode.style.width = ASDimensionMake(ASDimensionUnitPoints, 100.0);
self.subnode.style.height = ASDimensionMake(ASDimensionUnitPoints, 100.0);

[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];

ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, sizeRange.max);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}

- (void)testAutomaticallyManagesContentSizeWithSizeRangeBiggerThanParentSize
{
CGSize subnodeSize = CGSizeMake(100, 200);
Expand Down

0 comments on commit d970dc3

Please sign in to comment.