Skip to content

Commit 5619356

Browse files
add custom track
1 parent 085b68b commit 5619356

File tree

2 files changed

+46
-19
lines changed

2 files changed

+46
-19
lines changed

Diff for: MultiSlider.js

+45-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
PanResponder,
77
View,
88
Platform,
9-
Dimensions,
109
I18nManager,
1110
ImageBackground,
1211
} from 'react-native';
@@ -53,7 +52,8 @@ export default class MultiSlider extends React.Component {
5352
vertical: false,
5453
minMarkerOverlapDistance: 0,
5554
minMarkerOverlapStepDistance: 0,
56-
testID: '',
55+
testID: undefined,
56+
renderTrack: undefined,
5757
};
5858

5959
constructor(props) {
@@ -494,6 +494,7 @@ export default class MultiSlider extends React.Component {
494494
sliderLength,
495495
markerOffsetX,
496496
markerOffsetY,
497+
renderTrack,
497498
} = this.props;
498499
const twoMarkers = this.props.values.length == 2; // when allowOverlap, positionTwo could be 0, identified as string '0' and throwing 'RawText 0 needs to be wrapped in <Text>' error
499500

@@ -548,23 +549,48 @@ export default class MultiSlider extends React.Component {
548549
const body = (
549550
<React.Fragment>
550551
<View style={[styles.fullTrack, { width: sliderLength }]}>
551-
<View
552-
style={[
553-
styles.track,
554-
this.props.trackStyle,
555-
trackOneStyle,
556-
{ width: trackOneLength },
557-
]}
558-
/>
559-
<View
560-
style={[
561-
styles.track,
562-
this.props.trackStyle,
563-
trackTwoStyle,
564-
{ width: trackTwoLength },
565-
]}
566-
{...(twoMarkers ? this._panResponderBetween.panHandlers : {})}
567-
/>
552+
{renderTrack ? (
553+
renderTrack({
554+
selectedStyle: !twoMarkers,
555+
style: [
556+
styles.track,
557+
this.props.trackStyle,
558+
trackOneStyle,
559+
{ width: trackOneLength },
560+
],
561+
})
562+
) : (
563+
<View
564+
style={[
565+
styles.track,
566+
this.props.trackStyle,
567+
trackOneStyle,
568+
{ width: trackOneLength },
569+
]}
570+
/>
571+
)}
572+
{renderTrack ? (
573+
renderTrack({
574+
selectedStyle: !!twoMarkers,
575+
style: [
576+
styles.track,
577+
this.props.trackStyle,
578+
trackTwoStyle,
579+
{ width: trackTwoLength },
580+
],
581+
...(twoMarkers ? this._panResponderBetween.panHandlers : {}),
582+
})
583+
) : (
584+
<View
585+
style={[
586+
styles.track,
587+
this.props.trackStyle,
588+
trackTwoStyle,
589+
{ width: trackTwoLength },
590+
]}
591+
{...(twoMarkers ? this._panResponderBetween.panHandlers : {})}
592+
/>
593+
)}
568594
{twoMarkers && (
569595
<View
570596
style={[

Diff for: index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export interface MultiSliderProps {
9696
enableLabel?: boolean;
9797
vertical?: boolean;
9898
testID?: string;
99+
renderTrack?: ({ style: ViewStyle, selectedStyle: boolean }) => any;
99100
}
100101

101102
export default class MultiSlider extends React.Component<MultiSliderProps> {}

0 commit comments

Comments
 (0)