Files
NativeScript/tns-core-modules/ui/layouts/dock-layout/dock-layout-common.ts
Hristo Deshev b45cbe929b No more ambient modules for tns-core-modules/* subpackages.
- Use path mappings in tsconfig.json to resolve module typings
- Only use ambient mobules for global API's
- Move single-file modules to a subdir with the same name so that
we can provide a hand-written typing next to it (via package.json)
- Delete all mentions of tns-core-modules.d.ts
- Delete reference d.ts assembly build steps. Not needed anymore.
- HACK! Use a <reference> for global typings in application.d.ts
to avoid publishing a separate @types/tns-core-modules package.
- Rename declarations.d.ts to tns-core-modules.d.ts to preserve
JS project mappings in references.d.ts (the only place we use those)
2017-03-07 17:59:02 +02:00

52 lines
1.8 KiB
TypeScript

import { DockLayout as DockLayoutDefinition } from "ui/layouts/dock-layout";
import { LayoutBase, View, Property, isIOS, booleanConverter } from "ui/layouts/layout-base";
function validateArgs(element: View): View {
if (!element) {
throw new Error("element cannot be null or undefinied.");
}
return element;
}
export * from "ui/layouts/layout-base";
export class DockLayoutBase extends LayoutBase implements DockLayoutDefinition {
public static getDock(element: View): "left" | "top" | "right" | "bottom" {
return validateArgs(element).dock;
}
public static setDock(element: View, value: "left" | "top" | "right" | "bottom"): void {
validateArgs(element).dock = value;
}
public stretchLastChild: boolean;
public onDockChanged(view: View, oldValue: "left" | "top" | "right" | "bottom", newValue: "left" | "top" | "right" | "bottom") {
//
}
}
export const dockProperty = new Property<View, "left" | "top" | "right" | "bottom">({
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: (v) => {
if (v === "left" || v === "top" || v === "right" || v === "bottom") {
return <"left" | "top" | "right" | "bottom">v;
}
throw new Error(`Invalid value for dock property: ${v}`);
}
});
dockProperty.register(View);
export const stretchLastChildProperty = new Property<DockLayoutBase, boolean>({
name: "stretchLastChild", defaultValue: true, affectsLayout: isIOS, valueConverter: booleanConverter
});
stretchLastChildProperty.register(DockLayoutBase);