UNPKG

15.2 kBMarkdownView Raw
1# react-native-easy-slider
2
3Pure JS react native slider component with one or two markers.
4Options to customize track, touch area and provide customer markers and callbacks for touch events and value changes.
5
6[![NPM](https://nodei.co/npm/react-native-easy-slider.png)](https://nodei.co/npm/react-native-easy-slider/)
7
8[![install size](https://packagephobia.now.sh/badge?p=react-native-easy-slider)](https://packagephobia.now.sh/result?p=react-native-easy-slider) [![dependencies](https://david-dm.org/hosseinmd/react-native-easy-slider.svg)](https://david-dm.org/hosseinmd/react-native-easy-slider.svg)
9
10![Example](https://raw.githubusercontent.com/hosseinmd/react-native-easy-slider/master/docs/demo.gif)
11
12## Getting Started
13
14- [Installation](#installation)
15
16### Installation
17
18```npm
19npm install --save react-native-easy-slider
20```
21
22```npm
23yarn add react-native-easy-slider
24```
25
26### Usage in a ScrollView
27
28```javascript
29 enableScroll = () => this.setState({ scrollEnabled: true });
30 disableScroll = () => this.setState({ scrollEnabled: false });
31
32 render() {
33 return (
34 <ScrollView scrollEnabled={this.state.scrollEnabled}>
35 <MultiSlider
36 ...
37 onValuesChangeStart={this.disableScroll}
38 onValuesChangeFinish={this.enableScroll}
39 />
40 </ScrollView>
41 );
42```
43
44### shape up CustomMarker as left and right
45
46In order to make different styles on markers you can set isMarkersSeparated to true, define customMarkerLeft and customMarkerRight in MultiSlider. for example:
47
48```javascript
49<MultiSlider
50 ...
51 isMarkersSeparated={true}
52
53 customMarkerLeft={(e) => {
54 return (<CustomSliderMarkerLeft
55 currentValue={e.currentValue}/>)
56 }}
57
58 customMarkerRight={(e) => {
59 return (<CustomSliderMarkerRight
60 currentValue={e.currentValue}/>)
61 }}
62 />
63
64```
65
66### Partial report of the props
67
68Feel free to contribute to this part of the documentation.
69
70| Prop name | Default value | Type | Purpouse |
71| :-------------------------------------------------------------------------------: | :-----------------------------------------------------------: | :---------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
72| values | [0] | array of numbers | Prefixed values of the slider. |
73| onValuesChangeStart | () => {} | function | Callback when the value starts changing |
74| onValuesChange | () => {} | function | Callback when the value changes |
75| onValuesChangeFinish | (values) => {} | function | Callback when the value stops changing |
76| sliderLength | 280 | number | Length of the slider (?) |
77| touchDimensions | {height: 50,width: 50,borderRadius: 15,slipDisplacement: 200} | object | (?) |
78| customMarker | | function | Component used for the cursor. |
79| customMarkerLeft | | function | Component used for the left cursor. |
80| customMarkerRight | | function | Component used for the right cursor. |
81| isMarkersSeparated | | boolean | (?) |
82| min | 0 | number | Minimum value available in the slider. |
83| max | 10 | number | Maximum value available in the slider. |
84| step | 1 | number | Step value of the slider. |
85| optionsArray | | array of numbers | Possible values of the slider. Ignores min and max. |
86| {container/track/selected/unselected/ markerContainer/marker/pressedMarker} Style | | style object | Styles for the slider |
87| valuePrefix | | string | Prefix added to the value. |
88| valueSuffix | | string | Suffix added to the value. |
89| enabledOne | true | boolean | Enables the first cursor |
90| enabledTwo | true | boolean | Enables the second cursor |
91| onToggleOne | undefined | function callback | Listener when first cursor toggles. |
92| onToggleTwo | undefined | function callback | Listener when second cursor toggles. |
93| allowOverlap | false | boolean | Allow the overlap within the cursors. |
94| snapped | false | boolean | Use this when you want a fixed position for your markers, this will split the slider in N specific positions |
95| markerOffsetX | 0 | number | Offset first cursor. |
96| markerOffsetY | 0 | number | Offset second cursor. |
97| minMarkerOverlapDistance | 0 | number | if this is > 0 and allowOverlap is false, this value will determine the closest two markers can come to each other. 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. |