0.0.11 • Published 4 years ago

@webileapps/rn-range-slider v0.0.11

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

RangeSlider

A fully customizable high quality react native Slider component backed by custom native iOS and Android views with ability to select range of values.

Installation

  1. Add

    • npm: npm install --save rn-range-slider
    • yarn: yarn add rn-range-slider
  2. Linking

For older React native versions ( < 0.60 ) you need to link the library:
For newer React native versions ( >= 0.60 ) you need to install pods for iOS:
  • cd ios && pod install && cd ..
  • For android everything works out of the box

Usage

RangeSlider should have fixed width and height.

import RangeSlider from 'rn-range-slider';

...

<RangeSlider
    style={{width: 160, height: 80}}
    gravity={'center'}
    min={200}
    max={1000}
    step={20}
    selectionColor="#3df"
    blankColor="#f618"
    onValueChanged={(low, high, fromUser) => {
        this.setState({rangeLow: low, rangeHigh: high})
    }}/>
/>

...

Properties

Supported color formats are: #RGB, #RGBA, #RRGGBB, #RRGGBBAA

NameDescriptionTypeDefault Value
disabledIf true user won't be able to move the sliderBooleanfalse
rangeEnabledSlider works as an ordinary slider with 1 control if falseBooleantrue
valueTypeType of slider valuesStringCurrently supported values:- number- timenumber
lineWidthWidth of slider's lineNumber4
thumbRadiusRadius of thumb (including border)Number10
thumbBorderWidthBorder width of thumbNumber2
textSizeSize of label textNumber16
labelBorderWidthBorder width of labelNumber2
labelPaddingPadding of label (distance between border and text)Number4
labelBorderRadiusBorder radius of label bubbleNumber4
labelTailHeightHeight of label bubble's tailNumber8
labelGapHeightGap between label and sliderNumber4
textFormatThis string will be formatted with active value and shown in thumb.If valueType is set to time this prop will be considered as date formatter.Since this library uses native components and everything is rendered at native side, time on label text will be formatted by NSDateFormatter for iOS and SimpleDateFormat for Android, so make sure you are passing valid format for both platforms.String"Price: %d" =>"Price: 75"if the current value is 75%d (just the number)
labelStyleStyle of the label.Label is not shown if noneStringCurrently supported values:- none- bubblebubble
gravityVertical gravity of drawn contentStringCurrently supported values:- top- bottom- centertop
selectionColorColor of selected partString#4286f4
blankColorColor of unselected partString#ffffff7f
thumbColorColor of thumbString#ffffff
thumbBorderColorColor of thumb's borderString#cccccc
labelBackgroundColorColor label's backgroundString#ff60ad
labelBorderColorColor label's borderString#d13e85
labelTextColorColor label's textString#ffffff
stepStep of slider. If valueType is set to time, this prop wil considered as milliseconds.Number1

Props below may have different types depending on valueType prop. If valueType is set to number, these props should be Numbers (integer). If valueType is set to time, these props may be Number (integer) or Date and if a Number is passed the value will be considered as timestamp.

NameDescriptionTypeDefault Value
minMinimum value of sliderDepends on valueType0
maxMaximum value of sliderDepends on valueType100
initialLowValueInitial value of lower thumbDepends on valueType0
initialHighValueInitial value of higher thumbDepends on valueType100

If initialLowValue ( or initialHighValue) is not provided, it's set to min (or max).

Methods

To call methods of RangeSlider you need to have a reference to it's instance. React native provides 2 ways to do it:

...
<RangeSlider ref="_rangeSlider" />
...
this.refs._rangeSlider.setLowValue(42);
...

or

...
<RangeSlider ref={ component => this._rangeSlider = component } />
...
this._rangeSlider.setLowValue(42);
...

Available methods

NameDescriptionParams
setLowValueSet low value of slidervalue: Number (or Date, if valueType is set to time)
setHighValueSet high value of slidervalue: Number (or Date, if valueType is set to time)

Callbacks

NameDescriptionParams
onValueChangedA callback to be called when value was changed.Type of lowValue and highValue will be Number if valueType is number and Date if valueType is timefromUser parameter is true if the value was changed because of user's interaction (not by calling setLowValue or setHighValue methods). Just like android's OnSeekbarChangeListener.lowValue: numberhighValue: numberfromUser: boolean
onTouchStartNothing to explain I think :)-
onTouchEndNothing to explain here too-

Known issues

  • Label's corner radius is not working on iOS
0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.1

4 years ago