iOS: DoricLayout add other logic such as maxWidth and maxHeight and so on

This commit is contained in:
pengfei.zhou 2022-08-24 19:42:05 +08:00 committed by osborn
parent 8fbbaa7f56
commit 16cc6446e9

View File

@ -180,6 +180,9 @@ - (DoricMeasureSpec)getRootMeasureSpec:(CGFloat)targetSize
case DoricLayoutMost: case DoricLayoutMost:
return DoricMeasureSpecMake(DoricMeasureExactly, targetSize); return DoricMeasureSpecMake(DoricMeasureExactly, targetSize);
case DoricLayoutFit: case DoricLayoutFit:
if ([self.view.superview isKindOfClass:UIScrollView.class]) {
return DoricMeasureSpecMake(DoricMeasureAtMost, CGFLOAT_MAX);
}
return DoricMeasureSpecMake(DoricMeasureAtMost, targetSize); return DoricMeasureSpecMake(DoricMeasureAtMost, targetSize);
default: default:
return DoricMeasureSpecMake(DoricMeasureExactly, size); return DoricMeasureSpecMake(DoricMeasureExactly, size);
@ -483,7 +486,12 @@ - (void)measureWidth:(DoricMeasureSpec)widthSpec height:(DoricMeasureSpec)height
break; break;
} }
} }
if (self.measuredWidth > self.maxWidth || self.measuredHeight > self.measuredHeight) {
[self measureWidth:DoricMeasureSpecMake(DoricMeasureAtMost,
MIN(self.measuredWidth, self.maxWidth))
height:DoricMeasureSpecMake(DoricMeasureAtMost,
MIN(self.measuredHeight, self.maxHeight))];
}
// self.measuredCache[measuredKey] = [NSString stringWithFormat:@"%@;%@", // self.measuredCache[measuredKey] = [NSString stringWithFormat:@"%@;%@",
// @(self.measuredWidth), // @(self.measuredWidth),
// @(self.measuredHeight)]; // @(self.measuredHeight)];
@ -994,7 +1002,7 @@ - (void)stackMeasureWidth:(DoricMeasureSpec)widthMeasureSpec
self.measuredState = (widthSizeAndState.state self.measuredState = (widthSizeAndState.state
<< DORIC_MEASURED_HEIGHT_STATE_SHIFT) | heightSizeAndState.state; << DORIC_MEASURED_HEIGHT_STATE_SHIFT) | heightSizeAndState.state;
if (matchParentChildren.count > 1) { if (matchParentChildren.count > 0) {
for (DoricLayout *child in matchParentChildren) { for (DoricLayout *child in matchParentChildren) {
DoricMeasureSpec childWidthMeasureSpec; DoricMeasureSpec childWidthMeasureSpec;
if (child.widthSpec == DoricLayoutMost) { if (child.widthSpec == DoricLayoutMost) {