@@ -130,8 +130,9 @@ export default class Slider extends PureBaseComponent {
130
130
} ;
131
131
132
132
this . initialValue = this . getRoundedValue ( props . value ) ;
133
- this . initialThumbSize = THUMB_SIZE ;
133
+ this . lastValue = this . initialValue ;
134
134
135
+ this . initialThumbSize = THUMB_SIZE ;
135
136
this . checkProps ( props ) ;
136
137
137
138
this . createPanResponderConfig ( ) ;
@@ -174,6 +175,15 @@ export default class Slider extends PureBaseComponent {
174
175
}
175
176
}
176
177
178
+ componentDidMount ( ) {
179
+ Constants . addDimensionsEventListener ( this . onOrientationChanged ) ;
180
+ }
181
+
182
+ componentWillUnmount ( ) {
183
+ Constants . removeDimensionsEventListener ( this . onOrientationChanged ) ;
184
+ }
185
+
186
+
177
187
/* Gesture Recognizer */
178
188
179
189
handleMoveShouldSetPanResponder = ( ) => {
@@ -291,9 +301,9 @@ export default class Slider extends PureBaseComponent {
291
301
}
292
302
293
303
getXForValue ( v ) {
294
- const { minimumValue, maximumValue } = this . props ;
304
+ const { minimumValue} = this . props ;
295
305
const range = this . getRange ( ) ;
296
- const relativeValue = maximumValue > 0 ? minimumValue - v : maximumValue - v ; // for negatives in min value
306
+ const relativeValue = minimumValue - v ;
297
307
const value = minimumValue < 0 ? Math . abs ( relativeValue ) : v - minimumValue ; // for negatives
298
308
const ratio = value / range ;
299
309
const x = ratio * ( this . state . trackSize . width - this . initialThumbSize . width / 2 ) ;
@@ -348,18 +358,24 @@ export default class Slider extends PureBaseComponent {
348
358
349
359
updateTrackStepAndStyle = ( { nativeEvent} ) => {
350
360
this . _x = nativeEvent . locationX ;
351
- this . updateValue ( nativeEvent . locationX ) ;
352
-
361
+ this . updateValue ( this . _x ) ;
362
+
353
363
if ( this . props . step > 0 ) {
354
364
this . bounceToStep ( ) ;
355
365
} else {
356
- this . updateStyles ( nativeEvent . locationX ) ;
366
+ this . updateStyles ( this . _x ) ;
357
367
}
358
368
}
359
369
370
+ onOrientationChanged = ( ) => {
371
+ this . initialValue = this . lastValue ;
372
+ this . setState ( { measureCompleted : false } ) ;
373
+ } ;
374
+
360
375
/* Events */
361
376
362
377
onValueChange = value => {
378
+ this . lastValue = value ;
363
379
_ . invoke ( this . props , 'onValueChange' , value ) ;
364
380
} ;
365
381
@@ -376,6 +392,7 @@ export default class Slider extends PureBaseComponent {
376
392
} ;
377
393
378
394
onTrackLayout = ( { nativeEvent} ) => {
395
+ this . setState ( { measureCompleted : false } ) ;
379
396
this . handleMeasure ( 'trackSize' , nativeEvent ) ;
380
397
} ;
381
398
@@ -401,15 +418,15 @@ export default class Slider extends PureBaseComponent {
401
418
if ( currentSize && width === currentSize . width && height === currentSize . height ) {
402
419
return ;
403
420
}
404
-
405
421
this [ layoutName ] = size ;
406
-
407
422
if ( this . containerSize && this . thumbSize && this . trackSize ) {
423
+ // console.warn('post return');
408
424
this . setState ( {
409
425
containerSize : this . containerSize ,
410
426
trackSize : this . trackSize ,
411
- thumbSize : this . thumbSize ,
412
- measureCompleted : true
427
+ thumbSize : this . thumbSize
428
+ } , ( ) => {
429
+ this . setState ( { measureCompleted : true } ) ;
413
430
} ) ;
414
431
}
415
432
} ;
0 commit comments