Sfoglia il codice sorgente

sentry BAD_ACCESS attempt to fix

Viktoriia 7 mesi fa
parent
commit
4c01d8bce9

+ 1 - 1
src/screens/InAppScreens/MapScreen/MarkerItem/styles.tsx

@@ -18,7 +18,7 @@ export const styles = StyleSheet.create({
   },
   customView: {
     width: 200,
-    backgroundColor: 'white',
+    backgroundColor: Colors.WHITE,
     borderRadius: 8,
     shadowColor: '#212529',
     shadowOffset: { width: 0, height: 4 },

+ 17 - 18
src/screens/InAppScreens/MapScreen/index.tsx

@@ -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]);
 

+ 1 - 1
src/screens/InAppScreens/MapScreen/style.tsx

@@ -89,7 +89,7 @@ export const styles = StyleSheet.create({
   },
   customView: {
     width: 200,
-    backgroundColor: 'white',
+    backgroundColor: Colors.WHITE,
     borderRadius: 8,
     shadowColor: '#212529',
     shadowOffset: { width: 0, height: 4 },