chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -3,52 +3,59 @@ import { LayoutBase } from "../layout-base";
import { View, CSSType } from "../../core/view";
import { Property, makeValidator, makeParser } from "../../core/properties";
import { booleanConverter } from "../../core/view-base";
import { isIOS } from "../../../platform";
import { isIOS } from "../../../platform";
function validateArgs(element: View): View {
if (!element) {
throw new Error("element cannot be null or undefinied.");
}
if (!element) {
throw new Error("element cannot be null or undefinied.");
}
return element;
return element;
}
export * from "../layout-base";
@CSSType("DockLayout")
export class DockLayoutBase extends LayoutBase implements DockLayoutDefinition {
public static getDock(element: View): Dock {
return validateArgs(element).dock;
}
public static getDock(element: View): Dock {
return validateArgs(element).dock;
}
public static setDock(element: View, value: Dock): void {
validateArgs(element).dock = value;
}
public static setDock(element: View, value: Dock): void {
validateArgs(element).dock = value;
}
public stretchLastChild: boolean;
public stretchLastChild: boolean;
public onDockChanged(view: View, oldValue: Dock, newValue: Dock) {
//
}
public onDockChanged(view: View, oldValue: Dock, newValue: Dock) {
//
}
}
DockLayoutBase.prototype.recycleNativeView = "auto";
const dockConverter = makeParser<Dock>(makeValidator<Dock>("left", "top", "right", "bottom"));
const dockConverter = makeParser<Dock>(
makeValidator<Dock>("left", "top", "right", "bottom")
);
export const dockProperty = new Property<View, Dock>({
name: "dock", defaultValue: "left", valueChanged: (target, oldValue, newValue) => {
if (target instanceof View) {
const layout = target.parent;
if (layout instanceof DockLayoutBase) {
layout.onDockChanged(target, oldValue, newValue);
}
}
}, valueConverter: dockConverter
name: "dock",
defaultValue: "left",
valueChanged: (target, oldValue, newValue) => {
if (target instanceof View) {
const layout = target.parent;
if (layout instanceof DockLayoutBase) {
layout.onDockChanged(target, oldValue, newValue);
}
}
},
valueConverter: dockConverter,
});
dockProperty.register(View);
export const stretchLastChildProperty = new Property<DockLayoutBase, boolean>({
name: "stretchLastChild", defaultValue: true, affectsLayout: isIOS, valueConverter: booleanConverter
name: "stretchLastChild",
defaultValue: true,
affectsLayout: isIOS,
valueConverter: booleanConverter,
});
stretchLastChildProperty.register(DockLayoutBase);

View File

@@ -1,48 +1,57 @@
import { DockLayoutBase, dockProperty, stretchLastChildProperty } from "./dock-layout-common";
import {
DockLayoutBase,
dockProperty,
stretchLastChildProperty,
} from "./dock-layout-common";
import { View } from "../../core/view";
export * from "./dock-layout-common";
View.prototype[dockProperty.setNative] = function (this: View, value: "left" | "top" | "right" | "bottom") {
const nativeView: android.view.View = this.nativeViewProtected;
const lp = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
switch (value) {
case "left":
lp.dock = org.nativescript.widgets.Dock.left;
break;
View.prototype[dockProperty.setNative] = function (
this: View,
value: "left" | "top" | "right" | "bottom"
) {
const nativeView: android.view.View = this.nativeViewProtected;
const lp =
nativeView.getLayoutParams() ||
new org.nativescript.widgets.CommonLayoutParams();
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
switch (value) {
case "left":
lp.dock = org.nativescript.widgets.Dock.left;
break;
case "top":
lp.dock = org.nativescript.widgets.Dock.top;
break;
case "top":
lp.dock = org.nativescript.widgets.Dock.top;
break;
case "right":
lp.dock = org.nativescript.widgets.Dock.right;
break;
case "right":
lp.dock = org.nativescript.widgets.Dock.right;
break;
case "bottom":
lp.dock = org.nativescript.widgets.Dock.bottom;
break;
case "bottom":
lp.dock = org.nativescript.widgets.Dock.bottom;
break;
default:
throw new Error(`Invalid value for dock property: ${value}`);
}
default:
throw new Error(`Invalid value for dock property: ${value}`);
}
nativeView.setLayoutParams(lp);
}
nativeView.setLayoutParams(lp);
}
};
export class DockLayout extends DockLayoutBase {
nativeViewProtected: org.nativescript.widgets.DockLayout;
nativeViewProtected: org.nativescript.widgets.DockLayout;
public createNativeView() {
return new org.nativescript.widgets.DockLayout(this._context);
}
public createNativeView() {
return new org.nativescript.widgets.DockLayout(this._context);
}
[stretchLastChildProperty.getDefault](): boolean {
return true;
}
[stretchLastChildProperty.setNative](value: boolean) {
this.nativeViewProtected.setStretchLastChild(value);
}
[stretchLastChildProperty.getDefault](): boolean {
return true;
}
[stretchLastChildProperty.setNative](value: boolean) {
this.nativeViewProtected.setStretchLastChild(value);
}
}

View File

@@ -1,26 +1,26 @@
import { LayoutBase } from "../layout-base";
import { Property } from "../../core/properties";
import { View } from '../../core/view';
import { View } from "../../core/view";
/**
* A Layout that arranges its children at its outer edges, and allows its last child to take up the remaining space.
*/
export class DockLayout extends LayoutBase {
/**
* Gets the value of the Dock property from a given View.
*/
static getDock(view: View): Dock;
/**
* Gets the value of the Dock property from a given View.
*/
static getDock(view: View): Dock;
/**
* Sets the value of the Dock property from a given View.
*/
static setDock(view: View, value: Dock): void;
/**
* Sets the value of the Dock property from a given View.
*/
static setDock(view: View, value: Dock): void;
/**
* Gets or sets a value that indicates whether the last child element within a DockLayout stretches to fill the remaining available space.
* The default value is true.
*/
stretchLastChild: boolean;
/**
* Gets or sets a value that indicates whether the last child element within a DockLayout stretches to fill the remaining available space.
* The default value is true.
*/
stretchLastChild: boolean;
}
export type Dock = "left" | "top" | "right" | "bottom";

View File

@@ -5,142 +5,254 @@ import { layout } from "../../../utils/utils";
export * from "./dock-layout-common";
export class DockLayout extends DockLayoutBase {
public onDockChanged(
view: View,
oldValue: "left" | "top" | "right" | "bottom",
newValue: "left" | "top" | "right" | "bottom"
) {
this.requestLayout();
}
public onDockChanged(view: View, oldValue: "left" | "top" | "right" | "bottom", newValue: "left" | "top" | "right" | "bottom") {
this.requestLayout();
}
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;
let remainingWidth =
widthMode === layout.UNSPECIFIED
? Number.MAX_VALUE
: width - horizontalPaddingsAndMargins;
let remainingHeight =
heightMode === layout.UNSPECIFIED
? Number.MAX_VALUE
: height - verticalPaddingsAndMargins;
let remainingWidth = widthMode === layout.UNSPECIFIED ? Number.MAX_VALUE : width - horizontalPaddingsAndMargins;
let remainingHeight = heightMode === layout.UNSPECIFIED ? Number.MAX_VALUE : height - verticalPaddingsAndMargins;
let tempHeight: number = 0;
let tempWidth: number = 0;
let childWidthMeasureSpec: number;
let childHeightMeasureSpec: number;
let tempHeight: number = 0;
let tempWidth: number = 0;
let childWidthMeasureSpec: number;
let childHeightMeasureSpec: number;
this.eachLayoutChild((child, last) => {
if (this.stretchLastChild && last) {
childWidthMeasureSpec = layout.makeMeasureSpec(
remainingWidth,
widthMode
);
childHeightMeasureSpec = layout.makeMeasureSpec(
remainingHeight,
heightMode
);
} else {
// Measure children with AT_MOST even if our mode is EXACT
childWidthMeasureSpec = layout.makeMeasureSpec(
remainingWidth,
widthMode === layout.EXACTLY ? layout.AT_MOST : widthMode
);
childHeightMeasureSpec = layout.makeMeasureSpec(
remainingHeight,
heightMode === layout.EXACTLY ? layout.AT_MOST : heightMode
);
}
this.eachLayoutChild((child, last) => {
if (this.stretchLastChild && last) {
childWidthMeasureSpec = layout.makeMeasureSpec(remainingWidth, widthMode);
childHeightMeasureSpec = layout.makeMeasureSpec(remainingHeight, heightMode);
}
else {
// Measure children with AT_MOST even if our mode is EXACT
childWidthMeasureSpec = layout.makeMeasureSpec(remainingWidth, widthMode === layout.EXACTLY ? layout.AT_MOST : widthMode);
childHeightMeasureSpec = layout.makeMeasureSpec(remainingHeight, heightMode === layout.EXACTLY ? layout.AT_MOST : heightMode);
}
let childSize = View.measureChild(
this,
child,
childWidthMeasureSpec,
childHeightMeasureSpec
);
let childSize = View.measureChild(this, child, childWidthMeasureSpec, childHeightMeasureSpec);
switch (child.dock) {
case "top":
case "bottom":
remainingHeight = Math.max(
0,
remainingHeight - childSize.measuredHeight
);
tempHeight += childSize.measuredHeight;
measureWidth = Math.max(
measureWidth,
tempWidth + childSize.measuredWidth
);
measureHeight = Math.max(measureHeight, tempHeight);
break;
switch (child.dock) {
case "top":
case "bottom":
remainingHeight = Math.max(0, remainingHeight - childSize.measuredHeight);
tempHeight += childSize.measuredHeight;
measureWidth = Math.max(measureWidth, tempWidth + childSize.measuredWidth);
measureHeight = Math.max(measureHeight, tempHeight);
break;
case "left":
case "right":
default:
remainingWidth = Math.max(
0,
remainingWidth - childSize.measuredWidth
);
tempWidth += childSize.measuredWidth;
measureWidth = Math.max(measureWidth, tempWidth);
measureHeight = Math.max(
measureHeight,
tempHeight + childSize.measuredHeight
);
break;
}
});
case "left":
case "right":
default:
remainingWidth = Math.max(0, remainingWidth - childSize.measuredWidth);
tempWidth += childSize.measuredWidth;
measureWidth = Math.max(measureWidth, tempWidth);
measureHeight = Math.max(measureHeight, tempHeight + childSize.measuredHeight);
break;
}
});
measureWidth += horizontalPaddingsAndMargins;
measureHeight += verticalPaddingsAndMargins;
measureWidth += horizontalPaddingsAndMargins;
measureHeight += verticalPaddingsAndMargins;
measureWidth = Math.max(measureWidth, this.effectiveMinWidth);
measureHeight = Math.max(measureHeight, this.effectiveMinHeight);
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 horizontalPaddingsAndMargins =
this.effectivePaddingLeft +
this.effectivePaddingRight +
this.effectiveBorderLeftWidth +
this.effectiveBorderRightWidth +
insets.left +
insets.right;
const verticalPaddingsAndMargins =
this.effectivePaddingTop +
this.effectivePaddingBottom +
this.effectiveBorderTopWidth +
this.effectiveBorderBottomWidth +
insets.top +
insets.bottom;
const insets = this.getSafeAreaInsets();
const horizontalPaddingsAndMargins = this.effectivePaddingLeft + this.effectivePaddingRight + this.effectiveBorderLeftWidth + this.effectiveBorderRightWidth + insets.left + insets.right;
const verticalPaddingsAndMargins = this.effectivePaddingTop + this.effectivePaddingBottom + this.effectiveBorderTopWidth + this.effectiveBorderBottomWidth + insets.top + insets.bottom;
let childLeft =
this.effectiveBorderLeftWidth +
this.effectivePaddingLeft +
insets.left;
let childTop =
this.effectiveBorderTopWidth +
this.effectivePaddingTop +
insets.top;
let childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left;
let childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top;
let x = childLeft;
let y = childTop;
let x = childLeft;
let y = childTop;
let remainingWidth = Math.max(
0,
right - left - horizontalPaddingsAndMargins
);
let remainingHeight = Math.max(
0,
bottom - top - verticalPaddingsAndMargins
);
let remainingWidth = Math.max(0, right - left - horizontalPaddingsAndMargins);
let remainingHeight = Math.max(0, bottom - top - verticalPaddingsAndMargins);
this.eachLayoutChild((child, last) => {
let childWidth =
child.getMeasuredWidth() +
child.effectiveMarginLeft +
child.effectiveMarginRight;
let childHeight =
child.getMeasuredHeight() +
child.effectiveMarginTop +
child.effectiveMarginBottom;
this.eachLayoutChild((child, last) => {
if (last && this.stretchLastChild) {
// Last child with stretch - give it all the space and return;
View.layoutChild(
this,
child,
x,
y,
x + remainingWidth,
y + remainingHeight
);
let childWidth = child.getMeasuredWidth() + child.effectiveMarginLeft + child.effectiveMarginRight;
let childHeight = child.getMeasuredHeight() + child.effectiveMarginTop + child.effectiveMarginBottom;
return;
}
if (last && this.stretchLastChild) {
// Last child with stretch - give it all the space and return;
View.layoutChild(this, child, x, y, x + remainingWidth, y + remainingHeight);
let dock = DockLayout.getDock(child);
switch (dock) {
case "top":
childLeft = x;
childTop = y;
childWidth = remainingWidth;
y += childHeight;
remainingHeight = Math.max(
0,
remainingHeight - childHeight
);
break;
return;
}
case "bottom":
childLeft = x;
childTop = y + remainingHeight - childHeight;
childWidth = remainingWidth;
remainingHeight = Math.max(
0,
remainingHeight - childHeight
);
break;
let dock = DockLayout.getDock(child);
switch (dock) {
case "top":
childLeft = x;
childTop = y;
childWidth = remainingWidth;
y += childHeight;
remainingHeight = Math.max(0, remainingHeight - childHeight);
break;
case "right":
childLeft = x + remainingWidth - childWidth;
childTop = y;
childHeight = remainingHeight;
remainingWidth = Math.max(0, remainingWidth - childWidth);
break;
case "bottom":
childLeft = x;
childTop = y + remainingHeight - childHeight;
childWidth = remainingWidth;
remainingHeight = Math.max(0, remainingHeight - childHeight);
break;
case "left":
default:
childLeft = x;
childTop = y;
childHeight = remainingHeight;
x += childWidth;
remainingWidth = Math.max(0, remainingWidth - childWidth);
break;
}
case "right":
childLeft = x + remainingWidth - childWidth;
childTop = y;
childHeight = remainingHeight;
remainingWidth = Math.max(0, remainingWidth - childWidth);
break;
case "left":
default:
childLeft = x;
childTop = y;
childHeight = remainingHeight;
x += childWidth;
remainingWidth = Math.max(0, remainingWidth - childWidth);
break;
}
View.layoutChild(this, child, childLeft, childTop, childLeft + childWidth, childTop + childHeight);
});
}
View.layoutChild(
this,
child,
childLeft,
childTop,
childLeft + childWidth,
childTop + childHeight
);
});
}
}