index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { useEffect, useRef } from 'react';
  2. import { View, Image, Text, TouchableOpacity, Platform } from 'react-native';
  3. import { styles } from './styles';
  4. import { Colors } from 'src/theme';
  5. import CheckSvg from 'assets/icons/mark.svg';
  6. import MapLibreGL, { PointAnnotationRef } from '@maplibre/maplibre-react-native';
  7. const MarkerItem = ({
  8. marker,
  9. toggleSeries,
  10. token
  11. }: {
  12. marker: any;
  13. toggleSeries: (item: any) => void;
  14. token: string;
  15. }) => {
  16. const calloutRef = useRef<PointAnnotationRef>(null);
  17. useEffect(() => {
  18. if (Platform.OS === 'android') {
  19. calloutRef.current?.refresh();
  20. }
  21. }, [marker]);
  22. return (
  23. <>
  24. {Platform.OS === 'ios' ? (
  25. <MapLibreGL.PointAnnotation
  26. id="selected_marker_callout"
  27. coordinate={marker.coordinates}
  28. anchor={{ x: 0.5, y: 1 }}
  29. >
  30. <View style={styles.customView}>
  31. <View style={styles.calloutContainer}>
  32. <View style={styles.calloutImageContainer}>
  33. <Image
  34. source={{ uri: marker.icon.uri }}
  35. style={styles.calloutImage}
  36. resizeMode="contain"
  37. />
  38. </View>
  39. <View style={styles.calloutTextContainer}>
  40. <Text style={styles.seriesName}>{marker.series_name}</Text>
  41. <Text style={styles.markerName}>{marker.name}</Text>
  42. </View>
  43. <TouchableOpacity
  44. style={[
  45. styles.calloutButton,
  46. (marker.visited === 1 &&
  47. token && {
  48. backgroundColor: Colors.WHITE,
  49. borderWidth: 1,
  50. borderColor: Colors.BORDER_LIGHT
  51. }) ||
  52. {}
  53. ]}
  54. onPress={() => toggleSeries(marker)}
  55. >
  56. {marker?.visited === 1 && token ? (
  57. <View style={styles.completedContainer}>
  58. <CheckSvg width={14} height={14} fill={Colors.DARK_BLUE} />
  59. <Text style={[styles.calloutButtonText, { color: Colors.DARK_BLUE }]}>
  60. Completed
  61. </Text>
  62. </View>
  63. ) : (
  64. <Text style={styles.calloutButtonText}>Mark Completed</Text>
  65. )}
  66. </TouchableOpacity>
  67. </View>
  68. </View>
  69. </MapLibreGL.PointAnnotation>
  70. ) : (
  71. <MapLibreGL.PointAnnotation
  72. id="selected_marker_callout"
  73. coordinate={marker.coordinates}
  74. anchor={{ x: 0.5, y: 0.9 }}
  75. onSelected={() => toggleSeries(marker)}
  76. selected={true}
  77. ref={calloutRef}
  78. >
  79. <View style={styles.customView}>
  80. <View style={styles.calloutContainer}>
  81. <View style={styles.calloutImageContainer}>
  82. <Image
  83. source={{ uri: marker.icon.uri }}
  84. style={styles.calloutImage}
  85. resizeMode="contain"
  86. />
  87. </View>
  88. <View style={styles.calloutTextContainer}>
  89. <Text style={styles.seriesName}>{marker.series_name}</Text>
  90. <Text style={styles.markerName}>{marker.name}</Text>
  91. </View>
  92. <TouchableOpacity
  93. style={[
  94. styles.calloutButton,
  95. (marker.visited === 1 &&
  96. token && {
  97. backgroundColor: Colors.WHITE,
  98. borderWidth: 1,
  99. borderColor: Colors.BORDER_LIGHT
  100. }) ||
  101. {}
  102. ]}
  103. onPress={() => toggleSeries(marker)}
  104. >
  105. {marker?.visited === 1 && token ? (
  106. <View style={styles.completedContainer}>
  107. <CheckSvg width={14} height={14} fill={Colors.DARK_BLUE} />
  108. <Text style={[styles.calloutButtonText, { color: Colors.DARK_BLUE }]}>
  109. Completed
  110. </Text>
  111. </View>
  112. ) : (
  113. <Text style={styles.calloutButtonText}>Mark Completed</Text>
  114. )}
  115. </TouchableOpacity>
  116. </View>
  117. </View>
  118. </MapLibreGL.PointAnnotation>
  119. )}
  120. </>
  121. );
  122. };
  123. export default MarkerItem;