mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00

* chore: move tns-core-modules to nativescript-core * chore: preparing compat generate script * chore: add missing definitions * chore: no need for http-request to be private * chore: packages chore * test: generate tests for tns-core-modules * chore: add anroid module for consistency * chore: add .npmignore * chore: added privateModulesWhitelist * chore(webpack): added bundle-entry-points * chore: scripts * chore: tests changed to use @ns/core * test: add scoped-packages test project * test: fix types * test: update test project * chore: build scripts * chore: update build script * chore: npm scripts cleanup * chore: make the compat pgk work with old wp config * test: generate diff friendly tests * chore: create barrel exports * chore: move files after rebase * chore: typedoc config * chore: compat mode * chore: review of barrels * chore: remove tns-core-modules import after rebase * chore: dev workflow setup * chore: update developer-workflow * docs: experiment with API extractor * chore: api-extractor and barrel exports * chore: api-extractor configs * chore: generate d.ts rollup with api-extractor * refactor: move methods inside Frame * chore: fic tests to use Frame static methods * refactor: create Builder class * refactor: use Builder class in tests * refactor: include Style in ui barrel * chore: separate compat build script * chore: fix tslint errors * chore: update NATIVESCRIPT_CORE_ARGS * chore: fix compat pack * chore: fix ui-test-app build with linked modules * chore: Application, ApplicationSettings, Connectivity and Http * chore: export Trace, Profiling and Utils * refactor: Static create methods for ImageSource * chore: fix deprecated usages of ImageSource * chore: move Span and FormattedString to ui * chore: add events-args and ImageSource to index files * chore: check for CLI >= 6.2 when building for IOS * chore: update travis build * chore: copy Pod file to compat package * chore: update error msg ui-tests-app * refactor: Apply suggestions from code review Co-Authored-By: Martin Yankov <m.i.yankov@gmail.com> * chore: typings and refs * chore: add missing d.ts files for public API * chore: adress code review FB * chore: update api-report * chore: dev-workflow for other apps * chore: api update * chore: update api-report
145 lines
6.6 KiB
TypeScript
145 lines
6.6 KiB
TypeScript
import { DockLayoutBase, View, layout } from "./dock-layout-common";
|
|
|
|
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 onMeasure(widthMeasureSpec: number, heightMeasureSpec: number): void {
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
let measureWidth = 0;
|
|
let measureHeight = 0;
|
|
|
|
const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
|
const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
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;
|
|
}
|
|
});
|
|
|
|
measureWidth += horizontalPaddingsAndMargins;
|
|
measureHeight += verticalPaddingsAndMargins;
|
|
|
|
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);
|
|
|
|
this.setMeasuredDimension(widthAndState, heightAndState);
|
|
}
|
|
|
|
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;
|
|
|
|
let childLeft = this.effectiveBorderLeftWidth + this.effectivePaddingLeft + insets.left;
|
|
let childTop = this.effectiveBorderTopWidth + this.effectivePaddingTop + insets.top;
|
|
|
|
let x = childLeft;
|
|
let y = childTop;
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
return;
|
|
}
|
|
|
|
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 "bottom":
|
|
childLeft = x;
|
|
childTop = y + remainingHeight - childHeight;
|
|
childWidth = remainingWidth;
|
|
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 "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);
|
|
});
|
|
}
|
|
}
|