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.
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { Slider as SliderDefinition } from ".";
|
|
import { View, Property, CoercibleProperty, isIOS, CSSType } from "../core/view";
|
|
|
|
export * from "../core/view";
|
|
|
|
// TODO: Extract base Range class for slider and progress
|
|
@CSSType("SliderBase")
|
|
export class SliderBase extends View implements SliderDefinition {
|
|
public value: number;
|
|
public minValue: number;
|
|
public maxValue: number;
|
|
}
|
|
|
|
SliderBase.prototype.recycleNativeView = "auto";
|
|
|
|
/**
|
|
* Represents the observable property backing the value property of each Slider instance.
|
|
*/
|
|
export const valueProperty = new CoercibleProperty<SliderBase, number>({
|
|
name: "value", defaultValue: 0, coerceValue: (target, value) => {
|
|
value = Math.max(value, target.minValue);
|
|
value = Math.min(value, target.maxValue);
|
|
return value;
|
|
}, valueConverter: (v) => isIOS ? parseFloat(v) : parseInt(v)
|
|
});
|
|
valueProperty.register(SliderBase);
|
|
|
|
/**
|
|
* Represents the observable property backing the minValue property of each Slider instance.
|
|
*/
|
|
export const minValueProperty = new Property<SliderBase, number>({
|
|
name: "minValue", defaultValue: 0, valueChanged: (target, oldValue, newValue) => {
|
|
maxValueProperty.coerce(target);
|
|
valueProperty.coerce(target);
|
|
}, valueConverter: (v) => isIOS ? parseFloat(v) : parseInt(v)
|
|
});
|
|
minValueProperty.register(SliderBase);
|
|
|
|
/**
|
|
* Represents the observable property backing the maxValue property of each Slider instance.
|
|
*/
|
|
export const maxValueProperty = new CoercibleProperty<SliderBase, number>({
|
|
name: "maxValue", defaultValue: 100, coerceValue: (target, value) => {
|
|
let minValue = target.minValue;
|
|
if (value < minValue) {
|
|
value = minValue;
|
|
}
|
|
|
|
return value;
|
|
},
|
|
valueChanged: (target, oldValue, newValue) => valueProperty.coerce(target),
|
|
valueConverter: (v) => isIOS ? parseFloat(v) : parseInt(v)
|
|
});
|
|
maxValueProperty.register(SliderBase);
|