Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rn-range-slider

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rn-range-slider

React Native Range Slider for Android and iOS

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-0.99%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Demo app

Installation

  1. Add

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

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 valuesString

Currently supported values:
- number
- time
number
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 none
String

Currently supported values:
- none
- bubble
bubble
gravityVertical gravity of drawn contentString

Currently supported values:
- top
- bottom
- center
top
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 time

fromUser 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: number

highValue: number

fromUser: boolean
onTouchStartNothing to explain I think :)-
onTouchEndNothing to explain here too-

Known issues

  • Label's corner radius is not working on iOS
  • Problems with expo (won't fix as I don't take Expo seriously)

Keywords

FAQs

Package last updated on 03 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc