Repository navigation
feat: free drive and session state - #28
Merged
Merged
Conversation
mfazekas
marked this pull request as ready for review
October 28, 2026 13:34
mfazekas
force-pushed
the
feat/free-drive
branch
2 times, most recently
from
October 29, 2026 01:10
4f19c87 to
5d83617
Compare
Add Navigation.startFreeDrive, getSessionState/addSessionStateListener and
stopNavigation({ freeDrive }). Location events and the map puck now work in
free drive too. On Android the trip observers are registered whenever the
trip session runs; without location permission startFreeDrive rejects with
code location_permission. CarPlay no longer starts free drive on its own,
since free drive trips are billed.
…nce, views return to free drive
Remove stopNavigation's freeDrive option; startFreeDrive during guidance ends it
and keeps a simulated device where guidance stopped. Android free drive runs
without the foreground service unless startFreeDrive({ foregroundService: true }).
Navigation views started from free drive return to it instead of going idle.
…ator for live free drive
…ustom speed At a simulation speed other than 1x or without auto-advance, simulated guidance runs on the package's own simulator. startFreeDrive and a view returning to free drive didn't see that as simulating, so they asked for location permission and switched to live locations, and the simulator would have kept driving the route. Free drive now parks the SDK's simulation where guidance stopped.
mfazekas
force-pushed
the
feat/free-drive
branch
from
October 29, 2026 05:29
5d83617 to
b6b515b
Compare
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.
Today navigation only exists between
startActiveGuidanceandstopNavigation. Before and after a tripaddLocationListeneris silent, navigation maps have no puck, and the road name and speed limit aren't available. Speed limit and current road are among the most requested features in the unofficial packages (homee #90, pawan-pk #17), and "pick a new destination after arriving" (homee #83, #69) needs idle → free drive → guidance. This is item S1, ranked first in the API gap report.addLocationListener(road name, speed limit) now fires in free drive too, and navigation maps show the puck. As in the native SDKs,startFreeDrive()during guidance is how you go from guidance to free drive; after simulated guidance the simulated device stays where guidance stopped.Decisions applied:
startFreeDriveAutomatically = false), and the free drive the end-of-route feedback starts is stopped unless the app asked for free drive. The README says the CarPlay map has no puck until the app callsstartFreeDrive().startFreeDrive({ foregroundService: true })keeps tracking in the background with the SDK notification. Live guidance still uses the service. The README covers the billing and background implications. The SDK ignoresstartTripSessionwhile a session runs, so the trip session is restarted when the location source or the service changes (e.g. live free drive → simulated guidance, or guidance → free drive without the service).stopNavigation()has no options any more; the example's "Stop to free drive" callsstartFreeDrive().<NavigationView>and<RNNavigationView>stop their guidance through an internalstopViewGuidance: if the guidance started from free drive, the session returns to free drive (asstartFreeDrive()would, keepingforegroundService), otherwise it goes idle. If the session already left guidance, they leave it alone.pauseFreeDrive().Billing: Mapbox bills free drive trips like guidance trips. Free drive only starts when the app calls
startFreeDriveand runs untilstopNavigationor a JS reload.Platform notes:
tripSession().startFreeDrive()/setToIdle(); the session state comes from the SDK'stripSession().sessionpublisher, so CarPlay-initiated changes are reported too.startTripSession()without routes. The trip observers are registered whenever the trip session runs and unregistered when it goes idle. The routes observer ignores updates outside guidance, because registration replays the last (empty) routes and would clear a preview route. The state is set by this package's calls rather than read fromNavigationSessionStateObserver, which passes throughFreeDrivewhile guidance starts and stops.startFreeDriverejects withcode: 'location_permission'(checked before anything changes, so running guidance continues).simulatedLocationparks a simulated device at that position (iOS.simulation(initialLocation:); Android a replayer observer that re-pushes the point every second).Fixed during the device pass:
pushEventsrestarts the replayer clock at the pushed event; the next point is now pushed a second later.Verified:
yarn lint,yarn typecheck, exampletsc,yarn test(63 tests),yarn docs. On the Android emulator and the iOS simulator, with the example app and a temporary debug panel (not committed) showing the session state, the location event count, road and speed limit:freeDrive, puck at the origin, road name and speed limit; again → idle, puck gone, no further location events. Both platforms.startFreeDrive()rejects withlocation_permission; with permission and a mock location, events follow the location with road name and speed limit. Both.foregroundService: true, the location foreground service and its notification run and events keep coming in the background (about 1/s for 3 minutes). Switching back to the default stops the service.<NavigationView>and<RNNavigationView>: started from free drive, they return to free drive when closed or ended (on Android, a live free drive with the service keeps the service); started from idle, they return to idle. Both.Seen once on iOS, before the last fix and not reproduced in eight later runs: after
<NavigationView>returned to free drive, location events stalled while the state wasfreeDrive.Not verified: CarPlay. The CarPlay simulator was off-limits for this pass and the example app has no CarPlay scene, so the CarPlay behaviour above is unchanged from the prototype but untested.