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