1.0.0 • Published 5 years ago

react-native-super-slider v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
5 years ago

react-native-super-slider

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

Getting Started

Installation

$ npm i react-native-super-slider --save

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 numbersInit values of the slider.
displayValuefalsebooleanIf show the current value
valueContainerStyle{ width:30,height:25,backgroundColor:'rgb(237,49,43)',alignSelf:'center',position:'relative',top: -30,alignItems: 'center' },objectCurrent value text container style
valueTextStyle{ flex:1,fontSize:16,color:'#fff',lineHeight:25 },objectCurrent value text container style.
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}objectArea to be touched, should enclose the whole marker. Will be automatically centered and contain the marker. Slip displacement If finger leaves the marker measures distance before responder cuts out and changes are no longer registered, if not given marker will be active until pressed released.
customMarkerfunctionComponent used for the cursor.
customMarkerLeftfunctionComponent used for the left cursor.
customMarkerRightfunctionComponent used for the right cursor.
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} Stylestyle objectStyles for the slider
valuePrefixstringPrefix added to the value.
valueSuffixstringSuffix added to the value.
enabledOnetruebooleanEnables the first cursor
enabledTwotruebooleanEnables the second cursor
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
markerOffsetX0numberOffset first cursor.
markerOffsetY0numberOffset second cursor.