1.0.0 • Published 3 years ago

@pietroanello/ptomasroos-react-native-multi-slider v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-native-multi-slider

Pure JS react native slider component with one or two markers. Options to customize track, touch area and provide customer markers and callbacks for touch events and value changes.

Examples

cd example/Basic
npm install
react-native run-ios
react-native run-android

Example

Getting Started

Installation

$ npm install --save @ptomasroos/react-native-multi-slider

Usage in a ScrollView

 enableScroll = () => this.setState({ scrollEnabled: true });
 disableScroll = () => this.setState({ scrollEnabled: false });

 render() {
   return (
     <ScrollView scrollEnabled={this.state.scrollEnabled}>
      <MultiSlider
        ...
        onValuesChangeStart={this.disableScroll}
        onValuesChangeFinish={this.enableScroll}
      />
    </ScrollView>
    );

shape up CustomMarker as left and right

In order to make different styles on markers you can set isMarkersSeparated to true, define customMarkerLeft and customMarkerRight in MultiSlider. for example:

<MultiSlider
    ...
    isMarkersSeparated={true}

    customMarkerLeft={(e) => {
         return (<CustomSliderMarkerLeft
          currentValue={e.currentValue}/>)
    }}

    customMarkerRight={(e) => {
         return (<CustomSliderMarkerRight
         currentValue={e.currentValue}/>)
    }}
/>

Partial report of the props

Feel free to contribute to this part of the documentation.

Prop nameDefault valueTypePurpouse
values0array of numbersPrefixed values of the slider.
onValuesChangeStart() => {}functionCallback when the value starts changing
onValuesChange() => {}functionCallback when the value changes
onValuesChangeFinish(values) => {}functionCallback when the value stops changing
sliderLength280numberLength of the slider (?)
touchDimensions{height: 50,width: 50,borderRadius: 15,slipDisplacement: 200}object(?)
enableLabelfunctionEnable the label rendering
customLabelfunctionComponent used for rendering a label above the cursors.
customMarkerfunctionComponent used for the cursor.
customMarkerLeftfunctionComponent used for the left cursor.
customMarkerRightfunctionComponent used for the right cursor.
isMarkersSeparatedbooleanSee explaination above in the README.md
min0numberMinimum value available in the slider.
max10numberMaximum value available in the slider.
step1numberStep value of the slider.
optionsArrayarray of numbersPossible values of the slider. Ignores min and max.
{container/track/selected/unselected/ markerContainer/marker/pressedMarker/step/stepLabel/StepMarker} Stylestyle objectStyles for the slider
valuePrefixstringPrefix added to the value.
valueSuffixstringSuffix added to the value.
enabledOnetruebooleanEnables the first cursor
enabledTwotruebooleanEnables the second cursor
stepsAs[]array of objectsUse stepsAs when you want to customize the steps-labels. stepsAs expects an array of objects {index: number, stepLabel: string, prefix: string, suffix: string}. Where index is for which step you want to customize, and all the other steps will show its index as its stepLabel. Both showSteps and showStepsLabels has to be enabled for stepsAs to be used.
showStepsfalsebooleanShow steps
showStepMarkerstruebooleanShow steps-markers on the track, showSteps has to be enabled as well
showStepLabelstruebooleanShow steps-labels underneath the track, showSteps has to be enabled as well
onToggleOneundefinedfunction callbackListener when first cursor toggles.
onToggleTwoundefinedfunction callbackListener when second cursor toggles.
allowOverlapfalsebooleanAllow the overlap within the cursors.
snappedfalsebooleanUse this when you want a fixed position for your markers, this will split the slider in N specific positions
smoothSnappedfalsebooleanSame as snapped but you can move the slider as usual. When released it will go to the nearest marker
verticalfalsebooleanUse vertical orientation instead of horizontal.
markerOffsetX0numberOffset the cursor(s) on the X axis
markerOffsetY0numberOffset the cursor(s) on the Y axis
markerSize0numberIt determines the marker margin from the edges of the track, useful to avoid the markers to overflow out of the track.
minMarkerOverlapDistance0numberif this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in pixels, not steps). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. CANNOT be combined with minMarkerOverlapDistance
minMarkerOverlapStepDistance0numberif this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other (in steps, not pixels). This can be used for cases where you have two markers large cursors and you don't want them to overlap. Note that markers will still overlap at the start if starting values are too near. CANNOT be combined with minMarkerOverlapStepDistance
imageBackgroundSourceundefinedstringSpecifies the source as required by ImageBackground
testIDstringUsed to locate this view in end-to-end tests.