mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
We want webpack's uglification to mangle function and class names
but that's what the current implementation of the CSS in {N} relys on
to get the CSS type for each view when targeted by CSS type selectors.
The implementation is changed a little so now the CSS type can be set
directly on the prototype of each View class or for TS, through decorator.
BREAKING CHANGES:
Extending classes requires marking the derived class with @CSSType
The root classes are not marked with CSSType and classes derived from ViewBase and View
will continue to work as expected. More concrete view classes (Button, Label, etc.) are
marked with @CSSType now and store their cssType on the prototype suppressing the previous
implementation that looked up the class function name. So clien classes that derive from one of
our @CSSType decorated classes will now have to be marked with @CSSType.
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { AbsoluteLayout as AbsoluteLayoutDefinition } from ".";
|
|
import { LayoutBase, View, Property, Length, zeroLength, CSSType } 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;
|
|
}
|
|
|
|
@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;
|
|
}
|
|
|
|
// 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); |