iOS: fix when flexlayout's width is most,it cannot wrap child view properly

This commit is contained in:
pengfei.zhou 2022-07-18 18:20:35 +08:00 committed by osborn
parent 13ba43cb19
commit 037f5afbe0

View File

@ -47,7 +47,22 @@ - (CGSize)sizeThatFits:(CGSize)size {
if (self.yoga.isLeaf) { if (self.yoga.isLeaf) {
return CGSizeZero; return CGSizeZero;
} }
return [self.yoga intrinsicSize]; YGValue maxWidth = self.yoga.maxWidth;
YGValue maxHeight = self.yoga.maxHeight;
if (maxWidth.unit == YGUnitPoint) {
self.yoga.maxWidth = YGPointValue(MIN(maxWidth.value, size.width));
} else {
self.yoga.maxWidth = YGPointValue(size.width);
}
if (maxHeight.unit == YGUnitPoint) {
self.yoga.maxHeight = YGPointValue(MIN(maxHeight.value, size.height));
} else {
self.yoga.maxHeight = YGPointValue(size.height);
}
CGSize ret = [self.yoga intrinsicSize];
self.yoga.maxWidth = maxWidth;
self.yoga.maxHeight = maxHeight;
return ret;
} }
@end @end