BooleanCheckView.js
3.13 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
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
import React, {Component} from 'react';
import {
View,
Text,
TouchableOpacity,
Image,
} from 'react-native';
const checkedImg = require("../img/switch_on.png");
const unCheckedImg = require("../img/switch_off.png");
const HPading = (16);
export default class BooleanCheckView extends Component {
constructor(props) {
super(props);
this.state = {
checked: true
}
this.attrData = this.props.attrData;
this.extendData = JSON.parse(this.attrData.data);// null=无|true=是|false=否
}
componentWillMount() {
this.setState({
checked: this.extendData.booleanDefault
})
this.attrData.value = this.extendData.booleanDefault;
}
render() {
let {name, code, type, description, isRequired, isPreview} = this.attrData;
return (
<View style={{flexDirection: 'row', width: '100%', height: 46, backgroundColor: 'white', alignItems: 'center', paddingHorizontal: HPading}}>
<View style={{flexDirection: 'row',justifyContent:'flex-start',alignItems:'center'}}>
{isRequired&&<Text style={{ color: "#FF3030" }}>* {" "}</Text>}
{!isRequired&&<Text style={{ color: "#fff" }}>* {" "}</Text>}
<Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{name||""}</Text>
</View>
<TouchableOpacity
activeOpacity={0.8}
onPress={()=>{
let _checked = !this.state.checked;
this.setState({
checked: _checked
});
this.attrData.value = _checked;
}}
>
<Image
source={this.state.checked ? checkedImg : unCheckedImg}
style={{
width: 86,
height: 28,
marginLeft: 8,
marginRight: 8
}}
resizeMode={'contain'}
/>
</TouchableOpacity>
{/*<TouchableOpacity
style={{marginLeft: 10, flexDirection: 'row', alignItems: 'center'}}
activeOpacity={0.8}
onPress={()=>{
this.setState({
checked: false
});
this.attrData.value = "否";
}}
>
<Image
source={(this.state.checked !== null && !this.state.checked) ? checkedImg : unCheckedImg}
style={{
width: 20,
height: 20,
marginLeft: 8,
marginRight: 8
}}
/>
<Text style={{fontSize: 14, color: 'rgba(0, 0, 0 , 1)', paddingVertical: 10}}>否</Text>
</TouchableOpacity>*/}
</View>
);
}
}