├── img
├── rightSide.png
├── leftSideSmall.png
└── rightSideSmall.png
├── header_github_fluid.png
├── animated_fluid_slider.gif
├── src
├── styles.js
├── index.js
└── ogSlider.js
├── package.json
└── README.md
/img/rightSide.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openGeeksLab/react-native-fluid-slider/HEAD/img/rightSide.png
--------------------------------------------------------------------------------
/img/leftSideSmall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openGeeksLab/react-native-fluid-slider/HEAD/img/leftSideSmall.png
--------------------------------------------------------------------------------
/img/rightSideSmall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openGeeksLab/react-native-fluid-slider/HEAD/img/rightSideSmall.png
--------------------------------------------------------------------------------
/header_github_fluid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openGeeksLab/react-native-fluid-slider/HEAD/header_github_fluid.png
--------------------------------------------------------------------------------
/animated_fluid_slider.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openGeeksLab/react-native-fluid-slider/HEAD/animated_fluid_slider.gif
--------------------------------------------------------------------------------
/src/styles.js:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native';
2 |
3 | const styles = StyleSheet.create({
4 | container: {
5 | backgroundColor: 'transparent',
6 | },
7 | trackStyle: {
8 | height: 4,
9 | }
10 | });
11 |
12 | export default styles;
13 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@opengeekslab/react-native-fluid-slider",
3 | "version": "1.0.1",
4 | "description": "",
5 | "main": "src/index.js",
6 | "repository": {
7 | "type": "git",
8 | "url": "git+https://github.com/openGeeksLab/react-native-fluid-slider"
9 | },
10 | "scripts": {
11 | "test": "echo \"Error: no test specified\" && exit 1"
12 | },
13 | "keywords": [
14 | "react-native",
15 | "ios",
16 | "android"
17 | ],
18 | "author": "openGeeksLab",
19 | "license": "MIT",
20 | "bugs": {
21 | "url": "https://github.com/openGeeksLab/react-native-fluid-slider/issues"
22 | },
23 | "homepage": "https://github.com/openGeeksLab/react-native-fluid-slider/#README.md",
24 | "dependencies": {
25 | "prop-types": "^15.6.2"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { Text, View } from 'react-native';
3 | import PropTypes from 'prop-types';
4 |
5 | import Slider from './ogSlider';
6 | import styles from './styles';
7 |
8 | export default class App extends Component {
9 | static propTypes = {
10 | value: PropTypes.number,
11 | minimumValue: PropTypes.number,
12 | maximumValue: PropTypes.number,
13 | step: PropTypes.number,
14 | minimumTrackTintColor: PropTypes.string,
15 | maximumTrackTintColor: PropTypes.string,
16 | thumbTintColor: PropTypes.string,
17 | onValueChange: PropTypes.func,
18 | onSlidingComplete: PropTypes.func,
19 | }
20 | static defaultProps = {
21 | value: 0,
22 | minimumValue: 0,
23 | maximumValue: 100,
24 | step: 0,
25 | minimumTrackTintColor: '#FFFFFF',
26 | maximumTrackTintColor: '#FFFFFF',
27 | thumbTintColor: '#FFFFFF',
28 | onValueChange: () => {},
29 | onSlidingComplete: () => {},
30 | };
31 |
32 | getThumbMode = () => {
33 | const {
34 | value,
35 | minimumValue,
36 | maximumValue,
37 | } = this.props;
38 | if (value === maximumValue) {
39 | return 1;
40 | } else if (value === minimumValue) {
41 | return -1;
42 | }
43 | return 0;
44 | }
45 |
46 | render() {
47 | const {
48 | value,
49 | step,
50 | minimumValue,
51 | maximumValue,
52 | onValueChange,
53 | thumbTintColor,
54 | onSlidingComplete,
55 | minimumTrackTintColor,
56 | maximumTrackTintColor,
57 | } = this.props;
58 | return (
59 |
3 |
4 |
9 |
10 |
21 |
22 | # About
23 | Our company provides custom UI design and development solutions for mobile applications and websites.
24 |
25 | Need a team to create a project?
26 |
27 | This project is developed and maintained by openGeeksLab LLC.
28 |
29 |
30 |
31 |
32 | # react-native-fluid-slider
33 |
34 | ## Requirements
35 | - React Native 0.50+
36 | - iOS 9.0+
37 | - Android 4.2+
38 |
39 | ## Installation
40 | Just run:
41 | - npm i react-native-fluid-slider
42 |
43 | ## Basic usage
44 | ```javascript
45 | import React, { Component } from 'react';
46 | import {
47 | StyleSheet,
48 | Text,
49 | View,
50 | } from 'react-native';
51 |
52 | import Slider from 'react-native-fluid-slider';
53 |
54 | export default class App extends Component {
55 | state = { value: 40 }
56 |
57 | render() {
58 | return (
59 |
106 |
107 |
108 | # Licence
109 | Expanding is released under the MIT license.
110 |
111 | Inspired by @Virgil Pana
112 |
--------------------------------------------------------------------------------
/src/ogSlider.js:
--------------------------------------------------------------------------------
1 | import React, { PureComponent } from 'react';
2 |
3 | import {
4 | Animated,
5 | Image,
6 | StyleSheet,
7 | PanResponder,
8 | View,
9 | Easing,
10 | ViewPropTypes,
11 | I18nManager,
12 | } from 'react-native';
13 |
14 | import PropTypes from 'prop-types';
15 |
16 | const TRACK_SIZE = 4;
17 | const THUMB_SIZE = 20;
18 |
19 | function Rect(x, y, width, height) {
20 | this.x = x;
21 | this.y = y;
22 | this.width = width;
23 | this.height = height;
24 | }
25 |
26 | Rect.prototype.containsPoint = function(x, y) {
27 | return (
28 | x >= this.x &&
29 | y >= this.y &&
30 | x <= this.x + this.width &&
31 | y <= this.y + this.height
32 | );
33 | };
34 |
35 | const DEFAULT_ANIMATION_CONFIGS = {
36 | spring: {
37 | friction: 7,
38 | tension: 100,
39 | },
40 | timing: {
41 | duration: 150,
42 | easing: Easing.inOut(Easing.ease),
43 | delay: 0,
44 | },
45 | };
46 |
47 | import THUMB_RIGHT from '../img/rightSide.png';
48 | import THUMB_LEFT_SMALL from '../img/leftSideSmall.png';
49 | import THUMB_RIGHT_SMALL from '../img/rightSideSmall.png';
50 |
51 | export default class Slider extends PureComponent {
52 | static propTypes = {
53 | /**
54 | * Initial value of the slider. The value should be between minimumValue
55 | * and maximumValue, which default to 0 and 1 respectively.
56 | * Default value is 0.
57 | *
58 | * *This is not a controlled component*, e.g. if you don't update
59 | * the value, the component won't be reset to its inital value.
60 | */
61 | value: PropTypes.number,
62 |
63 | /**
64 | * If true the user won't be able to move the slider.
65 | * Default value is false.
66 | */
67 | disabled: PropTypes.bool,
68 |
69 | /**
70 | * Initial minimum value of the slider. Default value is 0.
71 | */
72 | minimumValue: PropTypes.number,
73 |
74 | /**
75 | * Initial maximum value of the slider. Default value is 1.
76 | */
77 | maximumValue: PropTypes.number,
78 |
79 | /**
80 | * Step value of the slider. The value should be between 0 and
81 | * (maximumValue - minimumValue). Default value is 0.
82 | */
83 | step: PropTypes.number,
84 |
85 | /**
86 | * The color used for the track to the left of the button. Overrides the
87 | * default blue gradient image.
88 | */
89 | minimumTrackTintColor: PropTypes.string,
90 |
91 | /**
92 | * The color used for the track to the right of the button. Overrides the
93 | * default blue gradient image.
94 | */
95 | maximumTrackTintColor: PropTypes.string,
96 |
97 | /**
98 | * The color used for the thumb.
99 | */
100 | thumbTintColor: PropTypes.string,
101 |
102 | /**
103 | * The size of the touch area that allows moving the thumb.
104 | * The touch area has the same center has the visible thumb.
105 | * This allows to have a visually small thumb while still allowing the user
106 | * to move it easily.
107 | * The default is {width: 40, height: 40}.
108 | */
109 | thumbTouchSize: PropTypes.shape({
110 | width: PropTypes.number,
111 | height: PropTypes.number,
112 | }),
113 |
114 | /**
115 | * Callback continuously called while the user is dragging the slider.
116 | */
117 | onValueChange: PropTypes.func,
118 |
119 | /**
120 | * Callback called when the user starts changing the value (e.g. when
121 | * the slider is pressed).
122 | */
123 | onSlidingStart: PropTypes.func,
124 |
125 | /**
126 | * Callback called when the user finishes changing the value (e.g. when
127 | * the slider is released).
128 | */
129 | onSlidingComplete: PropTypes.func,
130 |
131 | /**
132 | * The style applied to the slider container.
133 | */
134 | style: ViewPropTypes.style,
135 |
136 | /**
137 | * The style applied to the track.
138 | */
139 | trackStyle: ViewPropTypes.style,
140 |
141 | /**
142 | * The style applied to the thumb.
143 | */
144 | thumbStyle: ViewPropTypes.style,
145 |
146 | /**
147 | * Sets an image for the thumb.
148 | */
149 | thumbImage: Image.propTypes.source,
150 |
151 | /**
152 | * Set this to true to visually see the thumb touch rect in green.
153 | */
154 | debugTouchArea: PropTypes.bool,
155 |
156 | /**
157 | * Set to true to animate values with default 'timing' animation type
158 | */
159 | animateTransitions: PropTypes.bool,
160 |
161 | /**
162 | * Custom Animation type. 'spring' or 'timing'.
163 | */
164 | animationType: PropTypes.oneOf(['spring', 'timing']),
165 |
166 | /**
167 | * Used to configure the animation parameters. These are the same parameters in the Animated library.
168 | */
169 | animationConfig: PropTypes.object,
170 | };
171 |
172 | static defaultProps = {
173 | value: 0,
174 | minimumValue: 0,
175 | maximumValue: 1,
176 | step: 0,
177 | minimumTrackTintColor: '#3f3f3f',
178 | maximumTrackTintColor: '#b3b3b3',
179 | thumbTintColor: '#343434',
180 | thumbTouchSize: { width: 40, height: 40 },
181 | debugTouchArea: false,
182 | animationType: 'timing',
183 | };
184 |
185 | state = {
186 | containerSize: { width: 0, height: 0 },
187 | trackSize: { width: 0, height: 0 },
188 | thumbSize: { width: 0, height: 0 },
189 | allMeasured: false,
190 | value: new Animated.Value(this.props.value),
191 | };
192 |
193 | componentWillMount() {
194 | this._panResponder = PanResponder.create({
195 | onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
196 | onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
197 | onPanResponderGrant: this._handlePanResponderGrant,
198 | onPanResponderMove: this._handlePanResponderMove,
199 | onPanResponderRelease: this._handlePanResponderEnd,
200 | onPanResponderTerminationRequest: this._handlePanResponderRequestEnd,
201 | onPanResponderTerminate: this._handlePanResponderEnd,
202 | });
203 | }
204 |
205 | componentWillReceiveProps(nextProps) {
206 | const newValue = nextProps.value;
207 |
208 | if (this.props.value !== newValue) {
209 | if (this.props.animateTransitions) {
210 | this._setCurrentValueAnimated(newValue);
211 | } else {
212 | this._setCurrentValue(newValue);
213 | }
214 | }
215 | }
216 |
217 | getStyles = (mode) => {
218 | if (mode === -1) {
219 | return {
220 | justifyContent:'flex-start',
221 | width: 29,
222 | };
223 | } else if (mode === 1) {
224 | return {
225 | justifyContent:'flex-end',
226 | width: 32,
227 | };
228 | }
229 | return {
230 | alignItems: 'center',
231 | width: 40,
232 | };
233 | }
234 |
235 | renderThumbSides = (thumbSide, isSmall, thumbTintColor) => {
236 | const leftSide = (
237 |