Files
NativeScript/tns-core-modules/ui/layouts/absolute-layout/absolute-layout-common.ts
Hristo Hristov 0f14101238 recycling now happens only if nativeView and android properties are not accessed. (#4627)
recycleNativeView filed now accepts: "always" | "never" | "auto". Always will recycle the nativeView no matter if its nativeView or android proprties are accessed. Never will disable recycling. Auto will recycle it only if nativeView and android properties are not accessed.
2017-08-01 15:04:16 +03:00

70 lines
2.3 KiB
TypeScript

import { AbsoluteLayout as AbsoluteLayoutDefinition } from ".";
import { LayoutBase, View, Property, Length, zeroLength } from "../layout-base";
export * from "../layout-base";
View.prototype.effectiveLeft = 0;
View.prototype.effectiveTop = 0;
function validateArgs(element: View): View {
if (!element) {
throw new Error("element cannot be null or undefinied.");
}
return element;
}
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 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;
}
onLeftChanged(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)
});
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)
});
topProperty.register(View);