-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRangeSlider.tsx
126 lines (121 loc) · 3.19 KB
/
RangeSlider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React from 'react';
import { Platform, requireNativeComponent } from 'react-native';
import { RangeSliderProps, RangeSliderChangeEvent } from './types';
const Slider = requireNativeComponent('RNRangeSlider');
const RangeSlider: React.FC<RangeSliderProps> = ({
min,
max,
onChange,
tintColor,
tintColorBetweenHandles,
step,
handleBorderColor,
handleColor,
handleDiameter,
handleBorderWidth,
type = 'range',
selectedMaximum,
selectedMinimum,
minLabelColor,
maxLabelColor,
lineHeight,
prefix,
suffix,
hideLabels,
maxLabelFont,
minLabelFont,
maxLabelFontSize,
minLabelFontSize,
lineBorderWidth,
lineBorderColor,
labelPadding,
minDistance,
maxDistance,
leftHandleColor,
rightHandleColor,
leftHandlePressedColor,
rightHandlePressedColor,
handlePressedColor,
minStartValue,
maxStartValue,
fixGap,
style = {},
cornerRadius,
}: RangeSliderProps) => {
const defaultStyle = {
width: '100%',
height: 70,
};
const handleChange = ({ nativeEvent }: RangeSliderChangeEvent) => {
onChange && onChange(nativeEvent.min, nativeEvent.max);
};
if (Platform.OS === 'android') {
return (
<Slider
min={Number(min)}
max={Number(max)}
step={Number(step)}
tintColor={tintColor}
tintColorBetweenHandles={tintColorBetweenHandles}
handleColor={handleColor}
onChange={handleChange}
leftHandleColor={leftHandleColor}
rightHandleColor={rightHandleColor}
minStartValue={minStartValue}
maxStartValue={maxStartValue}
fixGap={fixGap}
leftHandlePressedColor={leftHandlePressedColor}
rightHandlePressedColor={rightHandlePressedColor}
handlePressedColor={handlePressedColor || handleColor}
cornerRadius={cornerRadius}
prefix={prefix}
suffix={suffix}
style={[defaultStyle, style]}
/>
);
} else {
return (
<Slider
disableRange={type === 'slider'}
minValue={Number(min)}
maxValue={Number(max)}
step={Number(step)}
selectedMaximum={selectedMaximum}
selectedMinimum={selectedMinimum}
tintColor={tintColor}
tintColorBetweenHandles={tintColorBetweenHandles}
handleBorderColor={handleBorderColor}
handleBorderWidth={handleBorderWidth}
handleColor={handleColor}
handleDiameter={handleDiameter}
minLabelColour={minLabelColor}
minLabelFont={minLabelFont}
minLabelFontSize={minLabelFontSize}
maxLabelFont={maxLabelFont}
maxLabelFontSize={maxLabelFontSize}
maxLabelColour={maxLabelColor}
lineHeight={lineHeight}
lineBorderWidth={lineBorderWidth}
lineBorderColor={lineBorderColor}
prefix={prefix}
suffix={suffix}
hideLabels={hideLabels}
labelPadding={labelPadding}
minDistance={minDistance}
maxDistance={maxDistance}
onChange={handleChange}
style={[defaultStyle, style]}
/>
);
}
};
RangeSlider.defaultProps = {
min: 0,
max: 100,
step: 1,
type: 'range',
selectedMinimum: 0,
selectedMaximum: 100,
tintColor: '#DCDCDC', // extra light gray
};
export default RangeSlider;