Skip to content

Commit 3cdbd68

Browse files
author
fbchen
committed
optimize seld wrapContent calculate
1 parent 5debaf2 commit 3cdbd68

File tree

1 file changed

+27
-55
lines changed

1 file changed

+27
-55
lines changed

lib/src/constraint_layout.dart

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,10 +2476,8 @@ class _ConstraintRenderBox extends RenderBox
24762476
resolvedHeight == wrapContent
24772477
? constraints.minHeight
24782478
: resolvedHeight);
2479-
double contentLeft = double.infinity;
2480-
double contentTop = double.infinity;
2481-
double contentRight = -double.infinity;
2482-
double contentBottom = -double.infinity;
2479+
double contentWidth = -double.infinity;
2480+
double contentHeight = -double.infinity;
24832481
for (int j = 0; j < i; j++) {
24842482
_ConstrainedNode sizeConfirmedChild = _layoutOrderList[j];
24852483

@@ -2509,69 +2507,43 @@ class _ConstraintRenderBox extends RenderBox
25092507

25102508
sizeConfirmedChild.offset =
25112509
calculateChildOffset(sizeConfirmedChild);
2512-
EdgeInsets margin = sizeConfirmedChild.margin;
2513-
EdgeInsets goneMargin = sizeConfirmedChild.goneMargin;
2514-
double childLeft = max(sizeConfirmedChild.getX(), 0);
2515-
double childTop = max(sizeConfirmedChild.getY(), 0);
2516-
double childRight =
2517-
childLeft + sizeConfirmedChild.getMeasuredWidth();
2518-
double childBottom =
2519-
childTop + sizeConfirmedChild.getMeasuredHeight();
2520-
2521-
if (element.leftConstraint != null) {
2522-
if (element.leftConstraint!.notLaidOut) {
2523-
childLeft -= _getLeftInsets(goneMargin);
2524-
} else {
2525-
childLeft -= _getLeftInsets(margin);
2526-
}
2527-
}
2528-
2529-
if (element.topConstraint != null) {
2530-
if (element.topConstraint!.notLaidOut) {
2531-
childTop -= _getTopInsets(goneMargin);
2532-
} else {
2533-
childTop -= _getTopInsets(margin);
2534-
}
2535-
}
2536-
2537-
if (element.rightConstraint != null) {
2538-
if (element.rightConstraint!.notLaidOut) {
2539-
childRight += _getRightInsets(goneMargin);
2540-
} else {
2541-
childRight += _getRightInsets(margin);
2542-
}
2543-
}
2544-
2545-
if (element.bottomConstraint != null) {
2546-
if (element.bottomConstraint!.notLaidOut) {
2547-
childBottom += _getBottomInsets(goneMargin);
2548-
} else {
2549-
childBottom += _getBottomInsets(margin);
2550-
}
2551-
}
2552-
2553-
if (childLeft < contentLeft) {
2554-
contentLeft = childLeft;
2510+
double childSpanWidth = sizeConfirmedChild.getMeasuredWidth();
2511+
double childSpanHeight = sizeConfirmedChild.getMeasuredHeight();
2512+
2513+
if (sizeConfirmedChild.leftConstraint != null &&
2514+
sizeConfirmedChild.rightConstraint != null) {
2515+
} else if (sizeConfirmedChild.leftConstraint != null) {
2516+
childSpanWidth += sizeConfirmedChild.getX();
2517+
} else if (sizeConfirmedChild.rightConstraint != null) {
2518+
childSpanWidth += size.width - sizeConfirmedChild.getRight();
2519+
} else {
2520+
/// It is not possible to execute this branch
25552521
}
25562522

2557-
if (childTop < contentTop) {
2558-
contentTop = childTop;
2523+
if (sizeConfirmedChild.topConstraint != null &&
2524+
sizeConfirmedChild.bottomConstraint != null) {
2525+
} else if (sizeConfirmedChild.topConstraint != null) {
2526+
childSpanHeight += sizeConfirmedChild.getY();
2527+
} else if (sizeConfirmedChild.bottomConstraint != null) {
2528+
childSpanHeight += size.height - sizeConfirmedChild.getBottom();
2529+
} else {
2530+
/// It is not possible to execute this branch
25592531
}
25602532

2561-
if (childRight > contentRight) {
2562-
contentRight = childRight;
2533+
if (childSpanWidth > contentWidth) {
2534+
contentWidth = childSpanWidth;
25632535
}
25642536

2565-
if (childBottom > contentBottom) {
2566-
contentBottom = childBottom;
2537+
if (childSpanHeight > contentHeight) {
2538+
contentHeight = childSpanHeight;
25672539
}
25682540
}
25692541
size = Size(
25702542
resolvedWidth == wrapContent
2571-
? constraints.constrainWidth(contentRight - contentLeft)
2543+
? constraints.constrainWidth(contentWidth)
25722544
: resolvedWidth,
25732545
resolvedHeight == wrapContent
2574-
? constraints.constrainHeight(contentBottom - contentTop)
2546+
? constraints.constrainHeight(contentHeight)
25752547
: resolvedHeight);
25762548
for (int j = 0; j < i; j++) {
25772549
_ConstrainedNode sizeConfirmedChild = _layoutOrderList[j];

0 commit comments

Comments
 (0)