Fixes #606 #610

Closed
kovpas wants to merge 4 commits from fix-606 into master
2 changed files with 25 additions and 4 deletions

View File

@@ -102,6 +102,7 @@ static YGConfigRef globalConfig;
@interface YGLayout ()
@property (nonatomic, weak, readonly) UIView *view;
@property (nonatomic, assign, readonly) BOOL isUIView;
@end
@@ -126,6 +127,7 @@ static YGConfigRef globalConfig;
YGNodeSetContext(_node, (__bridge void *) view);
_isEnabled = NO;
_isIncludedInLayout = YES;
_isUIView = [view isMemberOfClass:[UIView class]];
}
return self;
@@ -304,10 +306,19 @@ static YGSize YGMeasureView(
const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height;
priteshrnandgaonkar commented 2018-01-25 03:07:39 -08:00 (Migrated from github.com)
Review

Instead of pointing to the issue. Can you comment in the code, why this check is added.

Instead of pointing to the issue. Can you comment in the code, why this check is added.
priteshrnandgaonkar commented 2018-01-25 03:34:52 -08:00 (Migrated from github.com)
Review

I think !view.yoga.isUIView this check is not required. Happy to hear about your inputs

I think `!view.yoga.isUIView` this check is not required. Happy to hear about your inputs
kovpas commented 2018-01-25 03:54:45 -08:00 (Migrated from github.com)
Review

this condition practically says "we want to invoke sizeThatFits only in case if the measured view is not a UIView instance or it's a UIView, but has got children". The check is needed because we do want to invoke sizeThatFits for a UILabel (for example) that has got no subviews, but returns a correct value as a result of invocation of sizeThatFits

this condition practically says "we want to invoke `sizeThatFits` only in case if the measured view is not a `UIView` instance or it's a `UIView`, but has got children". The check is needed because we do want to invoke `sizeThatFits` for a UILabel (for example) that has got no subviews, but returns a correct value as a result of invocation of `sizeThatFits`
kovpas commented 2018-01-25 03:58:49 -08:00 (Migrated from github.com)
Review

Done.

Done.
priteshrnandgaonkar commented 2018-01-25 03:59:10 -08:00 (Migrated from github.com)
Review

Aah Got it. Can you add a comment(in brief) explaining this before the condition?

Aah Got it. Can you add a comment(in brief) explaining this before the condition?
kovpas commented 2018-01-25 04:02:34 -08:00 (Migrated from github.com)
Review

Done

Done
UIView *view = (__bridge UIView*) YGNodeGetContext(node);
const CGSize sizeThatFits = [view sizeThatFits:(CGSize) {
.width = constrainedWidth,
.height = constrainedHeight,
}];
CGSize sizeThatFits = CGSizeZero;
// The default implementation of sizeThatFits: returns the existing size of the view.
// That means that if we want to layout an empty UIView, which already has got a frame set,
// its measured size should be CGSizeZero, but UIKit returns the existing size.
//
// See https://github.com/facebook/yoga/issues/606 for more information.
if (!view.yoga.isUIView || [view.subviews count] > 0) {
sizeThatFits = [view sizeThatFits:(CGSize) {
.width = constrainedWidth,
.height = constrainedHeight,
}];
}
return (YGSize) {
.width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),

View File

@@ -129,6 +129,16 @@
XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width);
}
- (void)testSizeThatFitsEmptyView
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
view.yoga.isEnabled = YES;
const CGSize viewSize = view.yoga.intrinsicSize;
XCTAssertEqual(viewSize.height, 0);
XCTAssertEqual(viewSize.width, 0);
}
- (void)testPreservingOrigin
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)];