Merge pull request #14 from NativeScript/issue-1232

Fixed Issue #1232: WrapLayout crashes when itemWidth value is too high.
This commit is contained in:
Rossen Hristov
2016-02-05 16:20:01 +02:00

View File

@@ -112,14 +112,15 @@ public class WrapLayout extends LayoutBase {
CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec); CommonLayoutParams.measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec);
final int childMeasuredWidth = this.getDesiredWidth(child); final int childMeasuredWidth = this.getDesiredWidth(child);
final int childMeasuredHeight = this.getDesiredHeight(child); final int childMeasuredHeight = this.getDesiredHeight(child);
final boolean isFirst = this._lengths.size() <= rowOrColumn;
if (isVertical) { if (isVertical) {
if (childMeasuredHeight > remainingHeight) { if (childMeasuredHeight > remainingHeight) {
rowOrColumn++; rowOrColumn++;
maxLength = Math.max(maxLength, measureHeight); maxLength = Math.max(maxLength, measureHeight);
measureHeight = childMeasuredHeight; measureHeight = childMeasuredHeight;
remainingWidth = availableHeight - childMeasuredHeight; remainingHeight = availableHeight - childMeasuredHeight;
this._lengths.add(rowOrColumn, childMeasuredWidth); this._lengths.add(isFirst ? rowOrColumn - 1 : rowOrColumn, childMeasuredWidth);
} }
else { else {
remainingHeight -= childMeasuredHeight; remainingHeight -= childMeasuredHeight;
@@ -132,7 +133,7 @@ public class WrapLayout extends LayoutBase {
maxLength = Math.max(maxLength, measureWidth); maxLength = Math.max(maxLength, measureWidth);
measureWidth = childMeasuredWidth; measureWidth = childMeasuredWidth;
remainingWidth = availableWidth - childMeasuredWidth; remainingWidth = availableWidth - childMeasuredWidth;
this._lengths.add(rowOrColumn, childMeasuredHeight); this._lengths.add(isFirst ? rowOrColumn - 1 : rowOrColumn, childMeasuredHeight);
} }
else { else {
remainingWidth -= childMeasuredWidth; remainingWidth -= childMeasuredWidth;
@@ -140,7 +141,7 @@ public class WrapLayout extends LayoutBase {
} }
} }
if(this._lengths.size() <= rowOrColumn) { if(isFirst) {
this._lengths.add(rowOrColumn, isVertical ? childMeasuredWidth : childMeasuredHeight); this._lengths.add(rowOrColumn, isVertical ? childMeasuredWidth : childMeasuredHeight);
} }
else { else {
@@ -200,34 +201,40 @@ public class WrapLayout extends LayoutBase {
int length = this._lengths.get(rowOrColumn); int length = this._lengths.get(rowOrColumn);
if (isVertical) { if (isVertical) {
childWidth = length; childWidth = length;
final boolean isFirst = childTop == paddingTop;
if (childTop + childHeight > childrenLength) { if (childTop + childHeight > childrenLength) {
// Move to top. // Move to top.
childTop = paddingTop; childTop = paddingTop;
// Move to right with current column width. if (!isFirst){
childLeft += length; // Move to right with current column width.
childLeft += length;
}
// Move to next column. // Move to next column.
rowOrColumn++; rowOrColumn++;
// Take current column width. // Take respective column width.
childWidth = length = this._lengths.get(rowOrColumn); childWidth = this._lengths.get(isFirst ? rowOrColumn - 1 : rowOrColumn);
} }
} }
else { else {
childHeight = length; childHeight = length;
final boolean isFirst = childLeft == paddingLeft;
if (childLeft + childWidth > childrenLength) { if (childLeft + childWidth > childrenLength) {
// Move to left. // Move to left.
childLeft = paddingLeft; childLeft = paddingLeft;
// Move to bottom with current row height. if (!isFirst) {
childTop += length; // Move to bottom with current row height.
childTop += length;
}
// Move to next column. // Move to next row.
rowOrColumn++; rowOrColumn++;
// Take current row height. // Take respective row height.
childHeight = length = this._lengths.get(rowOrColumn); childHeight = this._lengths.get(isFirst ? rowOrColumn - 1 : rowOrColumn);
} }
} }