UNPKG

4.36 kBJavaScriptView Raw
1import { SliderBase, valueProperty, minValueProperty, maxValueProperty } from './slider-common';
2import { colorProperty, backgroundColorProperty, backgroundInternalProperty } from '../styling/style-properties';
3import { Color } from '../../color';
4import { AndroidHelper } from '../core/view';
5export * from './slider-common';
6let SeekBar;
7let SeekBarChangeListener;
8function initializeListenerClass() {
9 if (!SeekBarChangeListener) {
10 var SeekBarChangeListenerImpl = /** @class */ (function (_super) {
11 __extends(SeekBarChangeListenerImpl, _super);
12 function SeekBarChangeListenerImpl() {
13 var _this = _super.call(this) || this;
14 return global.__native(_this);
15 }
16 SeekBarChangeListenerImpl.prototype.onProgressChanged = function (seekBar, progress, fromUser) {
17 var owner = seekBar.owner;
18 if (owner && !owner._supressNativeValue) {
19 var newValue = progress + owner.minValue;
20 valueProperty.nativeValueChange(owner, newValue);
21 }
22 };
23 SeekBarChangeListenerImpl.prototype.onStartTrackingTouch = function (seekBar) {
24 //
25 };
26 SeekBarChangeListenerImpl.prototype.onStopTrackingTouch = function (seekBar) {
27 //
28 };
29 SeekBarChangeListenerImpl = __decorate([
30 Interfaces([android.widget.SeekBar.OnSeekBarChangeListener]),
31 __metadata("design:paramtypes", [])
32 ], SeekBarChangeListenerImpl);
33 return SeekBarChangeListenerImpl;
34}(java.lang.Object));
35 SeekBarChangeListener = new SeekBarChangeListenerImpl();
36 }
37}
38function getListener() {
39 return SeekBarChangeListener;
40}
41export class Slider extends SliderBase {
42 createNativeView() {
43 if (!SeekBar) {
44 SeekBar = android.widget.SeekBar;
45 }
46 return new SeekBar(this._context);
47 }
48 initNativeView() {
49 super.initNativeView();
50 const nativeView = this.nativeViewProtected;
51 nativeView.owner = this;
52 initializeListenerClass();
53 const listener = getListener();
54 nativeView.setOnSeekBarChangeListener(listener);
55 }
56 disposeNativeView() {
57 this.nativeViewProtected.owner = null;
58 super.disposeNativeView();
59 }
60 resetNativeView() {
61 super.resetNativeView();
62 const nativeView = this.nativeViewProtected;
63 nativeView.setMax(100);
64 nativeView.setProgress(0);
65 nativeView.setKeyProgressIncrement(1);
66 }
67 /**
68 * There is no minValue in Android. We simulate this by subtracting the minValue from the native value and maxValue.
69 * We need this method to call native setMax and setProgress methods when minValue property is changed,
70 * without handling the native value changed callback.
71 */
72 setNativeValuesSilently() {
73 this._supressNativeValue = true;
74 const nativeView = this.nativeViewProtected;
75 try {
76 nativeView.setMax(this.maxValue - this.minValue);
77 nativeView.setProgress(this.value - this.minValue);
78 }
79 finally {
80 this._supressNativeValue = false;
81 }
82 }
83 [valueProperty.setNative](value) {
84 this.setNativeValuesSilently();
85 }
86 [minValueProperty.setNative](value) {
87 this.setNativeValuesSilently();
88 }
89 [maxValueProperty.getDefault]() {
90 return 100;
91 }
92 [maxValueProperty.setNative](value) {
93 this.setNativeValuesSilently();
94 }
95 [colorProperty.getDefault]() {
96 return -1;
97 }
98 [colorProperty.setNative](value) {
99 const drawable = this.nativeViewProtected.getThumb();
100 if (value instanceof Color) {
101 AndroidHelper.setDrawableColor(value.android, drawable);
102 }
103 else {
104 AndroidHelper.clearDrawableColor(drawable);
105 }
106 }
107 [backgroundColorProperty.getDefault]() {
108 return -1;
109 }
110 [backgroundColorProperty.setNative](value) {
111 const drawable = this.nativeViewProtected.getProgressDrawable();
112 if (value instanceof Color) {
113 AndroidHelper.setDrawableColor(value.android, drawable);
114 }
115 else {
116 AndroidHelper.clearDrawableColor(drawable);
117 }
118 }
119 [backgroundInternalProperty.getDefault]() {
120 return null;
121 }
122 [backgroundInternalProperty.setNative](value) {
123 //
124 }
125}
126//# sourceMappingURL=index.android.js.map
\No newline at end of file