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

react-native-slider-picker

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-slider-picker

Custom range slide picker for React Native.

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Native Slider Picker

A lean, custom React Native input component to select a single value on a scale from 0 to a maximum value of your choice.

Installation

npm install react-native-slider-picker

Required dependencies

React Native Slider Picker's sole dependency is react-native-css-vh-vw, which is used for height and width dimensions.

Usage

Props:

Note: All props are optional and have default values.

Functional Props:

NameTypeDescriptionDefaultNotes
callbackFunctionCalled on change.() => {}
convertToNumericInputOnScreenReaderBooleanDetermines if the component should be converted to a numeric typed <TextInput> component.true
defaultValueNumberDefault value for slider on load.5If valued passed is greater than maxValue, the value will be set to that of maxValue.
errorToleranceMarginNumberMargin of error for user to move drag off of the cursor along the Y Axis of the screen/component. If user drags beyond this amount of units in either vertical direction the PanResponder event will not update position of cursor.50Is checked to ensure a Number type is passed that is greater than 0.
maxValueNumberThe maximum value/high end of range for the Slider.10
slideBeginCallbackFunctionCallback function to be executed when Slider's touch event begins.() => {}Called in onPanResponderGrant property of panResponder

General Style Props:

NameTypeDescriptionDefaultNotes
fillColorStringSets fill color of inner slider."dodgerblue"Can pass valid React Native color keywords, hexidecimal, rgb(), or rgba() values.
heightPercentageNumberPercentage of device's viewport to set as component's height.1Value passed to vh()
maxLabelStringLabel for the maximum value.Empty <View> component.Empty <View> has a flex : 1 value.
midLabelStringLabel for the medium value.Empty <View> component.Empty <View> has a flex : 1 value.
minLabelStringLabel for the minimum value.Empty <View> component.Empty <View> has a flex : 1 value.
showFillBooleanBoolean value to determine whether or not the slider inner shows a fill or if it is transparent.true
showNumberScaleBooleanBoolean value to determine whether or not to display scale of numbers for the Slider's range.false
showSeparatorScaleBooleanBoolean value to determine whether or not to display lines dividing the slider into different sections.false
widthPercentageNumberPercentage of device's viewport to set as component's width.85Value passed to vw()

Specific Style Props:

NameTypeDescriptionDefaultNotes
buttonBackgroundColorStringSets background color of Slider's button."white"Can pass valid React Native color keywords, hexidecimal, rgb(), or rgba() values.
buttonBorderColorStringSets border color of Slider's button."dimgrey"Can pass valid React Native color keywords, hexidecimal, rgb(), or rgba() values.
buttonBorderWidthNumberSets border width of Slider's button.1
buttonDimensionsPercentageNumberSets height and width of Slider's button as percentage of viewport width.1
labelFontColorStringSets font color of labels if they are displayed."dimgrey"Can pass valid React Native color keywords, hexidecimal, rgb(), or rgba() values.
labelFontSizeNumberSets font size of labels if they are displayed.28
labelFontWeightStringSets font weight of labels if they are displayed."normal"
scaleNumberFontColorStringSets font color of scale numbers if they are displayed."dimgrey"Can pass valid React Native color keywords, hexidecimal, rgb(), or rgba() values.
scaleNumberFontSizeNumberSets font size of scale numbers if they are displayed.24
scaleNumberFontWeightStringSets font weight of scale numbers if they are displayed."normal"
sliderInnerBackgroundColorStringSets background color of inner slider View."white"Can pass valid React Native color keywords, hexidecimal, rgb(), or rgba() values.
sliderInnerBorderStylesObjectAn object of StyleSheet properties to set border-related styles of sliderInner View component.{ borderWidth: vw(1) / 2, borderColor: '#d9dce4', borderBottomColor: '#f1f4f5', borderRadius: 50 }If passed, the object is filtered to remove any key/value properties that are not for component's border.

Style Override Props:

NameTypeDescriptionDefaultNotes
buttonStylesOverrideObjectIf passed, overrides all styling for the slider's button.null
labelStylesOverrideObjectIf passed, overrides all styling for the slider's label text.null
numberStylesOverrideObjectIf passed, overrides all styling for the slider's number scale text.null
selectionFillStylesOverrideObjectIf passed, overrides all styling for the slider's inner fill indicating current value.null
separatorStylesOverrideObjectIf passed, overrides all styling for the separator lines for the slider.null
sliderInnerStylesOverrideObjectIf passed, overrides all styling for the slider's inner container.null

Accessibility/Screen Reader Numeric Input Conversion Props:

NameTypeDescriptionDefaultNotes
accessibilityLabelStringPassed to accessibilityLabel prop on numeric TextInput if screen reader is enabled and convertToNumberInputOnScreenReader is true''
accessibilityHintStringPassed to accessibilityHint prop on numeric TextInput if screen reader is enabled and convertToNumericInputOnScreenReader is true.''
convertToNumericInputOnScreenReaderBooleanDetermines if the component should be converted to a numeric typed TextInput component.true
numericInputContainerStylesObjectStyleSheet rules passed to the <View> component that wraps <TextInput> in numeric input for screen readers.{ width: vw(25), flexDirection: 'row',backgroundColor: '#f1f4f5', borderBottomColor: "#889cb2", borderBottomWidth: vh(1) / 3, marginHorizontal: vw(5), marginVertical: vh(2), padding: vw(4), borderTopLeftRadius: 10, borderTopRightRadius: 10, ... Platform.isPad ? ({ marginTop: vh(4)}) : null }
numericInputTextInputStylesObjectStyleSheet rules passed to the <TextInput> component in numeric input for screen readers.{ flex: 1, fontSize: Math.ceil(vw(3) * 1.3), ... Platform.select({ ios: { marginTop: vw(2) }, android: { paddingBottom: 0, paddingTop: 5 }}) }

Basic, bare-bones usage:

import { SliderPicker } from 'react-native-slider-picker';

<SliderPicker />

Output:
react-native-slider-picker Basic Usage

Usage with many props:

import { SliderPicker } from 'react-native-slider-picker';

export class Demo extends React.Component {
  constructor(props) {
    super(props);

    this.state = { value: 25 };
  }
  
  render() {
    return (
      <View style={styles.container}>

        <SliderPicker 
          minLabel={'0'}
          midLabel={'50'}
          maxLabel={'100'}
          maxValue={100}
          callback={position => {
            this.setState({ value: position });
          }}
          defaultValue={this.state.value}
          labelFontColor={"#6c7682"}
          labelFontWeight={'600'}
          showFill={true}
          fillColor={'red'}
          labelFontWeight={'bold'}
          showNumberScale={true}
          showSeparatorScale={true}
          buttonBackgroundColor={'#fff'}
          buttonBorderColor={"#6c7682"}
          buttonBorderWidth={1}
          scaleNumberFontWeight={'300'}
          buttonDimensionsPercentage={6}
          heightPercentage={1}
          widthPercentage={80}
        />
        
        <Text>state.value: {this.state.value}</Text>
      </View>
    );
  }
}

Output:
react-native-slider-picker With Many Props

Usage with scale

import { SliderPicker } from 'react-native-slider-picker';

export class Demo extends React.Component {
  constructor(props) {
    super(props);

    this.state = { value: 5 };
  }
  
  render() {
    return (
      <View style={styles.container}>

        <SliderPicker 
          minLabel={'min'}
          midLabel={'mid'}
          maxLabel={'max'}
          maxValue={10}
          callback={position => {
            this.setState({ value: position });
          }}
          defaultValue={this.state.value}
          labelFontColor={"#6c7682"}
          labelFontWeight={'600'}
          showFill={true}
          fillColor={'green'}
          labelFontWeight={'bold'}
          showNumberScale={true}
          showSeparatorScale={true}
          buttonBackgroundColor={'#fff'}
          buttonBorderColor={"#6c7682"}
          buttonBorderWidth={1}
          scaleNumberFontWeight={'300'}
          buttonDimensionsPercentage={6}
          heightPercentage={1}
          widthPercentage={80}
        />
        
        <Text>state.value: {this.state.value}</Text>
      </View>
    );
  }
}

Output:
react-native-slider-picker With Scale

Keywords

FAQs

Package last updated on 10 Aug 2021

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