Skip to content

feat: let a map view factory hand over a map that lives elsewhere - #4412

Merged
mfazekas merged 2 commits into
mainfrom
feat/map-view-factory-external-map
Oct 27, 2026
Merged

mfazekas merged 2 commits into
mainfrom
feat/map-view-factory-external-map

Conversation

@mfazekas

@mfazekas mfazekas commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Lets a registered RNMBXMapViewFactory (the hooks from #4289 and #4369) hand over a map that lives elsewhere. RNMBXMapView then adds its children (sources, layers, images) to that map and removes them again, but leaves the map's style, ornaments, gestures, frame and lifetime to whoever owns it. This is what the CarPlay / Android Auto <CarMap> prototype in rnmapbox/navigation needs (rnmapbox/navigation#17).

  1. iOS: RNMBXMapView.ownsMapView (default true). A factory returning the map Mapbox Navigation's CarPlayManager created sets it to false. The view then doesn't take over the gesture delegate or remove the map on teardown, picks up a style that is already loaded, and re-adds its features when the owner swaps the style.
  2. Android: RNMBXMapViewFactory.registerExternalMap returns an RNMBXExternalMap (a MapboxMap, its plugin provider, and an optional MapView), so the map can be a MapSurface. RNMBXMapView.mapView is now MapView?: null before the map is created and for an external map without a MapView. Internals use mapPlugins (gestures, location, viewport, annotations) and getMapboxMap(); ornaments, snapshots and touch handling skip a missing MapView, and MarkerView / PointAnnotation children are skipped with a warning. Map props are ignored for an external map.

The nullable mapView is an SPI change: Kotlin callers of RNMBXMapView.mapView need ?. or a null check (e.g. RNMBXNavigationViewport in rnmapbox/navigation).

Rebased onto main, so this needs Mapbox Maps 11.33. On iOS, 11.33's MapView.didMoveToWindow seeds the scene from CPWindow.templateApplicationScene, so a car map added after the CarPlay scene activated starts its display link; 11.23 doesn't.

Checked: yarn lint, yarn type:check, yarn unittest, yarn generate (no drift), and example app builds for Android and the iOS simulator. Not re-tested on a device or car screen after the rebase.

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)

@mfazekas
mfazekas force-pushed the feat/map-view-factory-external-map branch from 0d3b8f0 to 93bf3cc Compare October 27, 2026 07:03
@mfazekas
mfazekas marked this pull request as ready for review October 27, 2026 09:10
@mfazekas
mfazekas merged commit 4b7ec57 into main Oct 27, 2026
10 checks passed
@mfazekas
mfazekas deleted the feat/map-view-factory-external-map branch October 27, 2026 09:11
mfazekas added a commit to rnmapbox/navigation that referenced this pull request Oct 27, 2026
<CarMap> uses the map view factory support for maps that live elsewhere
from rnmapbox/maps#4412, released in 10.3.15.
mfazekas added a commit to rnmapbox/navigation that referenced this pull request Oct 27, 2026
* feat(ios): prototype CarPlay support on the shared navigation session

CarPlay shows the Navigation SDK's CarPlayManager UI for the same session as
the phone: the map while idle and turn-by-turn guidance while guidance runs.
The Expo plugin's carPlay option adds the CarPlay scene and the carplay-maps
entitlement. The plugin now also adds the audio background mode, without
which the SDK asserts in debug builds when guidance starts.

* feat: add CarMap for @rnmapbox/maps children on the car screen's map

* feat(ios): CarMap on the CarPlay map, and create the session when the car connects

* feat(android): CarMap on Android Auto and a debug car screen preview

RNMBXNavigationCarMaps hands the car screen's MapSurface to <CarMap>'s
rnmbxnavcar map. RNMBXNavigationCarMapSurface draws that map onto a car
Surface, fed by the Android Auto SurfaceCallback (CarAppService declared
by the plugin's androidAuto option) or, in debug builds, by a SurfaceView
overlay toggled with an adb broadcast.

* fix(ios): start the CarPlay session without React Native

CarPlay can cold-launch the app with only the CarPlay scene, so JS never
sets the access token. Fall back to the Maps SDK token (Info.plist
MBXAccessToken) to create the navigation provider, which JS then reuses.

* docs: CarPlay entitlement, Info.plist token and a simulator shim for development

* fix: build against Navigation SDK 3.33 and a nullable RNMBXMapView.mapView

Nav SDK 3.33 moved the CarPlayManagerDelegate defaults this delegate relies on
to the MapboxCarPlayInternal SPI. On Android, maps #4412 now exposes
RNMBXMapView.mapView as optional.

* feat(example): highlight the car's position on the car screen's map

A ring that follows the navigation location and larger POI circles, drawn
with @rnmapbox/maps layers through <CarMap>.

* feat(ios): a CarPlay React root, so <CarMap> renders on a CarPlay-only launch

Navigation.registerCarPlayRoot registers a component that the CarPlay scene
mounts in a React root of its own while CarPlay is connected, on the app's
React Native factory. When CarPlay launches the app without its phone UI,
that root starts React Native; the phone scene later shares the same host.
The Expo plugin's carPlay option hands the factory to the CarPlay scene in
AppDelegate.swift. The host is still created on demand, so a phone cold start
keeps its launch options for Linking.getInitialURL.

The example renders its car map layers in that root on iOS and keeps them
emissive so the night style doesn't darken them.

* chore: require @rnmapbox/maps 10.3.15 for CarMap

<CarMap> uses the map view factory support for maps that live elsewhere
from rnmapbox/maps#4412, released in 10.3.15.

* fix(ios): keep the phone's trip when CarPlay takes over guidance

CarPlayNavigationViewController always starts active guidance from leg 0
in viewDidLoad, so CarPlay connecting mid-trip set a multi-leg trip back
to its first leg, and a trip the phone stopped while CarPlay was still
starting came back. Restore the leg index right after the view controller
restarts guidance, and end CarPlay's guidance again if the phone stopped
meanwhile.

* fix(ios): one CarPlay React root per process, created without reflection

Reconnecting CarPlay created a second root while the first one's surface
could still run, mounting <CarMap> twice on the same map. The root is now
created once and moved to each new CarPlay window.

An Objective-C helper creates it with React Native's own root view API,
with a fallback for versions before 0.84, instead of key-value lookups
and an unsafe cast; the factory property is typed.

The provider sink waits until the session has set its provider, and
setting a different token after CarPlay created the provider logs a
warning instead of being ignored silently.

* feat: make the CarPlay root opt-in, and let <CarMap> find its place

The CarPlay root wraps the registered component in a context. While it
is mounted, <CarMap> elsewhere in the app renders nothing, so the same
component can be rendered in the app for Android Auto and registered as
the CarPlay root without duplicating layers on iOS.

The plugin hands the factory to CarPlay only with carPlayRoot: true, so
apps that use the stock CarPlay UI don't start React Native on a
CarPlay-only launch. It warns instead of failing the prebuild for an app
delegate it doesn't know, and removes its scene, app delegate lines and
Android Auto service when the options are turned off. The audio
background mode moves to its own change.

CAR_MAP_VIEW_IMPL and the car event types are no longer exported.

* refactor(android): ship the car screen preview in debug builds only

It moves to the library's debug source set, with a no-op in release. Its
receiver is registered once and uses the latest React context, so it
keeps working after a JS reload instead of holding on to the first one.

* docs: CarPlay root, CarMap placement, Android Auto and plugin options

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