Fixes #606 #610
@@ -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;
|
||||
|
||||
|
||||
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),
|
||||
|
@@ -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)];
|
||||
|
Reference in New Issue
Block a user
Instead of pointing to the issue. Can you comment in the code, why this check is added.
I think
!view.yoga.isUIView
this check is not required. Happy to hear about your inputsthis condition practically says "we want to invoke
sizeThatFits
only in case if the measured view is not aUIView
instance or it's aUIView
, but has got children". The check is needed because we do want to invokesizeThatFits
for a UILabel (for example) that has got no subviews, but returns a correct value as a result of invocation ofsizeThatFits
Done.
Aah Got it. Can you add a comment(in brief) explaining this before the condition?
Done