FiveStarView.js
2.83 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
import React, {Component} from 'react';
import {
View,
Text,
Image,
TouchableOpacity,
TouchableWithoutFeedback
} from 'react-native';
import {observer} from "mobx-react/native";
import {observable} from "mobx";
import {width} from "../utils/getSize";
import {NoDoublePress} from "../utils/Common";
@observer
export default class FiveStarView extends Component {
@observable
star = !!this.data.star?this.data.star:0
constructor(props) {
super(props);
this.state = {
data: {star: 2}
}
this.title = this.props.title || "评分";
}
render() {
const starMap = [1, 2, 3, 4, 5];
return(
<View style={{backgroundColor: "white", paddingHorizontal: 5, paddingVertical: 10}}>
<View style={{flexDirection: 'row', alignItems: 'center'}}>
<Text style={{flex: 1, fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{this.title}</Text>
{this.state.data && this.state.data.star > 0 &&
<TouchableOpacity
style={{paddingHorizontal: 10}}
activeOpacity={0.8}
onPress={() => {
this.setState({
data: {star: 0}
})
}}
>
<Text style={{fontSize: 16, color: global.homeColor}}>清除</Text>
</TouchableOpacity>
}
</View>
<View style={[{height:25, width: width, flexDirection:'row', justifyContent:'flex-start',alignItems:'center'}]}>
{starMap.map((item,loop)=>{
return (
<TouchableWithoutFeedback key={loop} onPress={()=>NoDoublePress.onPress(()=>{
//this.state.data.star = loop+1;
let _temp = this.state.data;
_temp.star = loop+1;
this.setState({
data: _temp
})
//this.data = loop+1;
})}>
<Image source={this.state.data.star > loop?require('../img/star_on.png'):
require('../img/star_off.png')} style={{height: 20,width: 20,marginRight: 8}} resizeMode={"contain"}/>
</TouchableWithoutFeedback>
)
})}
{/*<Text style={{fontSize:setSpText2(12),color:'#999999'}}>
{this.logic.getStarStr(this.data)}
</Text>*/}
</View>
</View>
)
}
}