Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 12 additions & 4 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 @@ -179,7 +184,8 @@ export default class Slider extends PureComponent {
thumbTintColor: '#343434',
thumbTouchSize: {width: 40, height: 40},
debugTouchArea: false,
animationType: 'timing'
animationType: 'timing',
trackClickable: false,
};

state = {
Expand Down Expand Up @@ -228,6 +234,7 @@ export default class Slider extends PureComponent {
trackStyle,
thumbStyle,
debugTouchArea,
trackClickable,
...other
} = this.props;
var {value, containerSize, trackSize, thumbSize, allMeasured} = this.state;
Expand Down Expand Up @@ -296,6 +303,7 @@ export default class Slider extends PureComponent {
style,
trackStyle,
thumbStyle,
trackClickable,
...otherProps,
} = props;

Expand All @@ -304,16 +312,16 @@ export default class Slider extends PureComponent {

_handleStartShouldSetPanResponder = (e: Object, /*gestureState: Object*/): boolean => {
// Should we become active when the user presses down on the thumb?
return 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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gestureState.x0 is relative to the root component, this should be e.nativeEvent.locationX which is relative to the panResponder component.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to change:
this.state.thumbSize -> this.props.thumbTouchSize

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dummerbd @sreym Thanks for the review. I will make the changes and test them once. Haven't been working on RN lately.

this._fireChangeEvent('onSlidingStart');
};

Expand Down