@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
126 lines • 4.36 kB
JavaScript
import { SliderBase, valueProperty, minValueProperty, maxValueProperty } from './slider-common';
import { colorProperty, backgroundColorProperty, backgroundInternalProperty } from '../styling/style-properties';
import { Color } from '../../color';
import { AndroidHelper } from '../core/view';
export * from './slider-common';
let SeekBar;
let SeekBarChangeListener;
function initializeListenerClass() {
if (!SeekBarChangeListener) {
var SeekBarChangeListenerImpl = /** @class */ (function (_super) {
__extends(SeekBarChangeListenerImpl, _super);
function SeekBarChangeListenerImpl() {
var _this = _super.call(this) || this;
return global.__native(_this);
}
SeekBarChangeListenerImpl.prototype.onProgressChanged = function (seekBar, progress, fromUser) {
var owner = seekBar.owner;
if (owner && !owner._supressNativeValue) {
var newValue = progress + owner.minValue;
valueProperty.nativeValueChange(owner, newValue);
}
};
SeekBarChangeListenerImpl.prototype.onStartTrackingTouch = function (seekBar) {
//
};
SeekBarChangeListenerImpl.prototype.onStopTrackingTouch = function (seekBar) {
//
};
SeekBarChangeListenerImpl = __decorate([
Interfaces([android.widget.SeekBar.OnSeekBarChangeListener]),
__metadata("design:paramtypes", [])
], SeekBarChangeListenerImpl);
return SeekBarChangeListenerImpl;
}(java.lang.Object));
SeekBarChangeListener = new SeekBarChangeListenerImpl();
}
}
function getListener() {
return SeekBarChangeListener;
}
export class Slider extends SliderBase {
createNativeView() {
if (!SeekBar) {
SeekBar = android.widget.SeekBar;
}
return new SeekBar(this._context);
}
initNativeView() {
super.initNativeView();
const nativeView = this.nativeViewProtected;
nativeView.owner = this;
initializeListenerClass();
const listener = getListener();
nativeView.setOnSeekBarChangeListener(listener);
}
disposeNativeView() {
this.nativeViewProtected.owner = null;
super.disposeNativeView();
}
resetNativeView() {
super.resetNativeView();
const nativeView = this.nativeViewProtected;
nativeView.setMax(100);
nativeView.setProgress(0);
nativeView.setKeyProgressIncrement(1);
}
/**
* There is no minValue in Android. We simulate this by subtracting the minValue from the native value and maxValue.
* We need this method to call native setMax and setProgress methods when minValue property is changed,
* without handling the native value changed callback.
*/
setNativeValuesSilently() {
this._supressNativeValue = true;
const nativeView = this.nativeViewProtected;
try {
nativeView.setMax(this.maxValue - this.minValue);
nativeView.setProgress(this.value - this.minValue);
}
finally {
this._supressNativeValue = false;
}
}
[valueProperty.setNative](value) {
this.setNativeValuesSilently();
}
[minValueProperty.setNative](value) {
this.setNativeValuesSilently();
}
[maxValueProperty.getDefault]() {
return 100;
}
[maxValueProperty.setNative](value) {
this.setNativeValuesSilently();
}
[colorProperty.getDefault]() {
return -1;
}
[colorProperty.setNative](value) {
const drawable = this.nativeViewProtected.getThumb();
if (value instanceof Color) {
AndroidHelper.setDrawableColor(value.android, drawable);
}
else {
AndroidHelper.clearDrawableColor(drawable);
}
}
[backgroundColorProperty.getDefault]() {
return -1;
}
[backgroundColorProperty.setNative](value) {
const drawable = this.nativeViewProtected.getProgressDrawable();
if (value instanceof Color) {
AndroidHelper.setDrawableColor(value.android, drawable);
}
else {
AndroidHelper.clearDrawableColor(drawable);
}
}
[backgroundInternalProperty.getDefault]() {
return null;
}
[backgroundInternalProperty.setNative](value) {
//
}
}
//# sourceMappingURL=index.android.js.map