|
@@ -398,15 +398,13 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
}, [netInfo]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (!showNomads) {
|
|
|
- setNomads(null);
|
|
|
- } else {
|
|
|
+ if (showNomads) {
|
|
|
refetchUsersLocation();
|
|
|
}
|
|
|
}, [showNomads]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (usersLocation && showNomads) {
|
|
|
+ if (usersLocation && usersLocation.geojson && showNomads) {
|
|
|
const filteredNomads: GeoJSON.FeatureCollection = {
|
|
|
type: 'FeatureCollection',
|
|
|
features: usersLocation.geojson.features.filter(
|
|
@@ -414,7 +412,9 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
)
|
|
|
};
|
|
|
|
|
|
- setNomads(filteredNomads);
|
|
|
+ if (!nomads || JSON.stringify(filteredNomads) !== JSON.stringify(nomads)) {
|
|
|
+ setNomads(filteredNomads);
|
|
|
+ }
|
|
|
}
|
|
|
}, [usersLocation, showNomads]);
|
|
|
|
|
@@ -585,12 +585,6 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
}
|
|
|
}, [route, db1, db2, db3]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- if (selectedRegion) {
|
|
|
- mapRef.current;
|
|
|
- }
|
|
|
- }, [selectedRegion]);
|
|
|
-
|
|
|
useFocusEffect(
|
|
|
useCallback(() => {
|
|
|
if (token) {
|
|
@@ -612,7 +606,6 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
) {
|
|
|
setShowNomads(false);
|
|
|
storage.set('showNomads', false);
|
|
|
- setNomads(null);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -708,13 +701,19 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (initialRegion && !route.params?.id) {
|
|
|
- setTimeout(() => {
|
|
|
- cameraRef.current?.setCamera({
|
|
|
- centerCoordinate: [initialRegion.longitude, initialRegion.latitude],
|
|
|
- zoomLevel: Math.log2(360 / initialRegion.latitudeDelta),
|
|
|
- animationDuration: 500
|
|
|
- });
|
|
|
+ const timeoutId = setTimeout(() => {
|
|
|
+ if (cameraRef.current) {
|
|
|
+ cameraRef.current.setCamera({
|
|
|
+ centerCoordinate: [initialRegion.longitude, initialRegion.latitude],
|
|
|
+ zoomLevel: Math.log2(360 / initialRegion.latitudeDelta),
|
|
|
+ animationDuration: 500
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.warn("Camera ref is not available.");
|
|
|
+ }
|
|
|
}, 500);
|
|
|
+
|
|
|
+ return () => clearTimeout(timeoutId);
|
|
|
}
|
|
|
}, [initialRegion]);
|
|
|
|