Skip to content

Commit f8addf8

Browse files
authored
Fix Maps flickering issue with clustering (#874)
* Add unique key to clusters to prevent excessive animaitons * Use debounced value for context region * Less debounce value + remove tracks view changes * Revert tracks view changes
1 parent 5c623f4 commit f8addf8

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

packages/maps/src/components/MapView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const MapViewF = <T extends object>({
7575
}) => {
7676
const [currentRegion, setCurrentRegion] = React.useState<Region | null>(null);
7777
const delayedRegionValue = useDebounce(currentRegion, 300);
78+
const contextDelayedRegionValue = useDebounce(currentRegion, 50);
7879

7980
const markerRefs = React.useMemo<
8081
Map<string, React.RefObject<MapMarkerRefType>>
@@ -372,7 +373,7 @@ const MapViewF = <T extends object>({
372373
<MapViewContext.Provider
373374
value={{
374375
animateToLocation: (location) => animateToLocation(location),
375-
region: currentRegion,
376+
region: contextDelayedRegionValue,
376377
}}
377378
>
378379
{memoizedMapView}

packages/maps/src/components/marker-cluster/MapMarkerCluster.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,19 @@ const MapMarkerCluster: React.FC<React.PropsWithChildren> = ({
7070
markerCount: pointCount,
7171
}}
7272
>
73-
{renderMarker({
74-
latitude,
75-
longitude,
76-
children: clusterView,
77-
onPress,
78-
tracksViewChanges:
79-
clusterView.type === DefaultMapMarkerClusterView
80-
? false
81-
: clusterView.props.tracksViewChanges,
82-
})}
73+
{renderMarker(
74+
{
75+
latitude,
76+
longitude,
77+
children: clusterView,
78+
onPress,
79+
tracksViewChanges:
80+
clusterView.type === DefaultMapMarkerClusterView
81+
? false
82+
: clusterView.props.tracksViewChanges,
83+
},
84+
`${latitude}-${longitude}-${pointCount}`
85+
)}
8386
</MapMarkerClusterContext.Provider>
8487
);
8588
}}

0 commit comments

Comments
 (0)