@@ -64,6 +64,8 @@ export class Slider extends View {
6464 @cssProperty stepSize : number ;
6565 @cssProperty elevation : number ;
6666 _supressNativeValue : boolean ;
67+ _canChangeValues : boolean = true ;
68+ _needUpdate : boolean = true ;
6769 public value : number ;
6870 public minValue : number ;
6971 public maxValue : number ;
@@ -103,22 +105,6 @@ export class Slider extends View {
103105 super . disposeNativeView ( ) ;
104106 }
105107
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-
122108 [ colorProperty . setNative ] ( color : Color ) {
123109 if ( color ) {
124110 this . nativeViewProtected . setTrackTintList ( sliderGetEnabledColorStateList ( color ) ) ;
@@ -148,25 +134,44 @@ export class Slider extends View {
148134 [ stepSizeProperty . setNative ] ( value ) {
149135 this . nativeViewProtected . setStepSize ( value ) ;
150136 }
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' )
154144 const min = this . minValue || DEFAULT_MIN ;
155145 const max = this . maxValue || DEFAULT_MAX ;
156146 this . nativeViewProtected . setValueFrom ( min ) ;
157147 this . nativeViewProtected . setValueTo ( max ) ;
148+ let value = this . value ;
158149 value = Math . max ( value , min ) ;
159150 value = Math . min ( value , max ) ;
160151 this . nativeViewProtected . setValue ( value ) ;
161152 }
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+ }
162167 [ minValueProperty . setNative ] ( value ) {
163- this . nativeViewProtected . setValueFrom ( value ) ;
168+ this . updateValues ( ) ;
164169 }
165170 [ maxValueProperty . getDefault ] ( ) {
166171 return DEFAULT_MAX ;
167172 }
168173 [ maxValueProperty . setNative ] ( value ) {
169- this . nativeViewProtected . setValueTo ( value ) ;
174+ this . updateValues ( ) ;
170175 }
171176 // [colorProperty.getDefault]() {
172177 // return -1;
0 commit comments