[Android] All overlays disappear after a bottom-tab switch: second onDetachedFromWindow overwrites the pending savedFeatures

Author: hochraldoCreated Sep 28, 2026Updated Sep 28, 2026

Summary

On Android with the new architecture (Fabric), all overlays (markers, polygons, polylines) disappear after switching to another bottom tab and back. The map itself renders. Panning does not bring the overlays back, because React sees no change and sends no new mount instructions.

The cause is in MapView.onDetachedFromWindow. A tab switch with @react-navigation/bottom-tabs (react-native-screens) detaches the MapView, attaches it, and detaches it again within about 40 ms. The first detach saves the overlays:

java
savedFeatures = new ArrayList<>(features);
features.clear();

The attach schedules the restore in getMapAsync. The second detach runs before that callback and executes the same two lines again. features is empty at that point, so savedFeatures becomes an empty list. The pending callback then finds nothing to restore, and the overlays are lost for good.

Log from MapView.java with added Log.d calls (1.29.11, one switch to another tab):

detach features=13 savedFeatures=-1
attach savedMapState=true savedFeatures=13 features=0
detach features=0 savedFeatures=13
reattach mapAsync savedFeatures=0

(-1 means null.)

A second, related problem: when a restore does happen, MapPolygon.addToMap uses getPolygonOptions(), which caches the PolygonOptions built at the first draw. Props that changed later (for example fillColor and strokeColor) update the live Polygon, but not the cached options. So a restored polygon shows its first colors again.

Reproducible sample code

This is a reduced sketch of our setup (MapView as a direct bottom-tab screen). We found the bug in our app, not in this exact file.

typescript
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { NavigationContainer } from '@react-navigation/native';
import { Text, View } from 'react-native';
import MapView, { Marker, Polygon, PROVIDER_GOOGLE } from 'react-native-maps';

const Tab = createBottomTabNavigator();

function MapTab() {
  return (
    <MapView
      provider={PROVIDER_GOOGLE}
      style={{ flex: 1 }}
      initialRegion={{ latitude: 47.3769, longitude: 8.5417, latitudeDelta: 0.05, longitudeDelta: 0.05 }}
    >
      <Marker coordinate={{ latitude: 47.3769, longitude: 8.5417 }} />
      <Polygon
        coordinates={[
          { latitude: 47.37, longitude: 8.53 },
          { latitude: 47.38, longitude: 8.53 },
          { latitude: 47.38, longitude: 8.55 },
        ]}
        fillColor="rgba(255,0,0,0.3)"
      />
    </MapView>
  );
}

function OtherTab() {
  return <View style={{ flex: 1 }}><Text>Other</Text></View>;
}

export default function App() {
  return (
    <NavigationContainer>
      <Tab.Navigator>
        <Tab.Screen name="Map" component={MapTab} />
        <Tab.Screen name="Other" component={OtherTab} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

Steps to reproduce

  1. Run the sample on Android with the new architecture.
  2. Wait until the marker and the polygon show.
  3. Tap the "Other" tab.
  4. Tap the "Map" tab again.

Expected result

The marker and the polygon show again.

Actual result

The map shows without any overlay. Panning and zooming do not bring them back.

React Native Maps Version

1.29.11 (also 1.27.2)

What platforms are you seeing the problem on?

Android

React Native Version

0.86.3

What version of Expo are you using?

SDK 57 (dev client, CNG)

Device(s)

Android emulator, Pixel 8 AVD (API 37). A tester saw the same symptom on a physical Android phone, but we logged the mechanism only on the emulator.

Additional information

  • @react-navigation/bottom-tabs 6.6.1, react-native-screens 4.26.2.
  • A possible fix:
    • In onDetachedFromWindow, copy features into savedFeatures only when savedFeatures == null. A non-null savedFeatures means that a restore is still pending, and that list is the source of truth.
    • In the getMapAsync restore callback, restore only when the view is still attached. If it is not attached, keep savedFeatures for the next attach.
  • For the stale colors, addToMap could rebuild the options from the current props, for example by clearing the cached polygonOptions when a prop changes.
  • Our workaround: we give all MapView children a new React key each time the map screen regains focus, so React mounts fresh overlays from the current props.

Source: react-native-maps/react-native-maps