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 3 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
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
17 changes: 13 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,17 @@ 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._getThumbLeft(this._getCurrentValue());
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