mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: format
This commit is contained in:
@@ -10,66 +10,71 @@ View.prototype.effectiveLeft = 0;
|
||||
View.prototype.effectiveTop = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@CSSType("AbsoluteLayout")
|
||||
export class AbsoluteLayoutBase extends LayoutBase implements AbsoluteLayoutDefinition {
|
||||
// TODO: Do we still need this? it can be get like view.left
|
||||
public static getLeft(element: View): Length {
|
||||
return validateArgs(element).left;
|
||||
}
|
||||
export class AbsoluteLayoutBase extends LayoutBase
|
||||
implements AbsoluteLayoutDefinition {
|
||||
// TODO: Do we still need this? it can be get like view.left
|
||||
public static getLeft(element: View): Length {
|
||||
return validateArgs(element).left;
|
||||
}
|
||||
|
||||
// TODO: Do we still need this? it can be set like view.left=value
|
||||
public static setLeft(element: View, value: Length): void {
|
||||
validateArgs(element).left = value;
|
||||
}
|
||||
// TODO: Do we still need this? it can be set like view.left=value
|
||||
public static setLeft(element: View, value: Length): void {
|
||||
validateArgs(element).left = value;
|
||||
}
|
||||
|
||||
// TODO: Do we still need this? it can be get like view.top
|
||||
public static getTop(element: View): Length {
|
||||
return validateArgs(element).top;
|
||||
}
|
||||
// TODO: Do we still need this? it can be get like view.top
|
||||
public static getTop(element: View): Length {
|
||||
return validateArgs(element).top;
|
||||
}
|
||||
|
||||
// TODO: Do we still need this? it can be set like view.top=value
|
||||
public static setTop(element: View, value: Length): void {
|
||||
validateArgs(element).top = value;
|
||||
}
|
||||
// TODO: Do we still need this? it can be set like view.top=value
|
||||
public static setTop(element: View, value: Length): void {
|
||||
validateArgs(element).top = value;
|
||||
}
|
||||
|
||||
onLeftChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
//
|
||||
}
|
||||
onLeftChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
//
|
||||
}
|
||||
|
||||
onTopChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
//
|
||||
}
|
||||
onTopChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
AbsoluteLayoutBase.prototype.recycleNativeView = "auto";
|
||||
|
||||
export const leftProperty = new Property<View, Length>({
|
||||
name: "left", defaultValue: zeroLength,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
target.effectiveLeft = Length.toDevicePixels(newValue, 0);
|
||||
const layout = target.parent;
|
||||
if (layout instanceof AbsoluteLayoutBase) {
|
||||
layout.onLeftChanged(target, oldValue, newValue);
|
||||
}
|
||||
}, valueConverter: (v) => Length.parse(v)
|
||||
name: "left",
|
||||
defaultValue: zeroLength,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
target.effectiveLeft = Length.toDevicePixels(newValue, 0);
|
||||
const layout = target.parent;
|
||||
if (layout instanceof AbsoluteLayoutBase) {
|
||||
layout.onLeftChanged(target, oldValue, newValue);
|
||||
}
|
||||
},
|
||||
valueConverter: (v) => Length.parse(v),
|
||||
});
|
||||
leftProperty.register(View);
|
||||
|
||||
export const topProperty = new Property<View, Length>({
|
||||
name: "top", defaultValue: zeroLength,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
target.effectiveTop = Length.toDevicePixels(newValue, 0);
|
||||
const layout = target.parent;
|
||||
if (layout instanceof AbsoluteLayoutBase) {
|
||||
layout.onTopChanged(target, oldValue, newValue);
|
||||
}
|
||||
}, valueConverter: (v) => Length.parse(v)
|
||||
name: "top",
|
||||
defaultValue: zeroLength,
|
||||
valueChanged: (target, oldValue, newValue) => {
|
||||
target.effectiveTop = Length.toDevicePixels(newValue, 0);
|
||||
const layout = target.parent;
|
||||
if (layout instanceof AbsoluteLayoutBase) {
|
||||
layout.onTopChanged(target, oldValue, newValue);
|
||||
}
|
||||
},
|
||||
valueConverter: (v) => Length.parse(v),
|
||||
});
|
||||
topProperty.register(View);
|
||||
|
||||
@@ -1,27 +1,51 @@
|
||||
import { AbsoluteLayoutBase, leftProperty, topProperty } from "./absolute-layout-common";
|
||||
import {
|
||||
AbsoluteLayoutBase,
|
||||
leftProperty,
|
||||
topProperty,
|
||||
} from "./absolute-layout-common";
|
||||
import { View } from "../../core/view";
|
||||
import { Length } from "../../styling/style-properties";
|
||||
|
||||
export * from "./absolute-layout-common";
|
||||
|
||||
function makeNativeSetter<T>(setter: (this: View, lp: org.nativescript.widgets.CommonLayoutParams, value: T) => void) {
|
||||
return function (this: View, value: T) {
|
||||
const nativeView: android.view.View = this.nativeViewProtected;
|
||||
const lp = nativeView.getLayoutParams() || new org.nativescript.widgets.CommonLayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
|
||||
setter.call(this, lp, value);
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
};
|
||||
function makeNativeSetter<T>(
|
||||
setter: (
|
||||
this: View,
|
||||
lp: org.nativescript.widgets.CommonLayoutParams,
|
||||
value: T
|
||||
) => void
|
||||
) {
|
||||
return function (this: View, value: T) {
|
||||
const nativeView: android.view.View = this.nativeViewProtected;
|
||||
const lp =
|
||||
nativeView.getLayoutParams() ||
|
||||
new org.nativescript.widgets.CommonLayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.CommonLayoutParams) {
|
||||
setter.call(this, lp, value);
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
View.prototype[topProperty.setNative] = makeNativeSetter<number>(function (this: View, lp, value) { lp.top = Length.toDevicePixels(value, 0); });
|
||||
View.prototype[leftProperty.setNative] = makeNativeSetter<number>(function (this: View, lp, value) { lp.left = Length.toDevicePixels(value, 0); });
|
||||
View.prototype[topProperty.setNative] = makeNativeSetter<number>(function (
|
||||
this: View,
|
||||
lp,
|
||||
value
|
||||
) {
|
||||
lp.top = Length.toDevicePixels(value, 0);
|
||||
});
|
||||
View.prototype[leftProperty.setNative] = makeNativeSetter<number>(function (
|
||||
this: View,
|
||||
lp,
|
||||
value
|
||||
) {
|
||||
lp.left = Length.toDevicePixels(value, 0);
|
||||
});
|
||||
|
||||
export class AbsoluteLayout extends AbsoluteLayoutBase {
|
||||
nativeViewProtected: org.nativescript.widgets.AbsoluteLayout;
|
||||
nativeViewProtected: org.nativescript.widgets.AbsoluteLayout;
|
||||
|
||||
public createNativeView() {
|
||||
return new org.nativescript.widgets.AbsoluteLayout(this._context);
|
||||
}
|
||||
public createNativeView() {
|
||||
return new org.nativescript.widgets.AbsoluteLayout(this._context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import { LayoutBase } from "../layout-base";
|
||||
import { Property } from "../../core/properties";
|
||||
import { View } from '../../core/view';
|
||||
import { Length } from '../../styling/style-properties';
|
||||
import { View } from "../../core/view";
|
||||
import { Length } from "../../styling/style-properties";
|
||||
|
||||
/**
|
||||
* A layout that lets you specify exact locations (left/top coordinates) of its children.
|
||||
*/
|
||||
export class AbsoluteLayout extends LayoutBase {
|
||||
/**
|
||||
* Gets the value of the Left property from a given View.
|
||||
*/
|
||||
static getLeft(view: View): Length;
|
||||
/**
|
||||
* Gets the value of the Left property from a given View.
|
||||
*/
|
||||
static getLeft(view: View): Length;
|
||||
|
||||
/**
|
||||
* Sets the value of the Left property from a given View.
|
||||
*/
|
||||
static setLeft(view: View, value: Length): void;
|
||||
/**
|
||||
* Sets the value of the Left property from a given View.
|
||||
*/
|
||||
static setLeft(view: View, value: Length): void;
|
||||
|
||||
/**
|
||||
* Gets the value of the Top property from a given View.
|
||||
*/
|
||||
static getTop(view: View): Length;
|
||||
/**
|
||||
* Gets the value of the Top property from a given View.
|
||||
*/
|
||||
static getTop(view: View): Length;
|
||||
|
||||
/**
|
||||
* Sets the value of the Top property from a given View.
|
||||
*/
|
||||
static setTop(view: View, value: Length): void;
|
||||
/**
|
||||
* Sets the value of the Top property from a given View.
|
||||
*/
|
||||
static setTop(view: View, value: Length): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,62 +6,120 @@ import { layout } from "../../../utils/utils";
|
||||
export * from "./absolute-layout-common";
|
||||
|
||||
export class AbsoluteLayout extends AbsoluteLayoutBase {
|
||||
onLeftChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
this.requestLayout();
|
||||
}
|
||||
|
||||
onLeftChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
this.requestLayout();
|
||||
}
|
||||
onTopChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
this.requestLayout();
|
||||
}
|
||||
|
||||
onTopChanged(view: View, oldValue: Length, newValue: Length) {
|
||||
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 childMeasureSpec = layout.makeMeasureSpec(0, layout.UNSPECIFIED);
|
||||
|
||||
const childMeasureSpec = layout.makeMeasureSpec(0, layout.UNSPECIFIED);
|
||||
this.eachLayoutChild((child, last) => {
|
||||
let childSize = View.measureChild(
|
||||
this,
|
||||
child,
|
||||
childMeasureSpec,
|
||||
childMeasureSpec
|
||||
);
|
||||
measureWidth = Math.max(
|
||||
measureWidth,
|
||||
child.effectiveLeft + childSize.measuredWidth
|
||||
);
|
||||
measureHeight = Math.max(
|
||||
measureHeight,
|
||||
child.effectiveTop + childSize.measuredHeight
|
||||
);
|
||||
});
|
||||
|
||||
this.eachLayoutChild((child, last) => {
|
||||
let childSize = View.measureChild(this, child, childMeasureSpec, childMeasureSpec);
|
||||
measureWidth = Math.max(measureWidth, child.effectiveLeft + childSize.measuredWidth);
|
||||
measureHeight = Math.max(measureHeight, child.effectiveTop + childSize.measuredHeight);
|
||||
});
|
||||
measureWidth +=
|
||||
this.effectiveBorderLeftWidth +
|
||||
this.effectivePaddingLeft +
|
||||
this.effectivePaddingRight +
|
||||
this.effectiveBorderRightWidth;
|
||||
measureHeight +=
|
||||
this.effectiveBorderTopWidth +
|
||||
this.effectivePaddingTop +
|
||||
this.effectivePaddingBottom +
|
||||
this.effectiveBorderBottomWidth;
|
||||
|
||||
measureWidth += this.effectiveBorderLeftWidth + this.effectivePaddingLeft + this.effectivePaddingRight + this.effectiveBorderRightWidth;
|
||||
measureHeight += this.effectiveBorderTopWidth + this.effectivePaddingTop + this.effectivePaddingBottom + this.effectiveBorderBottomWidth;
|
||||
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();
|
||||
this.eachLayoutChild((child, last) => {
|
||||
const childWidth = child.getMeasuredWidth();
|
||||
const childHeight = child.getMeasuredHeight();
|
||||
|
||||
const insets = this.getSafeAreaInsets();
|
||||
this.eachLayoutChild((child, last) => {
|
||||
const childLeft =
|
||||
this.effectiveBorderLeftWidth +
|
||||
this.effectivePaddingLeft +
|
||||
child.effectiveLeft +
|
||||
insets.left;
|
||||
const childTop =
|
||||
this.effectiveBorderTopWidth +
|
||||
this.effectivePaddingTop +
|
||||
child.effectiveTop +
|
||||
insets.top;
|
||||
const childRight =
|
||||
childLeft +
|
||||
childWidth +
|
||||
child.effectiveMarginLeft +
|
||||
child.effectiveMarginRight;
|
||||
const childBottom =
|
||||
childTop +
|
||||
childHeight +
|
||||
child.effectiveMarginTop +
|
||||
child.effectiveMarginBottom;
|
||||
|
||||
const childWidth = child.getMeasuredWidth();
|
||||
const childHeight = child.getMeasuredHeight();
|
||||
|
||||
const childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + child.effectiveLeft + insets.left;
|
||||
const childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + child.effectiveTop + insets.top;
|
||||
const childRight = childLeft + childWidth + child.effectiveMarginLeft + child.effectiveMarginRight;
|
||||
const childBottom = childTop + childHeight + child.effectiveMarginTop + child.effectiveMarginBottom;
|
||||
|
||||
View.layoutChild(this, child, childLeft, childTop, childRight, childBottom);
|
||||
});
|
||||
}
|
||||
View.layoutChild(
|
||||
this,
|
||||
child,
|
||||
childLeft,
|
||||
childTop,
|
||||
childRight,
|
||||
childBottom
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user