@@ -64,6 +64,8 @@ export class Slider extends View {
64
64
@cssProperty stepSize : number ;
65
65
@cssProperty elevation : number ;
66
66
_supressNativeValue : boolean ;
67
+ _canChangeValues : boolean = true ;
68
+ _needUpdate : boolean = true ;
67
69
public value : number ;
68
70
public minValue : number ;
69
71
public maxValue : number ;
@@ -103,22 +105,6 @@ export class Slider extends View {
103
105
super . disposeNativeView ( ) ;
104
106
}
105
107
106
- /**
107
- * There is no minValue in Android. We simulate this by subtracting the minValue from the native value and maxValue.
108
- * We need this method to call native setMax and setProgress methods when minValue property is changed,
109
- * without handling the native value changed callback.
110
- */
111
- // setNativeValuesSilently() {
112
- // this._supressNativeValue = true;
113
- // const nativeView = this.nativeViewProtected;
114
- // try {
115
- // nativeView.setMax(this.maxValue - this.minValue);
116
- // nativeView.setProgress(this.value - this.minValue);
117
- // } finally {
118
- // this._supressNativeValue = false;
119
- // }
120
- // }
121
-
122
108
[ colorProperty . setNative ] ( color : Color ) {
123
109
if ( color ) {
124
110
this . nativeViewProtected . setTrackTintList ( sliderGetEnabledColorStateList ( color ) ) ;
@@ -148,25 +134,44 @@ export class Slider extends View {
148
134
[ stepSizeProperty . setNative ] ( value ) {
149
135
this . nativeViewProtected . setStepSize ( value ) ;
150
136
}
151
- [ valueProperty . setNative ] ( value ) {
152
- // ensure we set min/max to prevent errors depending on the ordered or applied props
153
- // when reusing sliders with different min/max
137
+ updateValues ( ) {
138
+ if ( ! this . _canChangeValues ) {
139
+ console . log ( 'test1' )
140
+ this . _needUpdate = true ;
141
+ return ;
142
+ }
143
+ console . log ( 'test2' )
154
144
const min = this . minValue || DEFAULT_MIN ;
155
145
const max = this . maxValue || DEFAULT_MAX ;
156
146
this . nativeViewProtected . setValueFrom ( min ) ;
157
147
this . nativeViewProtected . setValueTo ( max ) ;
148
+ let value = this . value ;
158
149
value = Math . max ( value , min ) ;
159
150
value = Math . min ( value , max ) ;
160
151
this . nativeViewProtected . setValue ( value ) ;
161
152
}
153
+
154
+ public onResumeNativeUpdates ( ) : void {
155
+ // {N} suspends properties update on `_suspendNativeUpdates`. So we only need to do this in onResumeNativeUpdates
156
+ this . _canChangeValues = false ;
157
+ super . onResumeNativeUpdates ( ) ;
158
+ this . _canChangeValues = true ;
159
+ if ( this . _needUpdate ) {
160
+ this . _needUpdate = false ;
161
+ this . updateValues ( ) ;
162
+ }
163
+ }
164
+ [ valueProperty . setNative ] ( value ) {
165
+ this . updateValues ( ) ;
166
+ }
162
167
[ minValueProperty . setNative ] ( value ) {
163
- this . nativeViewProtected . setValueFrom ( value ) ;
168
+ this . updateValues ( ) ;
164
169
}
165
170
[ maxValueProperty . getDefault ] ( ) {
166
171
return DEFAULT_MAX ;
167
172
}
168
173
[ maxValueProperty . setNative ] ( value ) {
169
- this . nativeViewProtected . setValueTo ( value ) ;
174
+ this . updateValues ( ) ;
170
175
}
171
176
// [colorProperty.getDefault]() {
172
177
// return -1;
0 commit comments