githuboftigran / rn-range-slider

A native slider with range
MIT License
234 stars 130 forks source link

Can you help me to reset the slider value? #63

Closed selva21kd closed 3 years ago

selva21kd commented 3 years ago

Hi,

It was an amazing component, helpful. I need to know how to reset the selected range value into default value. is this possible?

shayan1998 commented 3 years ago

i have the same problem

irosenzw commented 3 years ago

Hi,

It was an amazing component, helpful. I need to know how to reset the selected range value into default value. is this possible?

@shayan1998 You can use ref : https://github.com/githuboftigran/rn-range-slider#methods

githuboftigran commented 3 years ago

I'm working on version 2 which will be a pure JS component with Animated api. So I don't update this version anymore.

githuboftigran commented 3 years ago

And yes, you can use setLowValue, setHighValue methods, please read the Readme file.

irosenzw commented 3 years ago

@shayan1998 @selva21kd until version 2.0 will be published, if you are having some trouble you can use setHighValue and setLowValue like this:

const myComponent = () => {
  ...
  const sliderRef = React.useRef(null);
  ...
  const resetSlider = () => {
    sliderRef?.current.setLowValue(0);
    sliderRef?.current.setHighValue(10);
  }

  return (
    <RangeSlider
       ref={sliderRef}
       ...
     />
  )
   .....
}
shayan1998 commented 3 years ago

@shayan1998 @selva21kd until version 2.0 will be published, if you are having some trouble you can use setHighValue and setLowValue like this:

const myComponent = () => {
  ...
  const sliderRef = React.useRef(null);
  ...
  const resetSlider = () => {
    sliderRef?.current.setLowValue(0);
    sliderRef?.current.setHighValue(10);
  }

  return (
    <RangeSlider
       ref={sliderRef}
       ...
     />
  )
   .....
}

thank you. that's solve my problem

githuboftigran commented 3 years ago

@selva21kd , @shayan1998 , just released v2 of the library. To set the value you can simply pass low / high props.