From 037f5afbe07ab76b26b7c3f6f96474c83b13a9ef Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 18 Jul 2022 18:20:35 +0800 Subject: [PATCH] iOS: fix when flexlayout's width is most,it cannot wrap child view properly --- doric-iOS/Pod/Classes/Shader/DoricFlexNode.m | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m index e6240f93..ec07a71a 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m @@ -47,7 +47,22 @@ - (CGSize)sizeThatFits:(CGSize)size { if (self.yoga.isLeaf) { 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 @@ -248,11 +263,11 @@ - (void)requestLayout { self.view.yoga.marginHorizontal = YGValueZero; CGSize size = self.view.yoga.intrinsicSize; if (self.view.yoga.maxWidth.unit != YGUnitPoint - ||(self.view.yoga.maxWidth.unit == YGUnitPoint && self.view.yoga.maxWidth.value > size.width)){ + || (self.view.yoga.maxWidth.unit == YGUnitPoint && self.view.yoga.maxWidth.value > size.width)) { self.view.yoga.maxWidth = YGValueUndefined; } if (self.view.yoga.maxHeight.unit != YGUnitPoint - ||(self.view.yoga.maxHeight.unit == YGUnitPoint && self.view.yoga.maxHeight.value > size.height)){ + || (self.view.yoga.maxHeight.unit == YGUnitPoint && self.view.yoga.maxHeight.value > size.height)) { self.view.yoga.maxHeight = YGValueUndefined; } }