1
1
import _ from 'lodash' ;
2
2
import PropTypes from 'prop-types' ;
3
3
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' ;
5
11
import { Constants } from '../../helpers' ;
6
12
import { PureBaseComponent } from '../../commons' ;
7
13
import { Colors } from '../../style' ;
@@ -339,6 +345,17 @@ export default class Slider extends PureBaseComponent {
339
345
return scaleRatioFromSize || defaultScaleFactor ;
340
346
} ;
341
347
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
+
342
359
/* Events */
343
360
344
361
onValueChange = value => {
@@ -365,6 +382,15 @@ export default class Slider extends PureBaseComponent {
365
382
this . handleMeasure ( 'thumbSize' , nativeEvent ) ;
366
383
} ;
367
384
385
+ handleTrackPress = ( { nativeEvent} ) => {
386
+ if ( this . props . disabled ) {
387
+ return ;
388
+ }
389
+
390
+ this . updateTrackStepAndStyle ( { nativeEvent} ) ;
391
+ this . onSeekEnd ( ) ;
392
+ } ;
393
+
368
394
handleMeasure = ( name , nativeEvent ) => {
369
395
const { width, height} = nativeEvent . layout ;
370
396
const size = { width, height} ;
@@ -498,8 +524,9 @@ export default class Slider extends PureBaseComponent {
498
524
/>
499
525
</ View >
500
526
) }
527
+
528
+ < View style = { styles . touchArea } onTouchEnd = { this . handleTrackPress } />
501
529
{ this . renderThumb ( ) }
502
- { /* <View style={styles.touchArea}/> */ }
503
530
</ View >
504
531
) ;
505
532
}
0 commit comments