jeanregisser / react-native-slider

A pure JavaScript <Slider> component for react-native
MIT License
1.3k stars 571 forks source link

Wrong order of events when changing maximumValue and the value prop #118

Open jlo1 opened 6 years ago

jlo1 commented 6 years ago

When both maximumValue and value prop are adjusted, the thumb's position is set to value on the old min/max slider track, then the slider's track adjusts to the new maximumValue. But order of events should occur the other way around.

e.g. scenario: slider's initial props are set to {:minimumValue 0 :maximumValue 100 :value 50} update slider component props to {:value 100 :maximumValue 200} current result: slider component draws the thumb at the end of the slider even though the max value is 200; and interacting with the slider will readjust slider's value to new min/max value (e.g. dragging left slightly will recalibrate the thumb's current position to be near the 200 mark)

FelixMaulwurf commented 6 years ago

a workaround is to set new min/max first and slider values afterwards:

this.setState({ sliderMax: NEW_MAX }, () => { this.setState({ sliderValue: VALUE }) })

this is not ideal but fixes the wrong behavior of the slider

phthhieu commented 5 years ago

@FelixMaulwurf You save my day, it did work