MessageLocation.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React, { useRef } from 'react';
  2. import { View, TouchableOpacity, StyleSheet } from 'react-native';
  3. import * as MapLibreRN from '@maplibre/maplibre-react-native';
  4. import { useNavigation } from '@react-navigation/native';
  5. import { Colors } from 'src/theme';
  6. import { VECTOR_MAP_HOST } from 'src/constants';
  7. import { NAVIGATION_PAGES } from 'src/types';
  8. const MessageLocation = ({
  9. props,
  10. lat,
  11. lng,
  12. onLongPress
  13. }: {
  14. props: any;
  15. lat: number;
  16. lng: number;
  17. onLongPress: (currentMessage: any, props: any) => void;
  18. }) => {
  19. const navigation = useNavigation();
  20. const mapRef = useRef<MapLibreRN.MapViewRef>(null);
  21. const cameraRef = useRef<MapLibreRN.CameraRef>(null);
  22. return (
  23. <TouchableOpacity
  24. style={styles.container}
  25. onPress={() =>
  26. navigation.navigate(...([NAVIGATION_PAGES.FULL_MAP_VIEW, { lat, lng }] as never))
  27. }
  28. onLongPress={() => onLongPress(props.currentMessage, props)}
  29. >
  30. <MapLibreRN.MapView
  31. ref={mapRef}
  32. style={styles.map}
  33. mapStyle={VECTOR_MAP_HOST + '/nomadmania-maps.json'}
  34. rotateEnabled={false}
  35. attributionEnabled={false}
  36. scrollEnabled={false}
  37. zoomEnabled={false}
  38. pitchEnabled={false}
  39. >
  40. <MapLibreRN.Camera
  41. ref={cameraRef}
  42. defaultSettings={{ centerCoordinate: [lng, lat], zoomLevel: 10 }}
  43. />
  44. <MapLibreRN.MarkerView coordinate={[lng, lat]}>
  45. <View
  46. style={{
  47. width: 20,
  48. height: 20,
  49. borderRadius: 10,
  50. backgroundColor: Colors.ORANGE,
  51. borderWidth: 2,
  52. borderColor: Colors.WHITE
  53. }}
  54. />
  55. </MapLibreRN.MarkerView>
  56. </MapLibreRN.MapView>
  57. </TouchableOpacity>
  58. );
  59. };
  60. const styles = StyleSheet.create({
  61. container: {
  62. width: '100%',
  63. height: 150,
  64. borderRadius: 10,
  65. overflow: 'hidden'
  66. },
  67. map: {
  68. flex: 1
  69. }
  70. });
  71. export default MessageLocation;