RateBar.js 4.65 KB
import React,{ useState } from 'react';
import { Surface, Text ,HelperText} from 'react-native-paper';
import { StyleSheet,View } from 'react-native';
import { PieChart } from 'react-native-svg-charts';
import PromptSearchRate from '../PromptSearch/PromptSearchRate';

export default RateBar = (props) => {
    const [ click,setClick ] = useState(0);

    return (
        <Surface style={styles.surface}>
            
            {props.score.msg ?
            <>
            <View style={styles.container}>
                <Text style={styles.Text}> 점수 : {props.score.full}</Text>
            </View>

            <View style={styles.container}>                   
                <Text style={styles.message}>눌러서 각각의 점수를 알아보세요</Text>             
            </View>
            <View style={styles.infoContainer}>
                <HelperText type={'info'} visible={click==2} style={styles.helper}>맞춤법 : {props.score.fix}</HelperText>
                <HelperText type={'info'} visible={click==1} style={styles.helper}>키워드 : {props.score.key}</HelperText>             
            </View>
            <View style={styles.chartContatiner}>
                <View>
                    <PieChart
                        style={ styles.chart }
                        data={[{
                                value: props.score.key,
                                svg:{
                                    fill : '#e85a71',
                                    onPressIn: () => {setClick(1)},
                                    onPressOut: ()=>{setClick(0)}
                                },
                                key: "키워드"                            
                                },
                                {
                                value: props.score.fix,
                                svg: {
                                    fill : '#d8e9ef',
                                    onPressIn: () => {setClick(2)},
                                    onPressOut: ()=>{setClick(0)}
                                },
                                key: "맞춤법" 
                                }, 
                                {
                                value: (100-(props.score.key+props.score.fix)),
                                key : ""
                                }
                        ]}
                        innerRadius={"50%"}
                    />
                </View>                
                <View style={styles.colorContainer}>
                        <View style={styles.textContainer}>
                            <View style={styles.colorA}></View><Text>키워드 점수</Text>
                        </View>
                        <View style={styles.textContainer}>
                            <View style={styles.colorB}></View><Text>맞춤법 점수</Text>
                        </View>                                             
                </View>
            </View>
            </>
            : <PromptSearchRate />}
        </Surface>
        
     );
}



const styles = StyleSheet.create({
    container:{
        width: '100%',
        flexDirection:'row',
        justifyContent:'center',
        marginTop : 3,
    },
    colorContainer:{
        position:"absolute",
        right:20,
    },
    colorA:{
        backgroundColor:'#e85a71',
        height: 7,
        width: 7,
        marginRight: 5,
        fontFamily:"Regular",
        fontSize: 13,
    },
    colorB:{
        backgroundColor:'#d8e9ef', 
        height: 7,
        width: 7,
        marginRight: 5,
        fontFamily:"Regular",
        fontSize: 13,
    },
    chartContatiner:{
        flexDirection:'row',
        justifyContent:"flex-start",
        alignItems:'flex-start',
        marginBottom: 10,
    },
    chart:{
        height: 125, 
        width:"100%",
        position:"absolute",
    },
    textContainer:{
        flexDirection:'row',
        justifyContent:'center',
        alignItems:'center',
        fontFamily:"Bold",
    },
    infoContainer:{
        flexDirection:'row',
        justifyContent:'center',
        alignItems:'center',
        width: '100%'
    },
    surface: {
        paddingTop: 10,
        paddingBottom:0,
        flex: 0.55,
        width: '95%',
        flexDirection:'column',
        alignItems: "center",
        justifyContent: 'flex-start',
        elevation: 2,
        marginTop: 10,
        borderRadius: 5
    },
    Text:{
        fontSize: 22,
        marginBottom:5,
        fontFamily:"Bold",
    },
    message:{
        fontFamily:"Pen",
        fontSize: 20,
        marginBottom: 3,
    },
    helper:{
        fontFamily:"Bold",
        fontSize:15
    }
});