Skip to content

feat(android): let an external map's owner invalidate it before destroying it - #4417

Merged
mfazekas merged 1 commit into
mainfrom
feat/external-map-invalidate
Oct 27, 2026
Merged

mfazekas merged 1 commit into
mainfrom
feat/external-map-invalidate

Conversation

@mfazekas

Copy link
Copy Markdown
Contributor

Description

Adds RNMBXExternalMap.invalidate() (SPI, Android) for the owner of an external map (#4412) to call before destroying it. The RNMBXMapViews showing that map then remove their children right away, while the map is still alive, and skip style work when React unmounts them later. Without it, an Android Auto MapSurface destroyed before <CarMap> unmounts gets its layers and sources removed from a dead style. rnmapbox/navigation#17 will call it before MapSurface.onDestroy().

iOS needs no counterpart: RNMBXMapView keeps the CarPlay MapView alive until it unmounts, and there's no explicit destroy there.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Tested with navigation#17's expo example and its debug car preview on an Android emulator (<CarMap> with POI circles and a location ring), hiding and re-showing the preview. /example builds; it has no external map to exercise.

Screenshot OR Video

Before, on every hide:

I Mapbox  : [maps-android\MapSurface\132584438]: surfaceDestroyed() called
W Mapbox  : [maps-android\Mbgl-Style]: Style object (accessing removeStyleLayer) should not be stored and used after MapView is destroyed or new style has been loaded.
W Mapbox  : [maps-android\Mbgl-Style]: Style object (accessing removeStyleLayer) should not be stored and used after MapView is destroyed or new style has been loaded.
W Mapbox  : [maps-android\Mbgl-MapboxMap\132584438]: MapboxMap object (accessing getStyle) should not be stored and used after MapView is destroyed.
W Mapbox  : [maps-android\Mbgl-Style]: Style object (accessing removeStyleSource) should not be stored and used after MapView is destroyed or new style has been loaded.

After, with navigation calling invalidate(): no such warnings over 11 hide/show cycles (one during simulated guidance), and the re-shown car map still renders the <CarMap> children. View count and native heap stayed flat over 20 more cycles.

Component to reproduce the issue you're fixing

Navigation side of the repro (debug car preview from navigation#17):

// RNMBXNavigationCarMapSurface.surfaceDestroyed()
externalMap?.let {
  RNMBXNavigationCarMaps.detach(it)
  it.invalidate()
}
mapSurface.surfaceDestroyed()
mapSurface.onStop()
mapSurface.onDestroy()
adb shell am broadcast -a com.rnmapbox.navigation.DEBUG_CAR_PREVIEW --ez show true --ef latitude 37.789 --ef longitude -122.403 --ef zoom 15 --ez follow false
adb shell am broadcast -a com.rnmapbox.navigation.DEBUG_CAR_PREVIEW --ez show false

@mfazekas
mfazekas merged commit c6e6e50 into main Oct 27, 2026
10 checks passed
@mfazekas
mfazekas deleted the feat/external-map-invalidate branch October 27, 2026 12:44

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant