mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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.
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { Slider as SliderDefinition } from ".";
|
|
import { View, Property, CoercibleProperty, isIOS } from "../core/view";
|
|
|
|
export * from "../core/view";
|
|
|
|
// TODO: Extract base Range class for slider and progress
|
|
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);
|