FiveStarView.js 3.04 KB
import React, {Component} from 'react';
import {
    View,
    Text,
    Image,
    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 || "评分";
    }

    onPress(v){
        this.data.star=v
    }

    starItem = (v, i) => {
        const icon=(v>this.data.star)?require("../img/star_off.png"):require("../img/star_on.png")
        return (
            <TouchableWithoutFeedback onPress={()=>{this.onPress(v)}} key={v}>
                <Image source={icon} style={styles.starImg} resizeMode={"contain"}/>
            </TouchableWithoutFeedback>
        )
    };

    imgItem=(v,i)=>{
        return(
            <View style = {{height:74,width:74,justifyContent:'flex-end',marginRight:8}}>
                <Image source={{uri:v}} resizeMode={"cover"} style={[styles.img]} imageStyle = {{borderRadius:4}} key={i}></Image>
                <TouchableOpacity  style = {{position:'absolute',top:0,right:0}}onPress={()=>this.props.data.imgs.remove(v)}>
                    <Image  resizeMode={"contain"} style={styles.imgIcon} source={iv_shut}/>
                </TouchableOpacity>
            </View>

        )
    }

    render() {
        const starMap = [1, 2, 3, 4, 5];
        return(
            <View style={{backgroundColor: "white", paddingHorizontal: 5, paddingVertical: 10}}>
                <Text style={{fontSize: 16, color: 'rgba(0, 0, 0, 1)'}}>{this.title}</Text>
                <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>
        )
    }
}