Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/MapView/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
const [isIdle, setIsIdle] = useState(false);
const [currentPosition, setCurrentPosition] = useState(cachedUserLocation);
const [userInteractedWithMap, setUserInteractedWithMap] = useState(false);
const hasStartedGettingCurrentPosition = useRef(false);

useFocusEffect(
useCallback(() => {
if (isOffline) {
return;
}

if (hasStartedGettingCurrentPosition.current) {
return;
}

hasStartedGettingCurrentPosition.current = true;

getCurrentPosition(
(params) => {
const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude};
Expand Down
9 changes: 8 additions & 1 deletion src/components/MapView/MapView.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {useFocusEffect} from '@react-navigation/native';
import mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useState} from 'react';
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import Map, {MapRef, Marker} from 'react-map-gl';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -47,6 +47,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
const [currentPosition, setCurrentPosition] = useState(cachedUserLocation);
const [userInteractedWithMap, setUserInteractedWithMap] = useState(false);
const [shouldResetBoundaries, setShouldResetBoundaries] = useState<boolean>(false);
const hasStartedGettingCurrentPosition = useRef(false);
const setRef = useCallback((newRef: MapRef | null) => setMapRef(newRef), []);

useFocusEffect(
Expand All @@ -55,6 +56,12 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
return;
}

if (hasStartedGettingCurrentPosition.current) {
return;
}

hasStartedGettingCurrentPosition.current = true;

getCurrentPosition(
(params) => {
const currentCoords = {longitude: params.coords.longitude, latitude: params.coords.latitude};
Expand Down