githuboftigran / rn-range-slider

A native slider with range
MIT License
237 stars 133 forks source link

Programatically set the values of the min and max #8

Closed dayaki closed 5 years ago

dayaki commented 5 years ago

Hi, thanks for the package but am wondering if its possible to programatically set the values of the min and max range?

Say the min={20} and max={80}, how do I set it that it starts at 40 but the user can move min back to 20 if they want.

githuboftigran commented 5 years ago

@dayaki , thanks for your question. So you want to set the min to 40 and max to 80. But allow user to slide the lower thumb to left and change the min value?

dayaki commented 5 years ago

@githuboftigran Yes, users should be able to slide the left and right thumb higher or lower than the initial value

githuboftigran commented 5 years ago

@dayaki I don't really understand why you need to change the minimum and maximum values while user slides thumbs, but if I understood correctly, you can set min and max in state when the value is changed:

const { min, max } = this.state;

<RangeSlider
    style={{width: 160, height: 80}}
    min={min}
    max={max}
    onValueChanged={(low, high) => {
        if (low == min) { // Reached the minimum value
            low = min - step;
        }
        if (high == max) {  // Reached the maximum value
            high = max + step;
        }
        this.setState({min: low, max: high});
    }}/>
/>
githuboftigran commented 5 years ago

@dayaki I'm closing this issue, because:

  1. The feature you asked about is not supported by this lib
  2. The solution above should work