mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
refactor: wrap layout safe area support
This commit is contained in:
committed by
Martin Yankov
parent
3414f3660e
commit
2a9d1acb6f
@@ -119,7 +119,7 @@ export class WrapLayout extends WrapLayoutBase {
|
|||||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onLayout(left: number, top: number, right: number, bottom: number, insets: {left, top, right, bottom}): void {
|
public onLayout(left: number, top: number, right: number, bottom: number, insets: { left, top, right, bottom }): void {
|
||||||
super.onLayout(left, top, right, bottom);
|
super.onLayout(left, top, right, bottom);
|
||||||
|
|
||||||
const isVertical = this.orientation === "vertical";
|
const isVertical = this.orientation === "vertical";
|
||||||
@@ -130,12 +130,15 @@ export class WrapLayout extends WrapLayoutBase {
|
|||||||
|
|
||||||
let childLeft = paddingLeft;
|
let childLeft = paddingLeft;
|
||||||
let childTop = paddingTop;
|
let childTop = paddingTop;
|
||||||
let childrenLength: number;
|
|
||||||
|
let childrenWidth: number;
|
||||||
|
let childrenHeight: number;
|
||||||
if (isVertical) {
|
if (isVertical) {
|
||||||
childrenLength = bottom - top - paddingBottom;
|
childrenHeight = right - left - paddingRight;
|
||||||
}
|
childrenWidth = bottom - top - paddingBottom;
|
||||||
else {
|
} else {
|
||||||
childrenLength = right - left - paddingRight;
|
childrenHeight = bottom - top - paddingBottom;
|
||||||
|
childrenWidth = right - left - paddingRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rowOrColumn = 0;
|
var rowOrColumn = 0;
|
||||||
@@ -150,7 +153,7 @@ export class WrapLayout extends WrapLayoutBase {
|
|||||||
childWidth = length;
|
childWidth = length;
|
||||||
childHeight = this.effectiveItemHeight > 0 ? this.effectiveItemHeight : childHeight;
|
childHeight = this.effectiveItemHeight > 0 ? this.effectiveItemHeight : childHeight;
|
||||||
let isFirst = childTop === paddingTop;
|
let isFirst = childTop === paddingTop;
|
||||||
if (childTop + childHeight > childrenLength) {
|
if (childTop + childHeight > childrenWidth && childLeft + childWidth <= childrenHeight) {
|
||||||
// Move to top.
|
// Move to top.
|
||||||
childTop = paddingTop;
|
childTop = paddingTop;
|
||||||
|
|
||||||
@@ -165,12 +168,19 @@ export class WrapLayout extends WrapLayoutBase {
|
|||||||
// Take respective column width.
|
// Take respective column width.
|
||||||
childWidth = this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
|
childWidth = this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
if (childLeft < childrenHeight && childTop < childrenWidth) {
|
||||||
|
View.layoutChild(this, child, childLeft, childTop, childLeft + childWidth, childTop + childHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move next child Left position to right.
|
||||||
|
childTop += childHeight;
|
||||||
|
} else {
|
||||||
childWidth = this.effectiveItemWidth > 0 ? this.effectiveItemWidth : childWidth;
|
childWidth = this.effectiveItemWidth > 0 ? this.effectiveItemWidth : childWidth;
|
||||||
childHeight = length;
|
childHeight = length;
|
||||||
let isFirst = childLeft === paddingLeft;
|
let isFirst = childLeft === paddingLeft;
|
||||||
if (childLeft + childWidth > childrenLength) {
|
|
||||||
|
if (childLeft + childWidth > childrenWidth && childTop + childHeight <= childrenHeight) {
|
||||||
// Move to left.
|
// Move to left.
|
||||||
childLeft = paddingLeft;
|
childLeft = paddingLeft;
|
||||||
|
|
||||||
@@ -185,15 +195,11 @@ export class WrapLayout extends WrapLayoutBase {
|
|||||||
// Take respective row height.
|
// Take respective row height.
|
||||||
childHeight = this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
|
childHeight = this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
View.layoutChild(this, child, childLeft, childTop, childLeft + childWidth, childTop + childHeight);
|
if (childLeft < childrenWidth && childTop < childrenHeight) {
|
||||||
|
View.layoutChild(this, child, childLeft, childTop, childLeft + childWidth, childTop + childHeight);
|
||||||
|
}
|
||||||
|
|
||||||
if (isVertical) {
|
|
||||||
// Move next child Top position to bottom.
|
|
||||||
childTop += childHeight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Move next child Left position to right.
|
// Move next child Left position to right.
|
||||||
childLeft += childWidth;
|
childLeft += childWidth;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user