From b6d5dfdaa87fdc04f779ba3be0f82807155da40d Mon Sep 17 00:00:00 2001 From: Abbey Campbell Date: Mon, 9 Feb 2026 14:40:55 -0800 Subject: [PATCH] use initialRegion and regionToAnimate for maps --- src/components/Explore/MapView.tsx | 11 ++++++----- src/components/SharedComponents/Map/DetailsMap.tsx | 6 +++--- src/components/SharedComponents/Map/Map.tsx | 10 +++------- src/components/TaxonDetails/TaxonMapPreview.tsx | 4 ++-- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/components/Explore/MapView.tsx b/src/components/Explore/MapView.tsx index 3bc37124e..ec3a4a6b5 100644 --- a/src/components/Explore/MapView.tsx +++ b/src/components/Explore/MapView.tsx @@ -78,6 +78,7 @@ const MapView = ( { const { t } = useTranslation( ); const { state: exploreState, dispatch, defaultExploreLocation } = useExplore( ); const [showRedoSearchButton, setShowRedoSearchButton] = useState( false ); + const [regionToAnimate, setRegionToAnimate] = useState( undefined ); const isFirstRender = useRef( true ); const mapRef = useRef( null ); @@ -116,13 +117,12 @@ const MapView = ( { // since we're using initialRegion, we need to animate to the correct zoom level // when a user switches back to NEARBY or WORLDWIDE - if ( mapRef.current - && exploreState.placeMode === PLACE_MODE.NEARBY ) { + if ( exploreState.placeMode === PLACE_MODE.NEARBY ) { // Note: we do get observationBounds back from the API for nearby // but per user feedback, we want to show users a more zoomed in view // when they're looking at NEARBY view if ( nearbyRegion.latitude !== undefined && nearbyRegion.longitude !== undefined ) { - mapRef.current.animateToRegion( { + setRegionToAnimate( { ...nearbyRegion, latitude: nearbyRegion.latitude, longitude: nearbyRegion.longitude, @@ -132,13 +132,13 @@ const MapView = ( { } if ( mapRef.current && exploreState.placeMode === PLACE_MODE.WORLDWIDE ) { - mapRef.current.animateToRegion( worldwideRegion ); + setRegionToAnimate( worldwideRegion ); } if ( mapRef.current && exploreState.placeMode === PLACE_MODE.PLACE ) { if ( observationBounds ) { const newRegion = getMapRegion( observationBounds ); - mapRef.current.animateToRegion( newRegion ); + setRegionToAnimate( newRegion ); } } }, [ @@ -229,6 +229,7 @@ const MapView = ( { currentLocationButtonClassName="left-5 bottom-20" onPanDrag={handlePanDrag} initialRegion={initialRegion} + regionToAnimate={regionToAnimate} showCurrentLocationButton showSwitchMapTypeButton showsCompass={false} diff --git a/src/components/SharedComponents/Map/DetailsMap.tsx b/src/components/SharedComponents/Map/DetailsMap.tsx index e83775fb1..d2e0a54d5 100644 --- a/src/components/SharedComponents/Map/DetailsMap.tsx +++ b/src/components/SharedComponents/Map/DetailsMap.tsx @@ -27,7 +27,7 @@ interface Props { headerTitle?: React.ReactNode; // TODO MOB-1038: reconcile the type issues here requiring the intersection observation?: Observation & RealmObservation; - region?: Region; + initialRegion?: Region; tileMapParams: Record | null; } @@ -68,7 +68,7 @@ const DetailsMap = ( { coordinateString, headerTitle, observation, - region, + initialRegion, tileMapParams, }: Props ) => { const insets = useSafeAreaInsets(); @@ -114,7 +114,7 @@ const DetailsMap = ( { void; openMapScreen?: () => void; ref?: React.Ref; - region?: Region; regionToAnimate?: Region; scrollEnabled?: boolean; showCurrentLocationButton?: boolean; @@ -103,7 +102,6 @@ const Map = ( { onRegionChangeComplete, openMapScreen, ref, - region, regionToAnimate, scrollEnabled = true, showCurrentLocationButton, @@ -194,6 +192,8 @@ const Map = ( { animateToRegion( { latitude: regionToAnimate.latitude, longitude: regionToAnimate.longitude, + latitudeDelta: regionToAnimate.latitudeDelta, + longitudeDelta: regionToAnimate.longitudeDelta, } ); }, [ regionToAnimate, @@ -235,9 +235,6 @@ const Map = ( { if ( Platform.OS !== "android" && initialRegion ) { return null; } - if ( region?.latitude ) { - return region; - } return Platform.OS === "android" ? androidLocalRegion : defaultInitialRegion; @@ -377,7 +374,7 @@ const Map = ( { useEffect( ( ) => { if ( Platform.OS === "android" && androidAnimateRegion ) { - const curRegion = androidLocalRegion || region; + const curRegion = androidLocalRegion; const newRegion = { ...curRegion, // provides defaults for latitudeDelta and longitudeDelta ...androidAnimateRegion, @@ -391,7 +388,6 @@ const Map = ( { [ androidAnimateRegion, androidLocalRegion, - region, handleRegionChangeComplete, ], ); diff --git a/src/components/TaxonDetails/TaxonMapPreview.tsx b/src/components/TaxonDetails/TaxonMapPreview.tsx index ce70c824a..b46df07e2 100644 --- a/src/components/TaxonDetails/TaxonMapPreview.tsx +++ b/src/components/TaxonDetails/TaxonMapPreview.tsx @@ -69,7 +69,7 @@ const TaxonMapPreview = ( { mapViewClassName="-mx-3" observation={observation} openMapScreen={() => setShowMapModal( true )} - region={region} + initialRegion={region} scrollEnabled={false} tileMapParams={obsParams} withObsTiles @@ -93,7 +93,7 @@ const TaxonMapPreview = ( { style={{ margin: 0 }} modal={( setShowMapModal( false )} tileMapParams={obsParams}