JackDanielsAndCode / react-native-multi-slider

Pure JS react native slider component with one or two markers.
MIT License
151 stars 96 forks source link

Move the sliders / reset the filter with code #14

Closed olitomas closed 8 years ago

olitomas commented 8 years ago

It would be great if I could set the slider value with coding (not my finger). On the same note it would be good to have a "Reset filters" function that resets the filters to their original state.

mrlaessig commented 8 years ago

https://github.com/JackDanielsAndCode/react-native-multi-slider/pull/18 should enable you to set the slider values programmatically. Right now without an animation but maybe there will be a future implementation.

gudmundurmar commented 8 years ago

@l-urence This merge doesn't seem to have been released in a new npm version... I couldn't see it in 0.2.1 or 0.2.2 at least.

mrlaessig commented 8 years ago

@jrans I think the npm needs an update/new release. @gudmundurmar In the mean time you can install the package from github.

$ npm install --save JackDanielsAndCode/react-native-multi-slider
gudmundurmar commented 8 years ago

@l-urence Yes, that's what I ended up doing :) It's just not a nice solutions in case there are any breaking changes introduced to the master. When that's done I think this issue can be closed @olitomas @jrans

jrans commented 8 years ago

@l-urence @gudmundurmar npm version updated, sorry for teh delay and thanks for your patience!

gudmundurmar commented 8 years ago

@jrans Great :)

gudmundurmar commented 8 years ago

I have a question regarding this issue, since we're now allowing to send down props. Doesn't the arrayValue/optionsArray need to update as soon as the new props are received?

Otherwise it becomes a problem if you create an initial arrayValues/optionsArray that has [1,2,3], but then receive new values through props like 4. I get Invalid value, array does not contain: 4because a new arrayValues/optionsArray wasn't made with the new values from props

mrlaessig commented 8 years ago

According to the README:

Note these must be possible values from your set up.

Maybe you can can update the optionsArray prop with your new value(s)? As far as I can see the slider will then use your new optionsArray (https://github.com/JackDanielsAndCode/react-native-multi-slider/blob/master/Slider.js#L101).

gudmundurmar commented 8 years ago

@l-urence Had a better look at this and found the problem... Not only the values could be changing in componentWillReceiveProps, but also the min, max, and step. Causing the slider to malfunction when the new values don't fit the steps or exceed the old min-max bounds. To fix this the set(values) from https://github.com/JackDanielsAndCode/react-native-multi-slider/blob/master/Slider.js#L101 should also receive set(values, min, max, step). Otherwise making a new optionsArray will just use the old this.props.min, this.props.max and then the optionsArray will be wrong. I made pull request that addresses this problem. https://github.com/JackDanielsAndCode/react-native-multi-slider/pull/22 @jrans

mrlaessig commented 8 years ago

Fixed with #22.