This is a minimum reproducible example (MRE) demonstrating a bug in React Native Maps when navigating between screens containing MapView components.
Issue: NullPointerException occurs when navigating between screens containing MapView components, specifically during the onSaveInstanceState lifecycle method.
Error:
FATAL EXCEPTION: main
Process: com.mapsmre, PID: 19104
java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.impl.bp.z(android.os.Bundle)' on a null object reference
at com.google.maps.api.android.lib6.impl.ct.k(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (260400-0):3)
at com.google.android.gms.maps.internal.p.be(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (260400-0):109)
...
at com.rnmaps.maps.MapView.onDetachedFromWindow(MapView.java:341)
- Install dependencies:
npm install - Run the app:
npm run android - Follow the screen flow as suggested by the buttons:
- Start at OGMap screen (contains MapView)
- Tap "Go to MiddleWareToAnotherMap" button
- Tap "Go to NewMap" button (contains another MapView)
- Navigate back and forth between screens
The crash typically occurs when navigating away from a screen containing a MapView component.
- React Native Maps version: 1.26.13
- React Native version: 0.81.4
- Expo version: 54.0.1
- Platform: Android
- Navigation: React Navigation Native Stack
-
Install dependencies:
npm install
-
Run the app:
npm run android
-
Reproduce the bug:
- Follow the button flow: OGMap → MiddleWareToAnotherMap → NewMap
- Navigate back and forth between screens
- The crash should occur when navigating away from MapView screens
src/navigation/maps/OGMap.tsx- Initial screen with MapViewsrc/navigation/maps/MiddlewareToAnotherMap.tsx- Middleware screen (no MapView)src/navigation/maps/NewMap.tsx- Second screen with MapView- Navigation flow: OGMap → MiddlewareToAnotherMap → NewMap
This MRE demonstrates a known issue with React Native Maps when used with React Navigation. The bug occurs during the Android lifecycle management of MapView components.
Note: This is a minimal reproducible example created to demonstrate the bug. The issue appears to be related to the interaction between React Native Maps and React Navigation's screen lifecycle management on Android.