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

Slider to be be responsive to click #92

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ 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).
trackClickable | bool | Yes | false | Set to true to update the value whilst clicking the Slider

---

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.11.1",
"description": "A pure JavaScript <Slider /> component for react-native",
"main": "lib/Slider.js",
"files": [
Expand Down
15 changes: 12 additions & 3 deletions src/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export default class Slider extends PureComponent {
* Used to configure the animation parameters. These are the same parameters in the Animated library.
*/
animationConfig: PropTypes.object,

/**
* Set to true to update the value whilst clicking the Slider
*/
trackClickable : PropTypes.bool,
};

static defaultProps = {
Expand All @@ -180,6 +185,7 @@ export default class Slider extends PureComponent {
thumbTouchSize: { width: 40, height: 40 },
debugTouchArea: false,
animationType: 'timing',
trackClickable: false,
};

state = {
Expand Down Expand Up @@ -227,6 +233,7 @@ export default class Slider extends PureComponent {
trackStyle,
thumbStyle,
debugTouchArea,
trackClickable,
onValueChange,
thumbTouchSize,
animationType,
Expand Down Expand Up @@ -322,6 +329,7 @@ export default class Slider extends PureComponent {
style,
trackStyle,
thumbStyle,
trackClickable,
...otherProps
} = props;

Expand All @@ -332,15 +340,16 @@ export default class Slider extends PureComponent {
e: Object /* gestureState: Object */,
): boolean =>
// Should we become active when the user presses down on the thumb?
this._thumbHitTest(e);
return this.props.trackClickable ? true : this._thumbHitTest(e);
};

_handleMoveShouldSetPanResponder(/* e: Object, gestureState: Object */): boolean {
// Should we become active when the user moves a touch over the thumb?
return false;
}

_handlePanResponderGrant = (/* e: Object, gestureState: Object */) => {
this._previousLeft = this._getThumbLeft(this._getCurrentValue());
_handlePanResponderGrant = (e: Object, gestureState: Object) => {
this._previousLeft = this.props.trackClickable ? gestureState.x0 - (this.state.thumbSize.width/2) : this._getThumbLeft(this._getCurrentValue());
this._fireChangeEvent('onSlidingStart');
};

Expand Down