Repository navigation
feat(ios): CarPlay prototype on the shared navigation session - #17
Merged
Merged
Conversation
2 of 8 tasks
mfazekas
force-pushed
the
feat/carplay-prototype
branch
from
October 27, 2026 07:39
767a097 to
03d4c83
Compare
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.
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.
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.
…pView 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.
A ring that follows the navigation location and larger POI circles, drawn with @rnmapbox/maps layers through <CarMap>.
…y 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.
<CarMap> uses the map view factory support for maps that live elsewhere from rnmapbox/maps#4412, released in 10.3.15.
mfazekas
force-pushed
the
feat/carplay-prototype
branch
from
October 27, 2026 10:33
0cadbe0 to
276e7bd
Compare
This was referenced Oct 27, 2026
Merged
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.
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.
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.
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.
3 of 8 tasks
mfazekas
marked this pull request as ready for review
October 27, 2026 20:39
This was referenced Oct 27, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft prototype. Not ready to merge.
Design
CPTemplateApplicationSceneSessionRoleApplicationscene. Expo SDK 58 apps already use the scene-based life cycle:UIApplicationSceneManifesthas a phone scene whoseExpoAppSceneDelegatecreates the window, and the app delegate still creates the React Native factory. So the CarPlay scene can sit next to the phone scene without touching the app delegate orExpoAppDelegateSubscriber. The pod shipsRNMBXNavigationCarPlaySceneDelegate. The plugin's newcarPlay: trueoption adds the scene entry with that delegate, plus thecom.apple.developer.carplay-mapsentitlement. It throws if the app has no phone scene, since declaring a scene manifest without one leaves an app-delegate window unshown. Bare apps on RN < 0.88 would first have to adopt scenes themselves. RN 0.88 adds official SceneDelegate support, and Apple requires scenes from the iOS 27 SDK on.CarPlayManageron the process-wideMapboxNavigationProviderthat the TurboModule and every navigation map already share, so route handles and the session are reused as they are. While idle, CarPlay shows the SDK's map and free drive (its default). When the phone starts active guidance, CarPlay opensCarPlayNavigationViewControllerfor the same routes. When the phone stops, CarPlay exits it, and ending the trip on CarPlay stops navigation. The only new JS API isNavigation.isCarPlayConnected()andaddCarPlayConnectionListener; Android returnsfalse. CarPlay can launch the app without the phone scene, so without React Native; the scene delegate then creates the provider from the Info.plistMBXAccessToken, and JS reuses it later. Without that key CarPlay waits forsetAccessToken.What's in it
ios/RNMBXNavigationCarPlay.swift: the scene delegate and the session sync described above.carPlay,carPlayRootandandroidAutooptions. Turning them off removes what they added on the next prebuild. Theaudiobackground mode moved to feat(plugin): add the audio background mode, with a backgroundAudio opt-out #19; until that lands, the Expo example's Simulate asserts in debug builds.Testing
Unit tests, lint and typecheck pass. The Expo example builds for the iOS Simulator (Release) and Android (debug) against @rnmapbox/maps 10.3.15. The CarPlay-only cold launch was checked in the iOS 26.4 Simulator with the shim (see Status).
Running on a device
The
carplay-mapsentitlement has to be requested from Apple (developer.apple.com/contact/carplay). Apple adds it to the team as a managed capability, which requires a paid Developer Program membership; a free Personal Team can't get it. Device builds, whether connected to a car or to the CarPlay Simulator Mac app, can't be provisioned with the entitlement until Apple grants it. The Xcode Simulator only needs the entitlement key in the entitlements file.CarMap (experiment)
<CarMap>adds its@rnmapbox/mapschildren (sources, layers, images) to the car screen's map instead of the phone's. Render it anywhere in the app; on the phone it is a 0×0 host view. Its children can be a function ofactivity("browsing" / "navigating"). Native code reports every switch of the car map (CarPlay replaces its map when guidance starts), and<CarMap>remounts by key so the children are added to the new map.RNMBXNavigationCarPlaytracks the map CarPlayManager shows (didSetup,willPresent, end of navigation) and thernmbxnavcar:<id>factory hands it to maps.Navigation.registerCarPlayRoot(Component)registers a component that the CarPlay scene mounts in a React root of its own (zero-size, under the map) while CarPlay is connected. It's opt-in: the plugin'scarPlayRootoption hands the app'sRCTReactNativeFactoryover inAppDelegate.swift, and on a CarPlay-only launch the root starts React Native on it; the phone scene later shares the same host. The root is created once and moved to each CarPlay window. While it's mounted,<CarMap>elsewhere in the app renders nothing, so the same component serves Android Auto and the CarPlay root. The host is still created on demand rather than indidFinishLaunching, so a phone cold start keeps its launch options forLinking.getInitialURL(). The example renders its<CarMap>layers (a ring following the car, POI circles) in both.MapSurface-backed car map, fed by an Android AutoCarAppService(Car App LibraryNavigationTemplate+SurfaceCallback) and, in debug builds, a car screen preview overlay. The plugin'sandroidAutooption adds the service to the manifest.ownsMapView = false; AndroidregisterExternalMap, map without a MapView, nullableRNMBXMapView.mapView), from feat: let a map view factory hand over a map that lives elsewhere maps#4412, released in 10.3.15. The peer range is now>=10.3.15 <10.4.0, and both examples use 10.3.15.Status: on Android the car map shows the POI layers and switches style when guidance starts (verified with the debug preview; real Android Auto untested, no head unit).
On iOS, rebased onto Nav SDK 3.33 / Maps 11.33, a CarPlay-only cold launch (phone app not running) now shows the navigation map in the iOS 26.4 Simulator. Two things were in the way:
<CarMap>layers show without opening the phone app (checked with Simulator City Run: one ring following the puck, no duplicates once the phone scene connects).MapViewstarted its display link only fromwindow.windowScene(nil forCPWindow) or a later scene activation. Maps 11.24+ resolves the CarPlay scene indidMoveToWindow, so 11.33 fixes it without a workaround.The iOS 26.4/26.5 simulators crash CarPlayTemplateUIHost on any
CPMapTemplate(Apple bug, see mapbox/mapbox-navigation-ios#4827).scripts/carplay-simulator-shimhas a development-only stub that works around it; it isn't part of the package. The README now covers that, the Info.plist token and the entitlement.Review follow-up
CarPlayNavigationViewControlleralways restarts active guidance from leg 0 inviewDidLoad, so CarPlay connecting mid-trip reset a multi-leg trip to its first leg. CarPlay now restores the phone's leg right after, and ends its guidance again if the phone stopped while CarPlay was starting. Checked in the simulator: a 2-leg simulated trip on leg 1 stays on leg 1 when CarPlay connects (without the restore it drops to leg 0). A single progress event with leg 0 still reaches JS in between.<CarMap>with its two sources.<CarMap>children never appear on the CarPlay guidance map. For a map it doesn't own, maps waits forisStyleLoadedor the nextstyleLoadedevent, butisStyleLoadedalso waits for sources, and on the guidance map it's false after the style already loaded. A fix that re-checks on source and style data events makes them appear (verified locally); it needs a maps release.NavigationManager(navigationStarted/navigationEnded,onStopNavigation), a release host allowlist instead ofhosts_allowlist_sample, clearingsetSurfaceCallbackinonDestroy, and not addingandroidx.car.appand the service to apps withoutandroidAuto.