MessageLocation.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.MapRef>(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.Map
  31. ref={mapRef}
  32. style={styles.map}
  33. mapStyle={VECTOR_MAP_HOST + '/nomadmania-maps2025.json'}
  34. touchRotate={false}
  35. attribution={false}
  36. dragPan={false}
  37. touchZoom={false}
  38. doubleTapZoom={false}
  39. doubleTapHoldZoom={false}
  40. touchPitch={false}
  41. >
  42. <MapLibreRN.Camera
  43. ref={cameraRef}
  44. initialViewState={{ center: [lng, lat], zoom: 10 }}
  45. />
  46. <MapLibreRN.Marker lngLat={[lng, lat]}>
  47. <View
  48. style={{
  49. width: 20,
  50. height: 20,
  51. borderRadius: 10,
  52. backgroundColor: Colors.ORANGE,
  53. borderWidth: 2,
  54. borderColor: Colors.WHITE
  55. }}
  56. />
  57. </MapLibreRN.Marker>
  58. </MapLibreRN.Map>
  59. </TouchableOpacity>
  60. );
  61. };
  62. const styles = StyleSheet.create({
  63. container: {
  64. width: '100%',
  65. height: 150,
  66. borderRadius: 10,
  67. overflow: 'hidden'
  68. },
  69. map: {
  70. flex: 1
  71. }
  72. });
  73. export default MessageLocation;