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.
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { DockLayout as DockLayoutDefinition, Dock } from ".";
|
|
import { LayoutBase, View, Property, isIOS, booleanConverter, makeValidator, makeParser, CSSType } from "../layout-base";
|
|
|
|
function validateArgs(element: View): View {
|
|
if (!element) {
|
|
throw new Error("element cannot be null or undefinied.");
|
|
}
|
|
return element;
|
|
}
|
|
|
|
export * from "../layout-base";
|
|
|
|
@CSSType("DockLayout")
|
|
export class DockLayoutBase extends LayoutBase implements DockLayoutDefinition {
|
|
|
|
public static getDock(element: View): Dock {
|
|
return validateArgs(element).dock;
|
|
}
|
|
|
|
public static setDock(element: View, value: Dock): void {
|
|
validateArgs(element).dock = value;
|
|
}
|
|
|
|
public stretchLastChild: boolean;
|
|
|
|
public onDockChanged(view: View, oldValue: Dock, newValue: Dock) {
|
|
//
|
|
}
|
|
}
|
|
|
|
DockLayoutBase.prototype.recycleNativeView = "auto";
|
|
|
|
const dockConverter = makeParser<Dock>(makeValidator<Dock>("left", "top", "right", "bottom"));
|
|
export const dockProperty = new Property<View, Dock>({
|
|
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: dockConverter
|
|
});
|
|
dockProperty.register(View);
|
|
|
|
export const stretchLastChildProperty = new Property<DockLayoutBase, boolean>({
|
|
name: "stretchLastChild", defaultValue: true, affectsLayout: isIOS, valueConverter: booleanConverter
|
|
});
|
|
stretchLastChildProperty.register(DockLayoutBase);
|