forked from ptomasroos/react-native-multi-slider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultLabel.js
82 lines (72 loc) · 2.07 KB
/
DefaultLabel.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
import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
const sliderRadius = 3;
const width = 50;
export default class DefaultLabel extends React.Component {
static propTypes = {
oneMarkerValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
twoMarkerValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
oneMarkerLeftPosition: PropTypes.number,
twoMarkerLeftPosition: PropTypes.number,
oneMarkerPressed: PropTypes.bool,
twoMarkerPressed: PropTypes.bool,
};
render() {
const {
oneMarkerValue,
twoMarkerValue,
oneMarkerLeftPosition,
twoMarkerLeftPosition,
oneMarkerPressed,
twoMarkerPressed,
} = this.props;
return (
<View style={{ position: 'relative' }}>
{Number.isFinite(oneMarkerLeftPosition) &&
Number.isFinite(oneMarkerValue) && (
<View
style={[
styles.sliderLabel,
{ left: oneMarkerLeftPosition - width / 2 + sliderRadius },
oneMarkerPressed && styles.markerPressed,
]}
>
<Text style={styles.sliderLabelText}>{oneMarkerValue}</Text>
</View>
)}
{Number.isFinite(twoMarkerLeftPosition) &&
Number.isFinite(twoMarkerValue) && (
<View
style={[
styles.sliderLabel,
{ left: twoMarkerLeftPosition - width / 2 + sliderRadius },
twoMarkerPressed && styles.markerPressed,
]}
>
<Text style={styles.sliderLabelText}>{twoMarkerValue}</Text>
</View>
)}
</View>
);
}
}
const styles = StyleSheet.create({
sliderLabel: {
position: 'absolute',
bottom: 0,
minWidth: width,
padding: 8,
backgroundColor: '#f1f1f1',
},
sliderLabelText: {
alignItems: 'center',
textAlign: 'center',
fontStyle: 'normal',
fontSize: 11,
},
markerPressed: {
borderWidth: 2,
borderColor: '#999',
},
});