SliderView.js
2.28 KB
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
import React, {Component} from 'react';
import {
View,
Text,
Slider
} from 'react-native';
const defaultHeight = (70);
const HPading = (16);
const VPading = (6);
export default class SliderView extends Component {
constructor(props) {
super(props);
this.state = {
sliderValue: 0,
};
this.attrData = this.props.attrData;
this.onComplete = this.props.onComplete;
this.extendData = JSON.parse(this.attrData.data);
}
componentWillMount() {
let defaultValue = this.extendData.default;
this.setState({
sliderValue: 0
})
}
render() {
let {name, code, type, description, isRequired, isPreview} = this.attrData;
let {step, minValue, maxValue, showSpaceDot, rangeSlide} = this.extendData;
return(
<View style={{width: '100%', backgroundColor: 'white', height:defaultHeight,paddingTop: VPading,paddingHorizontal:HPading}}>
<View style={{flexDirection: 'row'}}>
{isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
{!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
<Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)', marginBottom: 5}}>{name||""}</Text>
<Text style={{flex: 1, fontSize: 16, color: 'rgba(0, 0, 0 , 1)', marginHorizontal: 10, textAlign: 'right'}}>
{Number.isInteger(this.state.sliderValue)? this.state.sliderValue+"": parseFloat(this.state.sliderValue).toFixed(2)}</Text>
</View>
<Slider
style={{width: '100%', marginTop: 5}}
value={this.state.sliderValue}
minimumValue={minValue||0}
maximumValue={maxValue||100}
step={Number(step)}
showSpaceDot={showSpaceDot}
rangeSlide={rangeSlide}
onValueChange={(value) => {
this.setState({
sliderValue: value
})
}}
onSlidingComplete={value => this.attrData.value = value}
//thumbImage={}
/>
</View>
);
}
}