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
Changes from 1 commit
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
15 changes: 11 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,8 +312,7 @@ 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 true;
return this.props.trackClickable ? true : this._thumbHitTest(e);
};

_handleMoveShouldSetPanResponder(/*e: Object, gestureState: Object*/): boolean {
Expand All @@ -315,7 +322,7 @@ export default class Slider extends PureComponent {

_handlePanResponderGrant = (e: Object, gestureState: Object) => {
// this._previousLeft = this._getThumbLeft(this._getCurrentValue());
this._previousLeft = gestureState.x0 - (this.state.thumbSize.width/2);
Copy link

@ghost ghost Jul 11, 2018

Choose a reason for hiding this comment

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

react-native-slider is still not clickable
Does anyone have a solution for this?
I made the above changes to the Slider.js file. It still does not work for Android or IOS.
Slider.txt

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