index.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { useEffect, useRef } from 'react';
  2. import { View, Image, Text, TouchableOpacity, Platform } from 'react-native';
  3. import { Marker, Callout, CalloutSubview, MapMarker } from 'react-native-maps';
  4. import CustomCallout from '../CustomCallout';
  5. import { styles } from './styles';
  6. import { ItemSeries } from '../../../../types/map';
  7. import { Colors } from 'src/theme';
  8. import CheckSvg from 'assets/icons/mark.svg';
  9. const MarkerItem = ({
  10. marker,
  11. iconUrl,
  12. coordinate,
  13. seriesName,
  14. toggleSeries,
  15. token
  16. }: {
  17. marker: ItemSeries;
  18. iconUrl: string;
  19. coordinate?: any;
  20. seriesName: string;
  21. toggleSeries: (item: any) => void;
  22. token: string;
  23. }) => {
  24. let markerRef = useRef<MapMarker>(null);
  25. useEffect(() => {
  26. if (markerRef.current && Platform.OS !== 'ios') {
  27. markerRef.current?.showCallout();
  28. }
  29. }, [marker.visited]);
  30. return (
  31. <>
  32. <Marker coordinate={coordinate} tracksViewChanges={false} ref={markerRef}>
  33. <View
  34. style={[
  35. styles.markerContainer,
  36. (marker.visited === 1 && token && { backgroundColor: Colors.ORANGE }) || {}
  37. ]}
  38. >
  39. <Image source={{ uri: iconUrl }} style={styles.icon} resizeMode="contain" />
  40. </View>
  41. {Platform.OS === 'ios' ? (
  42. <Callout tooltip style={styles.customView}>
  43. <View style={styles.calloutContainer}>
  44. <View style={styles.calloutImageContainer}>
  45. <Image source={{ uri: iconUrl }} style={styles.calloutImage} resizeMode="contain" />
  46. </View>
  47. <View style={styles.calloutTextContainer}>
  48. <Text style={styles.seriesName}>{seriesName}</Text>
  49. <Text style={styles.markerName}>{marker.name}</Text>
  50. </View>
  51. <CalloutSubview
  52. style={[
  53. styles.calloutButton,
  54. (marker.visited === 1 &&
  55. token && {
  56. backgroundColor: Colors.WHITE,
  57. borderWidth: 1,
  58. borderColor: Colors.BORDER_LIGHT
  59. }) ||
  60. {}
  61. ]}
  62. onPress={() => toggleSeries(marker)}
  63. >
  64. {marker?.visited === 1 && token ? (
  65. <View style={styles.completedContainer}>
  66. <CheckSvg width={14} height={14} fill={Colors.DARK_BLUE} />
  67. <Text style={[styles.calloutButtonText, { color: Colors.DARK_BLUE }]}>
  68. Completed
  69. </Text>
  70. </View>
  71. ) : (
  72. <Text style={styles.calloutButtonText}>Mark Completed</Text>
  73. )}
  74. </CalloutSubview>
  75. </View>
  76. </Callout>
  77. ) : (
  78. <CustomCallout
  79. marker={marker}
  80. toggleSeries={toggleSeries}
  81. seriesName={seriesName}
  82. token={token}
  83. />
  84. )}
  85. </Marker>
  86. </>
  87. );
  88. };
  89. export default MarkerItem;