Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds minimum and maximum values that the thumb can slide to #129

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ value | number | Yes | 0 | Initia
disabled | bool | Yes | false | If true the user won't be able to move the slider
minimumValue | number | Yes | 0 | Initial minimum value of the slider
maximumValue | number | Yes | 1 | Initial maximum value of the slider
minimumSlideValue | number | Yes | undefined | Minimum value the user can set the thumb to
maximumSlideValue | number | Yes | undefined | Maximum value the user can set the thumb to
step | number | Yes | 0 | Step value of the slider. The value should be between 0 and maximumValue - minimumValue)
minimumTrackTintColor | string | Yes | '#3f3f3f' | The color used for the track to the left of the button
maximumTrackTintColor | string | Yes | '#b3b3b3' | The color used for the track to the right of the button
Expand All @@ -94,7 +96,7 @@ thumbImage | [source](http://facebook.github.io/react-native/docs/ima
debugTouchArea | bool | Yes | false | Set this to true to visually see the thumb touch rect in green.
animateTransitions | bool | Yes | false | Set to true if you want to use the default 'spring' animation
animationType | string | Yes | 'timing' | Set to 'spring' or 'timing' to use one of those two types of animations with the default [animation properties](https://facebook.github.io/react-native/docs/animations.html).
animationConfig | object | Yes | undefined | Used to configure the animation parameters. These are the same parameters in the [Animated library](https://facebook.github.io/react-native/docs/animations.html).
animationConfig | object | Yes | undefined | Used to configure the animation parameters. These are the same parameters in the [Animated library](https://facebook.github.io/react-native/docs/animations.html).


---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-slider",
"version": "0.11.0",
"version": "0.13.0",
"description": "A pure JavaScript <Slider /> component for react-native",
"main": "lib/Slider.js",
"files": [
Expand Down
31 changes: 16 additions & 15 deletions src/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export default class Slider extends PureComponent {
onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
onPanResponderGrant: this._handlePanResponderGrant,
onPanResponderMove: this._handlePanResponderMove,
onPanResponderRelease: this._handlePanResponderEnd,
onPanResponderMove: (e, gestureState) => this._handlePanResponderEvent(e, gestureState, 'onValueChange'),
onPanResponderRelease: (e, gestureState) => this._handlePanResponderEvent(e, gestureState, 'onSlidingComplete'),
onPanResponderTerminationRequest: this._handlePanResponderRequestEnd,
onPanResponderTerminate: this._handlePanResponderEnd,
});
Expand Down Expand Up @@ -321,29 +321,30 @@ export default class Slider extends PureComponent {
this._fireChangeEvent('onSlidingStart');
};

_handlePanResponderMove = (e: Object, gestureState: Object) => {
_handlePanResponderEvent = (e: Object, gestureState: Object, changeEvent: string) => {
var value = this._getValue(gestureState)

if (this.props.disabled) {
return;
}

this._setCurrentValue(this._getValue(gestureState));
this._fireChangeEvent('onValueChange');
};
if(value < this.props.minimumSlideValue){
this._setCurrentValue(this.props.minimumSlideValue);
} else if (value > this.props.maximumSlideValue){
this._setCurrentValue(this.props.maximumSlideValue);
} else {
this._setCurrentValue(value);
}

this._fireChangeEvent(changeEvent);

}

_handlePanResponderRequestEnd(e: Object, gestureState: Object) {
// Should we allow another component to take over this pan?
return false;
};

_handlePanResponderEnd = (e: Object, gestureState: Object) => {
if (this.props.disabled) {
return;
}

this._setCurrentValue(this._getValue(gestureState));
this._fireChangeEvent('onSlidingComplete');
};

_measureContainer = (x: Object) => {
this._handleMeasure('containerSize', x);
};
Expand Down