mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -1,35 +1,24 @@
|
||||
import {
|
||||
WrapLayoutBase,
|
||||
orientationProperty,
|
||||
itemWidthProperty,
|
||||
itemHeightProperty,
|
||||
} from "./wrap-layout-common";
|
||||
import { Length } from "../../styling/style-properties";
|
||||
import { WrapLayoutBase, orientationProperty, itemWidthProperty, itemHeightProperty } from './wrap-layout-common';
|
||||
import { Length } from '../../styling/style-properties';
|
||||
|
||||
export * from "./wrap-layout-common";
|
||||
export * from './wrap-layout-common';
|
||||
|
||||
export class WrapLayout extends WrapLayoutBase {
|
||||
nativeViewProtected: org.nativescript.widgets.WrapLayout;
|
||||
nativeViewProtected: org.nativescript.widgets.WrapLayout;
|
||||
|
||||
public createNativeView() {
|
||||
return new org.nativescript.widgets.WrapLayout(this._context);
|
||||
}
|
||||
public createNativeView() {
|
||||
return new org.nativescript.widgets.WrapLayout(this._context);
|
||||
}
|
||||
|
||||
[orientationProperty.setNative](value: "horizontal" | "vertical") {
|
||||
this.nativeViewProtected.setOrientation(
|
||||
value === "vertical"
|
||||
? org.nativescript.widgets.Orientation.vertical
|
||||
: org.nativescript.widgets.Orientation.horizontal
|
||||
);
|
||||
}
|
||||
[orientationProperty.setNative](value: 'horizontal' | 'vertical') {
|
||||
this.nativeViewProtected.setOrientation(value === 'vertical' ? org.nativescript.widgets.Orientation.vertical : org.nativescript.widgets.Orientation.horizontal);
|
||||
}
|
||||
|
||||
[itemWidthProperty.setNative](value: Length) {
|
||||
this.nativeViewProtected.setItemWidth(Length.toDevicePixels(value, -1));
|
||||
}
|
||||
[itemWidthProperty.setNative](value: Length) {
|
||||
this.nativeViewProtected.setItemWidth(Length.toDevicePixels(value, -1));
|
||||
}
|
||||
|
||||
[itemHeightProperty.setNative](value: Length) {
|
||||
this.nativeViewProtected.setItemHeight(
|
||||
Length.toDevicePixels(value, -1)
|
||||
);
|
||||
}
|
||||
[itemHeightProperty.setNative](value: Length) {
|
||||
this.nativeViewProtected.setItemHeight(Length.toDevicePixels(value, -1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { LayoutBase } from "../layout-base";
|
||||
import { Length } from "../../styling/style-properties";
|
||||
import { Property } from "../../core/properties";
|
||||
import { LayoutBase } from '../layout-base';
|
||||
import { Length } from '../../styling/style-properties';
|
||||
import { Property } from '../../core/properties';
|
||||
|
||||
/**
|
||||
* WrapLayout position children in rows or columns depending on orientation property
|
||||
* until space is filled and then wraps them on new row or column.
|
||||
*/
|
||||
export class WrapLayout extends LayoutBase {
|
||||
/**
|
||||
* Gets or sets the flow direction. Default value is horizontal.
|
||||
* If orientation is horizontal items are arranged in rows, else items are arranged in columns.
|
||||
*/
|
||||
orientation: Orientation;
|
||||
/**
|
||||
* Gets or sets the flow direction. Default value is horizontal.
|
||||
* If orientation is horizontal items are arranged in rows, else items are arranged in columns.
|
||||
*/
|
||||
orientation: Orientation;
|
||||
|
||||
/**
|
||||
* Gets or sets the width used to measure and layout each child.
|
||||
* Default value is Number.NaN which does not restrict children.
|
||||
*/
|
||||
itemWidth: Length;
|
||||
/**
|
||||
* Gets or sets the width used to measure and layout each child.
|
||||
* Default value is Number.NaN which does not restrict children.
|
||||
*/
|
||||
itemWidth: Length;
|
||||
|
||||
/**
|
||||
* Gets or sets the height used to measure and layout each child.
|
||||
* Default value is Number.NaN which does not restrict children.
|
||||
*/
|
||||
itemHeight: Length;
|
||||
/**
|
||||
* Gets or sets the height used to measure and layout each child.
|
||||
* Default value is Number.NaN which does not restrict children.
|
||||
*/
|
||||
itemHeight: Length;
|
||||
}
|
||||
|
||||
export type Orientation = "horizontal" | "vertical";
|
||||
export type Orientation = 'horizontal' | 'vertical';
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the orientation property of each WrapLayout instance.
|
||||
|
||||
@@ -1,305 +1,195 @@
|
||||
import { WrapLayoutBase } from "./wrap-layout-common";
|
||||
import { View } from "../../core/view";
|
||||
import { layout } from "../../../utils/utils";
|
||||
import { WrapLayoutBase } from './wrap-layout-common';
|
||||
import { View } from '../../core/view';
|
||||
import { layout } from '../../../utils';
|
||||
|
||||
export * from "./wrap-layout-common";
|
||||
export * from './wrap-layout-common';
|
||||
|
||||
export class WrapLayout extends WrapLayoutBase {
|
||||
private _lengths: Array<number> = new Array<number>();
|
||||
private _lengths: Array<number> = new Array<number>();
|
||||
|
||||
private static getChildMeasureSpec(
|
||||
parentMode: number,
|
||||
parentLength: number,
|
||||
itemLength
|
||||
): number {
|
||||
if (itemLength > 0) {
|
||||
return layout.makeMeasureSpec(itemLength, layout.EXACTLY);
|
||||
} else if (parentMode === layout.UNSPECIFIED) {
|
||||
return layout.makeMeasureSpec(0, layout.UNSPECIFIED);
|
||||
} else {
|
||||
return layout.makeMeasureSpec(parentLength, layout.AT_MOST);
|
||||
}
|
||||
}
|
||||
private static getChildMeasureSpec(parentMode: number, parentLength: number, itemLength): number {
|
||||
if (itemLength > 0) {
|
||||
return layout.makeMeasureSpec(itemLength, layout.EXACTLY);
|
||||
} else if (parentMode === layout.UNSPECIFIED) {
|
||||
return layout.makeMeasureSpec(0, layout.UNSPECIFIED);
|
||||
} else {
|
||||
return layout.makeMeasureSpec(parentLength, layout.AT_MOST);
|
||||
}
|
||||
}
|
||||
|
||||
public onMeasure(
|
||||
widthMeasureSpec: number,
|
||||
heightMeasureSpec: number
|
||||
): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
let measureWidth = 0;
|
||||
let measureHeight = 0;
|
||||
let measureWidth = 0;
|
||||
let measureHeight = 0;
|
||||
|
||||
const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
||||
const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
||||
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
||||
|
||||
const height = layout.getMeasureSpecSize(heightMeasureSpec);
|
||||
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
|
||||
const height = layout.getMeasureSpecSize(heightMeasureSpec);
|
||||
const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
|
||||
|
||||
const horizontalPaddingsAndMargins =
|
||||
this.effectivePaddingLeft +
|
||||
this.effectivePaddingRight +
|
||||
this.effectiveBorderLeftWidth +
|
||||
this.effectiveBorderRightWidth;
|
||||
const verticalPaddingsAndMargins =
|
||||
this.effectivePaddingTop +
|
||||
this.effectivePaddingBottom +
|
||||
this.effectiveBorderTopWidth +
|
||||
this.effectiveBorderBottomWidth;
|
||||
const horizontalPaddingsAndMargins = this.effectivePaddingLeft + this.effectivePaddingRight + this.effectiveBorderLeftWidth + this.effectiveBorderRightWidth;
|
||||
const verticalPaddingsAndMargins = this.effectivePaddingTop + this.effectivePaddingBottom + this.effectiveBorderTopWidth + this.effectiveBorderBottomWidth;
|
||||
|
||||
const availableWidth =
|
||||
widthMode === layout.UNSPECIFIED
|
||||
? Number.MAX_VALUE
|
||||
: width - horizontalPaddingsAndMargins;
|
||||
const availableHeight =
|
||||
heightMode === layout.UNSPECIFIED
|
||||
? Number.MAX_VALUE
|
||||
: height - verticalPaddingsAndMargins;
|
||||
const availableWidth = widthMode === layout.UNSPECIFIED ? Number.MAX_VALUE : width - horizontalPaddingsAndMargins;
|
||||
const availableHeight = heightMode === layout.UNSPECIFIED ? Number.MAX_VALUE : height - verticalPaddingsAndMargins;
|
||||
|
||||
const childWidthMeasureSpec: number = WrapLayout.getChildMeasureSpec(
|
||||
widthMode,
|
||||
availableWidth,
|
||||
this.effectiveItemWidth
|
||||
);
|
||||
const childHeightMeasureSpec: number = WrapLayout.getChildMeasureSpec(
|
||||
heightMode,
|
||||
availableHeight,
|
||||
this.effectiveItemHeight
|
||||
);
|
||||
const childWidthMeasureSpec: number = WrapLayout.getChildMeasureSpec(widthMode, availableWidth, this.effectiveItemWidth);
|
||||
const childHeightMeasureSpec: number = WrapLayout.getChildMeasureSpec(heightMode, availableHeight, this.effectiveItemHeight);
|
||||
|
||||
let remainingWidth = availableWidth;
|
||||
let remainingHeight = availableHeight;
|
||||
let remainingWidth = availableWidth;
|
||||
let remainingHeight = availableHeight;
|
||||
|
||||
this._lengths.length = 0;
|
||||
let rowOrColumn = 0;
|
||||
let maxLength = 0;
|
||||
this._lengths.length = 0;
|
||||
let rowOrColumn = 0;
|
||||
let maxLength = 0;
|
||||
|
||||
const isVertical = this.orientation === "vertical";
|
||||
const isVertical = this.orientation === 'vertical';
|
||||
|
||||
let useItemWidth: boolean = this.effectiveItemWidth > 0;
|
||||
let useItemHeight: boolean = this.effectiveItemHeight > 0;
|
||||
let itemWidth = this.effectiveItemWidth;
|
||||
let itemHeight = this.effectiveItemHeight;
|
||||
let useItemWidth: boolean = this.effectiveItemWidth > 0;
|
||||
let useItemHeight: boolean = this.effectiveItemHeight > 0;
|
||||
let itemWidth = this.effectiveItemWidth;
|
||||
let itemHeight = this.effectiveItemHeight;
|
||||
|
||||
this.eachLayoutChild((child, last) => {
|
||||
const desiredSize = View.measureChild(
|
||||
this,
|
||||
child,
|
||||
childWidthMeasureSpec,
|
||||
childHeightMeasureSpec
|
||||
);
|
||||
let childMeasuredWidth = useItemWidth
|
||||
? itemWidth
|
||||
: desiredSize.measuredWidth;
|
||||
let childMeasuredHeight = useItemHeight
|
||||
? itemHeight
|
||||
: desiredSize.measuredHeight;
|
||||
let isFirst = this._lengths.length <= rowOrColumn;
|
||||
this.eachLayoutChild((child, last) => {
|
||||
const desiredSize = View.measureChild(this, child, childWidthMeasureSpec, childHeightMeasureSpec);
|
||||
let childMeasuredWidth = useItemWidth ? itemWidth : desiredSize.measuredWidth;
|
||||
let childMeasuredHeight = useItemHeight ? itemHeight : desiredSize.measuredHeight;
|
||||
let isFirst = this._lengths.length <= rowOrColumn;
|
||||
|
||||
if (isVertical) {
|
||||
if (childMeasuredHeight > remainingHeight) {
|
||||
rowOrColumn++;
|
||||
maxLength = Math.max(maxLength, measureHeight);
|
||||
measureHeight = childMeasuredHeight;
|
||||
remainingHeight = availableHeight - childMeasuredHeight;
|
||||
this._lengths[
|
||||
isFirst ? rowOrColumn - 1 : rowOrColumn
|
||||
] = childMeasuredWidth;
|
||||
} else {
|
||||
remainingHeight -= childMeasuredHeight;
|
||||
measureHeight += childMeasuredHeight;
|
||||
}
|
||||
} else {
|
||||
if (childMeasuredWidth > remainingWidth) {
|
||||
rowOrColumn++;
|
||||
maxLength = Math.max(maxLength, measureWidth);
|
||||
measureWidth = childMeasuredWidth;
|
||||
remainingWidth = availableWidth - childMeasuredWidth;
|
||||
this._lengths[
|
||||
isFirst ? rowOrColumn - 1 : rowOrColumn
|
||||
] = childMeasuredHeight;
|
||||
} else {
|
||||
remainingWidth -= childMeasuredWidth;
|
||||
measureWidth += childMeasuredWidth;
|
||||
}
|
||||
}
|
||||
if (isVertical) {
|
||||
if (childMeasuredHeight > remainingHeight) {
|
||||
rowOrColumn++;
|
||||
maxLength = Math.max(maxLength, measureHeight);
|
||||
measureHeight = childMeasuredHeight;
|
||||
remainingHeight = availableHeight - childMeasuredHeight;
|
||||
this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn] = childMeasuredWidth;
|
||||
} else {
|
||||
remainingHeight -= childMeasuredHeight;
|
||||
measureHeight += childMeasuredHeight;
|
||||
}
|
||||
} else {
|
||||
if (childMeasuredWidth > remainingWidth) {
|
||||
rowOrColumn++;
|
||||
maxLength = Math.max(maxLength, measureWidth);
|
||||
measureWidth = childMeasuredWidth;
|
||||
remainingWidth = availableWidth - childMeasuredWidth;
|
||||
this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn] = childMeasuredHeight;
|
||||
} else {
|
||||
remainingWidth -= childMeasuredWidth;
|
||||
measureWidth += childMeasuredWidth;
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
this._lengths[rowOrColumn] = isVertical
|
||||
? childMeasuredWidth
|
||||
: childMeasuredHeight;
|
||||
} else {
|
||||
this._lengths[rowOrColumn] = Math.max(
|
||||
this._lengths[rowOrColumn],
|
||||
isVertical ? childMeasuredWidth : childMeasuredHeight
|
||||
);
|
||||
}
|
||||
});
|
||||
if (isFirst) {
|
||||
this._lengths[rowOrColumn] = isVertical ? childMeasuredWidth : childMeasuredHeight;
|
||||
} else {
|
||||
this._lengths[rowOrColumn] = Math.max(this._lengths[rowOrColumn], isVertical ? childMeasuredWidth : childMeasuredHeight);
|
||||
}
|
||||
});
|
||||
|
||||
if (isVertical) {
|
||||
measureHeight = Math.max(maxLength, measureHeight);
|
||||
this._lengths.forEach((value, index, array) => {
|
||||
measureWidth += value;
|
||||
});
|
||||
} else {
|
||||
measureWidth = Math.max(maxLength, measureWidth);
|
||||
this._lengths.forEach((value, index, array) => {
|
||||
measureHeight += value;
|
||||
});
|
||||
}
|
||||
if (isVertical) {
|
||||
measureHeight = Math.max(maxLength, measureHeight);
|
||||
this._lengths.forEach((value, index, array) => {
|
||||
measureWidth += value;
|
||||
});
|
||||
} else {
|
||||
measureWidth = Math.max(maxLength, measureWidth);
|
||||
this._lengths.forEach((value, index, array) => {
|
||||
measureHeight += value;
|
||||
});
|
||||
}
|
||||
|
||||
measureWidth += horizontalPaddingsAndMargins;
|
||||
measureHeight += verticalPaddingsAndMargins;
|
||||
measureWidth += horizontalPaddingsAndMargins;
|
||||
measureHeight += verticalPaddingsAndMargins;
|
||||
|
||||
// Check against our minimum sizes
|
||||
measureWidth = Math.max(measureWidth, this.effectiveMinWidth);
|
||||
measureHeight = Math.max(measureHeight, this.effectiveMinHeight);
|
||||
// Check against our minimum sizes
|
||||
measureWidth = Math.max(measureWidth, this.effectiveMinWidth);
|
||||
measureHeight = Math.max(measureHeight, this.effectiveMinHeight);
|
||||
|
||||
const widthAndState = View.resolveSizeAndState(
|
||||
measureWidth,
|
||||
width,
|
||||
widthMode,
|
||||
0
|
||||
);
|
||||
const heightAndState = View.resolveSizeAndState(
|
||||
measureHeight,
|
||||
height,
|
||||
heightMode,
|
||||
0
|
||||
);
|
||||
const widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
||||
const heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||
|
||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||
}
|
||||
this.setMeasuredDimension(widthAndState, heightAndState);
|
||||
}
|
||||
|
||||
public onLayout(
|
||||
left: number,
|
||||
top: number,
|
||||
right: number,
|
||||
bottom: number
|
||||
): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||
super.onLayout(left, top, right, bottom);
|
||||
|
||||
const insets = this.getSafeAreaInsets();
|
||||
const isVertical = this.orientation === "vertical";
|
||||
const paddingLeft =
|
||||
this.effectiveBorderLeftWidth +
|
||||
this.effectivePaddingLeft +
|
||||
insets.left;
|
||||
const paddingTop =
|
||||
this.effectiveBorderTopWidth +
|
||||
this.effectivePaddingTop +
|
||||
insets.top;
|
||||
const paddingRight =
|
||||
this.effectiveBorderRightWidth +
|
||||
this.effectivePaddingRight +
|
||||
insets.right;
|
||||
const paddingBottom =
|
||||
this.effectiveBorderBottomWidth +
|
||||
this.effectivePaddingBottom +
|
||||
insets.bottom;
|
||||
const insets = this.getSafeAreaInsets();
|
||||
const isVertical = this.orientation === 'vertical';
|
||||
const paddingLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left;
|
||||
const paddingTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top;
|
||||
const paddingRight = this.effectiveBorderRightWidth + this.effectivePaddingRight + insets.right;
|
||||
const paddingBottom = this.effectiveBorderBottomWidth + this.effectivePaddingBottom + insets.bottom;
|
||||
|
||||
let childLeft = paddingLeft;
|
||||
let childTop = paddingTop;
|
||||
let childrenHeight = bottom - top - paddingBottom;
|
||||
let childrenWidth = right - left - paddingRight;
|
||||
let rowOrColumn = 0;
|
||||
let childLeft = paddingLeft;
|
||||
let childTop = paddingTop;
|
||||
let childrenHeight = bottom - top - paddingBottom;
|
||||
let childrenWidth = right - left - paddingRight;
|
||||
let rowOrColumn = 0;
|
||||
|
||||
this.eachLayoutChild((child, last) => {
|
||||
// Add margins because layoutChild will sustract them.
|
||||
// * density converts them to device pixels.
|
||||
let childHeight =
|
||||
child.getMeasuredHeight() +
|
||||
child.effectiveMarginTop +
|
||||
child.effectiveMarginBottom;
|
||||
let childWidth =
|
||||
child.getMeasuredWidth() +
|
||||
child.effectiveMarginLeft +
|
||||
child.effectiveMarginRight;
|
||||
this.eachLayoutChild((child, last) => {
|
||||
// Add margins because layoutChild will sustract them.
|
||||
// * density converts them to device pixels.
|
||||
let childHeight = child.getMeasuredHeight() + child.effectiveMarginTop + child.effectiveMarginBottom;
|
||||
let childWidth = child.getMeasuredWidth() + child.effectiveMarginLeft + child.effectiveMarginRight;
|
||||
|
||||
let length = this._lengths[rowOrColumn];
|
||||
if (isVertical) {
|
||||
childWidth = length;
|
||||
childHeight =
|
||||
this.effectiveItemHeight > 0
|
||||
? this.effectiveItemHeight
|
||||
: childHeight;
|
||||
let isFirst = childTop === paddingTop;
|
||||
if (
|
||||
childTop + childHeight > childrenHeight &&
|
||||
childLeft + childWidth <= childrenWidth
|
||||
) {
|
||||
// Move to top.
|
||||
childTop = paddingTop;
|
||||
let length = this._lengths[rowOrColumn];
|
||||
if (isVertical) {
|
||||
childWidth = length;
|
||||
childHeight = this.effectiveItemHeight > 0 ? this.effectiveItemHeight : childHeight;
|
||||
let isFirst = childTop === paddingTop;
|
||||
if (childTop + childHeight > childrenHeight && childLeft + childWidth <= childrenWidth) {
|
||||
// Move to top.
|
||||
childTop = paddingTop;
|
||||
|
||||
if (!isFirst) {
|
||||
// Move to right with current column width.
|
||||
childLeft += length;
|
||||
}
|
||||
if (!isFirst) {
|
||||
// Move to right with current column width.
|
||||
childLeft += length;
|
||||
}
|
||||
|
||||
// Move to next column.
|
||||
rowOrColumn++;
|
||||
// Move to next column.
|
||||
rowOrColumn++;
|
||||
|
||||
// Take respective column width.
|
||||
childWidth = this._lengths[
|
||||
isFirst ? rowOrColumn - 1 : rowOrColumn
|
||||
];
|
||||
}
|
||||
// Take respective column width.
|
||||
childWidth = this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
|
||||
}
|
||||
|
||||
if (childLeft < childrenWidth && childTop < childrenHeight) {
|
||||
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);
|
||||
}
|
||||
|
||||
// Move next child Top position to bottom.
|
||||
childTop += childHeight;
|
||||
} else {
|
||||
childWidth =
|
||||
this.effectiveItemWidth > 0
|
||||
? this.effectiveItemWidth
|
||||
: childWidth;
|
||||
childHeight = length;
|
||||
let isFirst = childLeft === paddingLeft;
|
||||
if (
|
||||
childLeft + childWidth > childrenWidth &&
|
||||
childTop + childHeight <= childrenHeight
|
||||
) {
|
||||
// Move to left.
|
||||
childLeft = paddingLeft;
|
||||
// Move next child Top position to bottom.
|
||||
childTop += childHeight;
|
||||
} else {
|
||||
childWidth = this.effectiveItemWidth > 0 ? this.effectiveItemWidth : childWidth;
|
||||
childHeight = length;
|
||||
let isFirst = childLeft === paddingLeft;
|
||||
if (childLeft + childWidth > childrenWidth && childTop + childHeight <= childrenHeight) {
|
||||
// Move to left.
|
||||
childLeft = paddingLeft;
|
||||
|
||||
if (!isFirst) {
|
||||
// Move to bottom with current row height.
|
||||
childTop += length;
|
||||
}
|
||||
if (!isFirst) {
|
||||
// Move to bottom with current row height.
|
||||
childTop += length;
|
||||
}
|
||||
|
||||
// Move to next row.
|
||||
rowOrColumn++;
|
||||
// Move to next row.
|
||||
rowOrColumn++;
|
||||
|
||||
// Take respective row height.
|
||||
childHeight = this._lengths[
|
||||
isFirst ? rowOrColumn - 1 : rowOrColumn
|
||||
];
|
||||
}
|
||||
// Take respective row height.
|
||||
childHeight = this._lengths[isFirst ? rowOrColumn - 1 : rowOrColumn];
|
||||
}
|
||||
|
||||
if (childLeft < childrenWidth && childTop < childrenHeight) {
|
||||
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);
|
||||
}
|
||||
|
||||
// Move next child Left position to right.
|
||||
childLeft += childWidth;
|
||||
}
|
||||
});
|
||||
}
|
||||
// Move next child Left position to right.
|
||||
childLeft += childWidth;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,46 @@
|
||||
import { WrapLayout as WrapLayoutDefinition, Orientation } from ".";
|
||||
import { LayoutBase } from "../layout-base";
|
||||
import { CSSType } from "../../core/view";
|
||||
import { Property, makeValidator, makeParser } from "../../core/properties";
|
||||
import { Length } from "../../styling/style-properties";
|
||||
import { isIOS } from "../../../platform";
|
||||
import { WrapLayout as WrapLayoutDefinition, Orientation } from '.';
|
||||
import { LayoutBase } from '../layout-base';
|
||||
import { CSSType } from '../../core/view';
|
||||
import { Property, makeValidator, makeParser } from '../../core/properties';
|
||||
import { Length } from '../../styling/style-properties';
|
||||
import { isIOS } from '../../../platform';
|
||||
|
||||
export * from "../layout-base";
|
||||
export * from '../layout-base';
|
||||
|
||||
@CSSType("WrapLayout")
|
||||
@CSSType('WrapLayout')
|
||||
export class WrapLayoutBase extends LayoutBase implements WrapLayoutDefinition {
|
||||
public orientation: Orientation;
|
||||
public itemWidth: Length;
|
||||
public itemHeight: Length;
|
||||
public effectiveItemWidth: number;
|
||||
public effectiveItemHeight: number;
|
||||
public orientation: Orientation;
|
||||
public itemWidth: Length;
|
||||
public itemHeight: Length;
|
||||
public effectiveItemWidth: number;
|
||||
public effectiveItemHeight: number;
|
||||
}
|
||||
|
||||
WrapLayoutBase.prototype.recycleNativeView = "auto";
|
||||
WrapLayoutBase.prototype.recycleNativeView = 'auto';
|
||||
|
||||
export const itemWidthProperty = new Property<WrapLayoutBase, Length>({
|
||||
name: "itemWidth",
|
||||
defaultValue: "auto",
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: (v) => Length.parse(v),
|
||||
valueChanged: (target, oldValue, newValue) =>
|
||||
(target.effectiveItemWidth = Length.toDevicePixels(newValue, -1)),
|
||||
name: 'itemWidth',
|
||||
defaultValue: 'auto',
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: (v) => Length.parse(v),
|
||||
valueChanged: (target, oldValue, newValue) => (target.effectiveItemWidth = Length.toDevicePixels(newValue, -1)),
|
||||
});
|
||||
itemWidthProperty.register(WrapLayoutBase);
|
||||
|
||||
export const itemHeightProperty = new Property<WrapLayoutBase, Length>({
|
||||
name: "itemHeight",
|
||||
defaultValue: "auto",
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: (v) => Length.parse(v),
|
||||
valueChanged: (target, oldValue, newValue) =>
|
||||
(target.effectiveItemHeight = Length.toDevicePixels(newValue, -1)),
|
||||
name: 'itemHeight',
|
||||
defaultValue: 'auto',
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: (v) => Length.parse(v),
|
||||
valueChanged: (target, oldValue, newValue) => (target.effectiveItemHeight = Length.toDevicePixels(newValue, -1)),
|
||||
});
|
||||
itemHeightProperty.register(WrapLayoutBase);
|
||||
|
||||
const converter = makeParser<Orientation>(
|
||||
makeValidator<Orientation>("horizontal", "vertical")
|
||||
);
|
||||
const converter = makeParser<Orientation>(makeValidator<Orientation>('horizontal', 'vertical'));
|
||||
export const orientationProperty = new Property<WrapLayoutBase, Orientation>({
|
||||
name: "orientation",
|
||||
defaultValue: "horizontal",
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: converter,
|
||||
name: 'orientation',
|
||||
defaultValue: 'horizontal',
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: converter,
|
||||
});
|
||||
orientationProperty.register(WrapLayoutBase);
|
||||
|
||||
Reference in New Issue
Block a user