KickMarkerComponent.js 4.31 KB
import React from "react";
import {View, Text, Image} from "react-native";
import {Callout, Marker} from "react-native-maps";
import {useNavigation} from '@react-navigation/native';
import SquareButtonComponent from "./Base/SquareButtonComponent";
import {BUTTON_COLOR} from "../constant";

const KickMarkerComponent = (props) => {
    const navigation = useNavigation();

    // 데이터
    const {markerImage, serviceNumber, nameOfService, infoOfService, kickLocationMarker, index, minIndex, servicePrice, getPath} = props;

    // 함수
    const goToMyPage = () => {
        navigation.navigate('이킥저킥');
    };

    // 렌더링
    return (
        <Marker coordinate={{
                    latitude: parseFloat(kickLocationMarker.coordinate.latitude),
                    longitude: parseFloat(kickLocationMarker.coordinate.longitude),
                }}
                onPress={() => getPath(serviceNumber, {
                    title: kickLocationMarker.title,
                    coordinate: {
                        latitude: parseFloat(kickLocationMarker.coordinate.latitude),
                        longitude: parseFloat(kickLocationMarker.coordinate.longitude),
                    }
                })}
                opacity={index === minIndex ? 1.0 : 0.6}
        >
            {serviceNumber === 0
                ?
                <Image source={require('../assets/gcooter.png')} style={{height: 35, width: 35, borderRadius: 50}}/>
                :
                serviceNumber === 1
                    ?
                    <Image source={require('../assets/flower_road.png')}
                           style={{height: 35, width: 35, borderRadius: 50}}/>
                    :
                    <Image source={require('../assets/ssing_ssing.png')}
                           style={{height: 35, width: 35, borderRadius: 50}}/>
            }
            <Callout tooltip={true}
                     style={{width: 200}} onPress={goToMyPage}>
                <View style={{backgroundColor: '#ffffff', paddingLeft: 10, paddingRight: 10, paddingTop: 10, paddingBottom: 5, borderRadius: 5}}>
                    <View style={{
                        backgroundColor: '#ebebeb',
                        padding: 5,
                        marginBottom: 10,
                        borderRadius: 5
                    }}>
                        <Text style={{
                            fontSize: 16,
                            color: '#373737',
                            fontWeight: 'bold',
                            textAlign: 'center'
                        }}>
                            {index === minIndex ? '가까운' : ''} {nameOfService}
                        </Text>
                        {index === minIndex
                            ?
                            <Text style={{
                                fontSize: 16,
                                color: '#373737',
                                fontWeight: 'bold',
                                textAlign: 'center'
                            }}>
                                예상비용 {servicePrice}
                            </Text>
                            :
                            <></>}
                    </View>
                    <Text style={{fontSize: 14, color: '#373737'}}>
                        남은 배터리 {kickLocationMarker.title}%
                    </Text>
                    <Text style={{fontSize: 14, color: '#373737'}}>
                        {infoOfService}
                    </Text>
                    <SquareButtonComponent
                        text={'대여하기'}
                        style1={{
                            marginLeft: 0,
                            marginRight: 0,
                            marginTop: 5,
                            marginBottom: 5,
                            padding: 5,
                            borderRadius: 3,
                            backgroundColor: BUTTON_COLOR
                        }}
                        style2={{
                            fontSize: 16,
                            fontWeight: 'bold',
                            textAlign: 'center',
                            color: '#ffffff'
                        }}
                    />
                </View>
            </Callout>
        </Marker>
    );
};

export default KickMarkerComponent;