Skip to content

Commit 8ea357e

Browse files
committed
Add trackClickable as a prop
1 parent 3e86e38 commit 8ea357e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Slider.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ export default class Slider extends PureComponent {
167167
* Used to configure the animation parameters. These are the same parameters in the Animated library.
168168
*/
169169
animationConfig : PropTypes.object,
170+
171+
/**
172+
* Set to true to update the value whilst clicking the Slider
173+
*/
174+
trackClickable : PropTypes.bool,
170175
};
171176

172177
static defaultProps = {
@@ -179,7 +184,8 @@ export default class Slider extends PureComponent {
179184
thumbTintColor: '#343434',
180185
thumbTouchSize: {width: 40, height: 40},
181186
debugTouchArea: false,
182-
animationType: 'timing'
187+
animationType: 'timing',
188+
trackClickable: false,
183189
};
184190

185191
state = {
@@ -228,6 +234,7 @@ export default class Slider extends PureComponent {
228234
trackStyle,
229235
thumbStyle,
230236
debugTouchArea,
237+
trackClickable,
231238
...other
232239
} = this.props;
233240
var {value, containerSize, trackSize, thumbSize, allMeasured} = this.state;
@@ -296,6 +303,7 @@ export default class Slider extends PureComponent {
296303
style,
297304
trackStyle,
298305
thumbStyle,
306+
trackClickable,
299307
...otherProps,
300308
} = props;
301309

@@ -304,8 +312,7 @@ export default class Slider extends PureComponent {
304312

305313
_handleStartShouldSetPanResponder = (e: Object, /*gestureState: Object*/): boolean => {
306314
// Should we become active when the user presses down on the thumb?
307-
// return this._thumbHitTest(e);
308-
return true;
315+
return this.props.trackClickable ? true : this._thumbHitTest(e);
309316
};
310317

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

316323
_handlePanResponderGrant = (e: Object, gestureState: Object) => {
317324
// this._previousLeft = this._getThumbLeft(this._getCurrentValue());
318-
this._previousLeft = gestureState.x0 - (this.state.thumbSize.width/2);
325+
this._previousLeft = this.props.trackClickable ? gestureState.x0 - (this.state.thumbSize.width/2) : this._getThumbLeft(this._getCurrentValue());
319326
this._fireChangeEvent('onSlidingStart');
320327
};
321328

0 commit comments

Comments
 (0)