maplibre / maplibre-react-native

A MapLibre react native module for creating custom maps
Other
172 stars 39 forks source link

Quick black flash at the start #367

Closed Gabotron-ES closed 3 weeks ago

Gabotron-ES commented 3 weeks ago

Hi everybody, my map view shows a black flash when map is starting , is there a way to fix this? also is there a way to check if map is loaded, I could show a spinner this way.

tyrauber commented 3 weeks ago

Hey @Gabotron-ES, if I am understanding correctly, the map is briefly black before rendering.

One approach to this problem is to use setState to create a mapOpacity variable that defaults to 0 and then setMapOpacity to 1 onDidFinishLoadingMap.

 const [mapOpacity, setMapOpacity] = useState(0);
 ...
 <MapLibre.MapView
    style={[{ height: '100%' }, { opacity: mapOpacity }]}
    onDidFinishLoadingMap={() => setMapOpacity(1)}