Files
NativeScript/tns-core-modules/ui/layouts/absolute-layout/absolute-layout.android.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

26 lines
1.2 KiB
TypeScript

import { AbsoluteLayoutBase, View, leftProperty, topProperty, Length } from "./absolute-layout-common";
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);
}
}
}
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;
public createNativeView() {
return new org.nativescript.widgets.AbsoluteLayout(this._context);
}
}