Skip to content

Colota - Android GPS Location tracker

fix: defer fitBounds to next frame to fix intermittent auto-zoom (#275)

Max Dietrich7f085b4c254e
diff --git a/apps/mobile/src/components/features/inspector/TrackMap.tsx b/apps/mobile/src/components/features/inspector/TrackMap.tsx
index 147ad6ff..ffb9c88b 100644
--- a/apps/mobile/src/components/features/inspector/TrackMap.tsx
+++ b/apps/mobile/src/components/features/inspector/TrackMap.tsx
@@ -64,8 +64,12 @@ export function TrackMap({ locations, selectedPoint, colors, trips, fitVersion }
useEffect(() => {
if (!bounds || !mapReady || !mapRef.current?.camera) return
if (fitVersion === fittedVersionRef.current) return
- fittedVersionRef.current = fitVersion ?? 0
- mapRef.current.camera.fitBounds(bounds.ne, bounds.sw, [60, 60, 60, 60], MAP_ANIMATION_DURATION_MS)
+ // Defer to next frame so the map's GL context is fully ready after onDidFinishLoadingMap
+ requestAnimationFrame(() => {
+ if (!mapRef.current?.camera) return
+ fittedVersionRef.current = fitVersion ?? 0
+ mapRef.current.camera.fitBounds(bounds.ne, bounds.sw, [60, 60, 60, 60], MAP_ANIMATION_DURATION_MS)
+ })
}, [bounds, mapReady, fitVersion])
const handleMapReady = useCallback(() => setMapReady(true), [])