Skip to content

Commit e675bb5

Browse files
committed
Allow track press to change slider position
1 parent 707263b commit e675bb5

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/components/slider/index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import _ from 'lodash';
22
import PropTypes from 'prop-types';
33
import React from 'react';
4-
import {StyleSheet, PanResponder, ViewPropTypes, AccessibilityInfo, Animated} from 'react-native';
4+
import {
5+
StyleSheet,
6+
PanResponder,
7+
ViewPropTypes,
8+
AccessibilityInfo,
9+
Animated
10+
} from 'react-native';
511
import {Constants} from '../../helpers';
612
import {PureBaseComponent} from '../../commons';
713
import {Colors} from '../../style';
@@ -339,6 +345,17 @@ export default class Slider extends PureBaseComponent {
339345
return scaleRatioFromSize || defaultScaleFactor;
340346
};
341347

348+
updateTrackStepAndStyle = ({nativeEvent}) => {
349+
this._x = nativeEvent.locationX;
350+
this.updateValue(nativeEvent.locationX);
351+
352+
if (this.props.step > 0) {
353+
this.bounceToStep();
354+
} else {
355+
this.updateStyles(nativeEvent.locationX);
356+
}
357+
}
358+
342359
/* Events */
343360

344361
onValueChange = value => {
@@ -365,6 +382,15 @@ export default class Slider extends PureBaseComponent {
365382
this.handleMeasure('thumbSize', nativeEvent);
366383
};
367384

385+
handleTrackPress = ({nativeEvent}) => {
386+
if (this.props.disabled) {
387+
return;
388+
}
389+
390+
this.updateTrackStepAndStyle({nativeEvent});
391+
this.onSeekEnd();
392+
};
393+
368394
handleMeasure = (name, nativeEvent) => {
369395
const {width, height} = nativeEvent.layout;
370396
const size = {width, height};
@@ -498,8 +524,9 @@ export default class Slider extends PureBaseComponent {
498524
/>
499525
</View>
500526
)}
527+
528+
<View style={styles.touchArea} onTouchEnd={this.handleTrackPress}/>
501529
{this.renderThumb()}
502-
{/* <View style={styles.touchArea}/> */}
503530
</View>
504531
);
505532
}

0 commit comments

Comments
 (0)