Skip to content

Commit

Permalink
Merge pull request #44767 from callstack-internal/fix/mapbox-initiali…
Browse files Browse the repository at this point in the history
…zation

fix: render Mapbox.MapView when access token is correctly set
  • Loading branch information
deetergp authored Jul 8, 2024
2 parents 4a3ecb3 + 5b489bd commit 9dccffe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/MapView/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
const currentPosition = userLocation ?? initialLocation;
const [userInteractedWithMap, setUserInteractedWithMap] = useState(false);
const shouldInitializeCurrentPosition = useRef(true);
const [isAccessTokenSet, setIsAccessTokenSet] = useState(false);

// Determines if map can be panned to user's detected
// location without bothering the user. It will return
Expand Down Expand Up @@ -138,7 +139,12 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
}, [navigation]);

useEffect(() => {
setAccessToken(accessToken);
setAccessToken(accessToken).then((token) => {
if (!token) {
return;
}
setIsAccessTokenSet(true);
});
}, [accessToken]);

const setMapIdle = (e: MapState) => {
Expand Down Expand Up @@ -198,7 +204,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>(
const initCenterCoordinate = useMemo(() => (interactive ? centerCoordinate : undefined), [interactive, centerCoordinate]);
const initBounds = useMemo(() => (interactive ? undefined : waypointsBounds), [interactive, waypointsBounds]);

return !isOffline && !!accessToken && !!defaultSettings ? (
return !isOffline && isAccessTokenSet && !!defaultSettings ? (
<View style={[style, !interactive ? styles.pointerEventsNone : {}]}>
<Mapbox.MapView
style={{flex: 1}}
Expand Down

0 comments on commit 9dccffe

Please sign in to comment.