-
Notifications
You must be signed in to change notification settings - Fork 44
/
sliders.js
131 lines (116 loc) · 2.93 KB
/
sliders.js
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
127
128
129
130
131
/**
* Created by ywu on 15/8/31.
*/
import React, { Component, createRef } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { MKColor, Slider, RangeSlider, setTheme } from 'react-native-material-kit';
import appStyles from './styles';
// customize the material design theme
// setTheme({
// primaryColor: MKColor.Orange,
// });
const styles = Object.assign(
{},
appStyles,
StyleSheet.create({
slider: {
width: 130,
},
})
);
class ValueText extends Component {
constructor(props) {
super(props);
this.state = {
curValue: props.initial,
};
}
onChange(curValue) {
this.setState({ curValue });
}
render() {
return (
<Text style={styles.legendLabel}>
{this.state.curValue} ({this.props.rangeText})
</Text>
);
}
}
class Sliders extends Component {
sliderWithValue = createRef();
rangeSlider = createRef();
valueText = createRef();
rangeValueText = createRef();
componentDidMount() {
const slider = this.sliderWithValue.current;
// const ranged = this.rangeSlider.current;
setTimeout(() => {
if (slider) {
slider.value = 75;
}
// if (ranged) {
// ranged.maxValue = 95;
// }
}, 1000);
}
render() {
return (
<View
style={[
styles.scrollView,
{
marginTop: 120,
},
]}
contentContainerStyle={styles.container}
>
<View style={styles.row}>
<View style={styles.col}>
<Slider style={styles.slider} />
<Text style={styles.legendLabel}>Slider</Text>
</View>
<View style={styles.col}>
<Slider
ref={this.sliderWithValue}
min={10}
max={100}
value={25}
style={styles.slider}
onChange={this._onChange}
/>
<ValueText ref={this.valueText} initial="25.00" rangeText="10~100" />
</View>
</View>
<View style={styles.row}>
<View style={styles.col}>
<RangeSlider style={styles.slider} />
<Text style={styles.legendLabel}>Range Slider</Text>
</View>
<View style={styles.col}>
<RangeSlider
ref={this.rangeSlider}
range={{ min: 20, max: 75 }}
step={5}
style={styles.slider}
onChange={this._onRangeChange}
/>
<ValueText ref={this.rangeValueText} initial="20.00-75.00" rangeText="10~100" />
</View>
</View>
</View>
);
}
_onChange = value => {
const text = this.valueText.current;
if (text) {
text.onChange(value.toFixed(2));
}
};
_onRangeChange = range => {
const text = this.rangeValueText.current;
if (text) {
text.onChange(range.min.toFixed(2) + '-' + range.max.toFixed(2));
}
};
}
export default Sliders;