123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import { useEffect, useRef } from 'react';
- import { View, Image, Text, TouchableOpacity, Platform } from 'react-native';
- import { styles } from './styles';
- import { Colors } from 'src/theme';
- import CheckSvg from 'assets/icons/mark.svg';
- import MapLibreGL, { PointAnnotationRef } from '@maplibre/maplibre-react-native';
- const MarkerItem = ({
- marker,
- toggleSeries,
- token
- }: {
- marker: any;
- toggleSeries: (item: any) => void;
- token: string;
- }) => {
- const calloutRef = useRef<PointAnnotationRef>(null);
- useEffect(() => {
- if (Platform.OS === 'android') {
- calloutRef.current?.refresh();
- }
- }, [marker]);
- return (
- <>
- {Platform.OS === 'ios' ? (
- <MapLibreGL.PointAnnotation
- id="selected_marker_callout"
- coordinate={marker.coordinates}
- anchor={{ x: 0.5, y: 1 }}
- >
- <View style={styles.customView}>
- <View style={styles.calloutContainer}>
- <View style={styles.calloutImageContainer}>
- <Image
- source={{ uri: marker.icon.uri }}
- style={styles.calloutImage}
- resizeMode="contain"
- />
- </View>
- <View style={styles.calloutTextContainer}>
- <Text style={styles.seriesName}>{marker.series_name}</Text>
- <Text style={styles.markerName}>{marker.name}</Text>
- </View>
- <TouchableOpacity
- style={[
- styles.calloutButton,
- (marker.visited === 1 &&
- token && {
- backgroundColor: Colors.WHITE,
- borderWidth: 1,
- borderColor: Colors.BORDER_LIGHT
- }) ||
- {}
- ]}
- onPress={() => toggleSeries(marker)}
- >
- {marker?.visited === 1 && token ? (
- <View style={styles.completedContainer}>
- <CheckSvg width={14} height={14} fill={Colors.DARK_BLUE} />
- <Text style={[styles.calloutButtonText, { color: Colors.DARK_BLUE }]}>
- Completed
- </Text>
- </View>
- ) : (
- <Text style={styles.calloutButtonText}>Mark Completed</Text>
- )}
- </TouchableOpacity>
- </View>
- </View>
- </MapLibreGL.PointAnnotation>
- ) : (
- <MapLibreGL.PointAnnotation
- id="selected_marker_callout"
- coordinate={marker.coordinates}
- anchor={{ x: 0.5, y: 0.9 }}
- onSelected={() => toggleSeries(marker)}
- selected={true}
- ref={calloutRef}
- >
- <View style={styles.customView}>
- <View style={styles.calloutContainer}>
- <View style={styles.calloutImageContainer}>
- <Image
- source={{ uri: marker.icon.uri }}
- style={styles.calloutImage}
- resizeMode="contain"
- />
- </View>
- <View style={styles.calloutTextContainer}>
- <Text style={styles.seriesName}>{marker.series_name}</Text>
- <Text style={styles.markerName}>{marker.name}</Text>
- </View>
- <TouchableOpacity
- style={[
- styles.calloutButton,
- (marker.visited === 1 &&
- token && {
- backgroundColor: Colors.WHITE,
- borderWidth: 1,
- borderColor: Colors.BORDER_LIGHT
- }) ||
- {}
- ]}
- onPress={() => toggleSeries(marker)}
- >
- {marker?.visited === 1 && token ? (
- <View style={styles.completedContainer}>
- <CheckSvg width={14} height={14} fill={Colors.DARK_BLUE} />
- <Text style={[styles.calloutButtonText, { color: Colors.DARK_BLUE }]}>
- Completed
- </Text>
- </View>
- ) : (
- <Text style={styles.calloutButtonText}>Mark Completed</Text>
- )}
- </TouchableOpacity>
- </View>
- </View>
- </MapLibreGL.PointAnnotation>
- )}
- </>
- );
- };
- export default MarkerItem;
|