mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Shrink will not damage the last item when it is shrink=0
This commit is contained in:
@ -600,54 +600,32 @@ export class FlexboxLayout extends FlexboxLayoutBase {
|
|||||||
if (this._isMainAxisDirectionHorizontal(flexDirection)) {
|
if (this._isMainAxisDirectionHorizontal(flexDirection)) {
|
||||||
// The direction of main axis is horizontal
|
// The direction of main axis is horizontal
|
||||||
if (!this._childrenFrozen[childIndex]) {
|
if (!this._childrenFrozen[childIndex]) {
|
||||||
let rawCalculatedWidth = child.getMeasuredWidth() - unitShrink * lp.flexShrink;
|
let rawCalculatedWidth = child.getMeasuredWidth() - unitShrink * lp.flexShrink + accumulatedRoundError;
|
||||||
if (i === flexLine.itemCount - 1) {
|
let roundedCalculatedWidth = Math.round(rawCalculatedWidth);
|
||||||
rawCalculatedWidth += accumulatedRoundError;
|
if (roundedCalculatedWidth < lp.minWidth) {
|
||||||
accumulatedRoundError = 0;
|
|
||||||
}
|
|
||||||
let newWidth = Math.round(rawCalculatedWidth);
|
|
||||||
if (newWidth < lp.minWidth) {
|
|
||||||
needsReshrink = true;
|
needsReshrink = true;
|
||||||
newWidth = lp.minWidth;
|
roundedCalculatedWidth = lp.minWidth;
|
||||||
this._childrenFrozen[childIndex] = true;
|
this._childrenFrozen[childIndex] = true;
|
||||||
flexLine._totalFlexShrink -= lp.flexShrink;
|
flexLine._totalFlexShrink -= lp.flexShrink;
|
||||||
} else {
|
} else {
|
||||||
accumulatedRoundError += (rawCalculatedWidth - newWidth);
|
accumulatedRoundError = rawCalculatedWidth - roundedCalculatedWidth;
|
||||||
if (accumulatedRoundError > 1.0) {
|
|
||||||
newWidth += 1;
|
|
||||||
accumulatedRoundError -= 1;
|
|
||||||
} else if (accumulatedRoundError < -1.0) {
|
|
||||||
newWidth -= 1;
|
|
||||||
accumulatedRoundError += 1;
|
|
||||||
}
|
}
|
||||||
}
|
child.measure(makeMeasureSpec(roundedCalculatedWidth, EXACTLY), makeMeasureSpec(child.getMeasuredHeight(), EXACTLY));
|
||||||
child.measure(makeMeasureSpec(newWidth, EXACTLY), makeMeasureSpec(child.getMeasuredHeight(), EXACTLY));
|
|
||||||
}
|
}
|
||||||
flexLine._mainSize += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
|
flexLine._mainSize += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
|
||||||
} else {
|
} else {
|
||||||
if (!this._childrenFrozen[childIndex]) {
|
if (!this._childrenFrozen[childIndex]) {
|
||||||
let rawCalculatedHeight = child.getMeasuredHeight() - unitShrink * lp.flexShrink;
|
let rawCalculatedHeight = child.getMeasuredHeight() - unitShrink * lp.flexShrink + accumulatedRoundError;
|
||||||
if (i === flexLine.itemCount - 1) {
|
let roundedCalculatedHeight = Math.round(rawCalculatedHeight);
|
||||||
rawCalculatedHeight += accumulatedRoundError;
|
if (roundedCalculatedHeight < lp.minHeight) {
|
||||||
accumulatedRoundError = 0;
|
|
||||||
}
|
|
||||||
let newHeight = Math.round(rawCalculatedHeight);
|
|
||||||
if (newHeight < lp.minHeight) {
|
|
||||||
needsReshrink = true;
|
needsReshrink = true;
|
||||||
newHeight = lp.minHeight;
|
roundedCalculatedHeight = lp.minHeight;
|
||||||
this._childrenFrozen[childIndex] = true;
|
this._childrenFrozen[childIndex] = true;
|
||||||
flexLine._totalFlexShrink -= lp.flexShrink;
|
flexLine._totalFlexShrink -= lp.flexShrink;
|
||||||
} else {
|
} else {
|
||||||
accumulatedRoundError += (rawCalculatedHeight - newHeight);
|
accumulatedRoundError = rawCalculatedHeight - roundedCalculatedHeight;
|
||||||
if (accumulatedRoundError > 1.0) {
|
|
||||||
newHeight += 1;
|
|
||||||
accumulatedRoundError -= 1;
|
|
||||||
} else if (accumulatedRoundError < -1.0) {
|
|
||||||
newHeight -= 1;
|
|
||||||
accumulatedRoundError += 1;
|
|
||||||
}
|
}
|
||||||
}
|
child.measure(makeMeasureSpec(child.getMeasuredWidth(), EXACTLY), makeMeasureSpec(roundedCalculatedHeight, EXACTLY));
|
||||||
child.measure(makeMeasureSpec(child.getMeasuredWidth(), EXACTLY), makeMeasureSpec(newHeight, EXACTLY));
|
|
||||||
}
|
}
|
||||||
flexLine._mainSize += child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
|
flexLine._mainSize += child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user