You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReactfrom'react';import{useEffect,useMemo,useRef}from'react';importMapbox,{Camera,MapView}from'@rnmapbox/maps';import{AppNavigationProp,GeoPosition,MapMarker,PlaceDetails}from'@/types';import{FRANCE_CENTER_COORDINATES,FRANCE_ZOOM_LEVEL,INITIAL_CENTER_COORDINATES,INITIAL_ZOOM_LEVEL,mapboxPlaceBboxToZoomLevel,POI_POSITION_ZOOM_LEVEL,}from'@/modules/map/utils/map';import{Markers}from'@/modules/map/components/markers/Markers';// eslint-disable-next-line import/no-unresolved -- Android and iOS specific componentsimport{UseMarkersState}from'@/modules/map/hooks/useMarkers';import{useMarkerStatus}from'@/modules/map/hooks/useMarkerStatus';import{noop}from'@/common/utils/helpers';import{envAsString}from'@/common/utils/envs';import{StyleSheet,View}from'react-native';typeMapWithMarkersProps=UseMarkersState&{navigation: AppNavigationProp;selectedMarker: MapMarker|null;onMarkerPress: (marker: MapMarker)=>void;selectedPlaceDetails?: PlaceDetails;favoriteMarkers: MapMarker[]|undefined;favoriteFilterActive: boolean;onFavoritePress: ()=>void;};constMapWithMarkers=({ selectedPlaceDetails, ...useMarkersState}: MapWithMarkersProps)=>{const{ markers, updateBoundsAndRefetchMarkers }=useMarkersState;const{ displayedStatus, smallStatus }=useMarkerStatus();// Use a stable reference for the markers to avoid unnecessary re-rendersconstmarkersDisplayed=useMemo(()=>markers||[],[markers]);constcameraRef=useRef<Camera>(null);consthandleOnMapLoaded=()=>{if(cameraRef.current){// Set the camera to FrancesetCameraPosition(FRANCE_CENTER_COORDINATES,FRANCE_ZOOM_LEVEL);}};// Refetch markers when the map is idleconsthandleOnMapIdle=(state: Mapbox.MapState)=>{updateBoundsAndRefetchMarkers(state.properties.bounds);};constsetCameraPosition=(center: GeoPosition,zoomLevel: number)=>{cameraRef.current?.setCamera({centerCoordinate: center,
zoomLevel,animationMode: 'flyTo',animationDuration: 3000,});};// Set the camera to the selected place when it changesuseEffect(()=>{if(selectedPlaceDetails?.position){// Convert the bbox to a zoom level if it existsconstzoomLevel=selectedPlaceDetails.bbox
? mapboxPlaceBboxToZoomLevel(selectedPlaceDetails.bbox)
: POI_POSITION_ZOOM_LEVEL;setCameraPosition(selectedPlaceDetails.position,zoomLevel);}},[selectedPlaceDetails]);return(<Viewstyle={[styles.container,styles.size]}><MapViewstyle={styles.size}onDidFinishLoadingMap={handleOnMapLoaded}onMapIdle={handleOnMapIdle}projection="globe"rotateEnabled={false}scaleBarEnabled={false}pitchEnabled={false}styleURL={''}localizeLabels={{locale: 'current'}}><Cameraref={cameraRef}defaultSettings={{centerCoordinate: INITIAL_CENTER_COORDINATES,zoomLevel: INITIAL_ZOOM_LEVEL,}}/><Markersmarkers={markersDisplayed}filteredStatus={displayedStatus}smallStatus={smallStatus}onMarkerPress={noop}/></MapView></View>);};conststyles=StyleSheet.create({size: {width: '100%',height: '100%',},container: {position: 'relative',flex: 1,},});exportdefaultMapWithMarkers;
Regression when camera flies to / moves and there are many markers: app is freezing for a few seconds when RNMapboxMapsVersion is greater than 10.18.2
Mapbox 10.18.2
mapbox-ios-sim-10.18.2.mov
Mapbox 10.19.2
mapbox-ios-sim-10.19.2.mov
Expected behavior
No freeze though some sporadic and quick flickering (as in 10.18.2) is acceptable when high number of markers is displayed.
Notes / preliminary analysis
I have tested many combinations of version with @rnmapbox/maps and RNMapboxMapsVersion, device and simulator, the conclusion is always the same: any version greater than 10.18.2 shows some freezes issue, on iOS, when dealing with high number of markers.
Mapbox Implementation
Mapbox
Mapbox Version
10.19.2
React Native Version
0.76
Platform
iOS
@rnmapbox/maps
version10.1.33
Standalone component to reproduce
Observed behavior and steps to reproduce
Regression when camera flies to / moves and there are many markers: app is freezing for a few seconds when
RNMapboxMapsVersion
is greater than10.18.2
Mapbox 10.18.2
mapbox-ios-sim-10.18.2.mov
Mapbox 10.19.2
mapbox-ios-sim-10.19.2.mov
Expected behavior
No freeze though some sporadic and quick flickering (as in
10.18.2
) is acceptable when high number of markers is displayed.Notes / preliminary analysis
I have tested many combinations of version with
@rnmapbox/maps
andRNMapboxMapsVersion
, device and simulator, the conclusion is always the same: any version greater than10.18.2
shows some freezes issue, on iOS, when dealing with high number of markers.Should I post an issue to the https://github.com/mapbox/mapbox-maps-ios repo? I'm not comfortable with Swift nor Xcode.
The text was updated successfully, but these errors were encountered: