Skip to content

feat: support custom MapView delegates and add Navigation SDK sample app - #1061

Merged
kikoso merged 5 commits into
mainfrom
feat/navigation-sdk
Nov 24, 2026
Merged

kikoso merged 5 commits into
mainfrom
feat/navigation-sdk

Conversation

@dkhawk

@dkhawk dkhawk commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds MapViewDelegate, DefaultMapViewDelegate, and mapViewDelegateFactory to GoogleMap (while preserving mapViewFactory and a @deprecated(level = DeprecationLevel.HIDDEN) binary-compatibility overload) so custom map containers such as the Android Navigation SDK's NavigationView can be hosted inside Maps Compose without breaking source or binary compatibility. Also adds the :navigation-app sample module and headless JVM Robolectric unit test suites for both :maps-compose and :navigation-app using com.google.maps.android:maps-testing-robolectric:1.0.0-rc01.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Coverage (unit tests)

Compared against 0293633 on main (#1093).

Module Line % Change Branch % Change
maps-compose 45.82% 🔺 +30.50 15.23% 🔺 +11.26
maps-compose-utils 26.29% no change 12.70% no change
maps-compose-widgets 3.87% no change 0.00% no change
TOTAL 38.93% 🔺 +21.55 14.22% 🔺 +8.60

Line and branch coverage from unit test reports. History is recorded on the coverage-history branch after each merge to main.

Comment thread gradle/libs.versions.toml Fixed
@dkhawk
dkhawk force-pushed the feat/navigation-sdk branch 3 times, most recently from a5df619 to ce14db7 Compare November 10, 2026 23:41
@dkhawk
dkhawk marked this pull request as ready for review November 17, 2026 16:27
@snippet-bot

snippet-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@dkhawk
dkhawk force-pushed the feat/navigation-sdk branch from ce14db7 to 8e28a51 Compare November 17, 2026 21:33
@googlemaps-bot

googlemaps-bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Coverage (instrumentation tests)

Overall Project 46.09% -0.34% 🍏
Files changed 71.14% 🍏

Module Coverage
maps-app 64.61% -0.91% 🍏
Files
Module File Coverage
maps-app ComposeInfoWindowAdapter.kt 90.84% 🍏
GoogleMap.kt 77.98% -6.28% 🍏
MapComposeViewRender.kt 67.64% -2.91% ❌
MapApplier.kt 41.21% 🍏

@dkhawk
dkhawk force-pushed the feat/navigation-sdk branch from 8e28a51 to 1d3955d Compare November 17, 2026 23:12
@kikoso
kikoso self-requested a review November 17, 2026 23:54
*
* @param T the underlying [ViewGroup] type hosted by this delegate
*/
public interface MapViewDelegate<out T : ViewGroup> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should mark MapViewDelegate (and DefaultMapViewDelegate) as @MapsComposeExperimentalApi for now. NavigationView already needs onSaveInstanceState and onTrimMemory, which the interface doesn't have (the sample fakes a trim level in onLowMemory), and adding an abstract member later would break every implementer. What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — addressed in 6624a123:

  • Marked MapViewDelegate, DefaultMapViewDelegate, and the delegate-based GoogleMap overload (@JvmName("GoogleMapWithDelegate")) with @MapsComposeExperimentalApi, restoring the standard non-experimental GoogleMap signature unchanged from main (and removing the @Deprecated(HIDDEN) shim).
  • Added onTrimMemory(level: Int) to MapViewDelegate with a default implementation delegating to onLowMemory() when level >= TRIM_MEMORY_UI_HIDDEN, wired componentCallbacks2() to forward the real trim level directly, and updated NavigationViewDelegate to pass the exact trim level through to NavigationView.

Keeping it @MapsComposeExperimentalApi also leaves room to evolve lifecycle hooks like onSaveInstanceState cleanly before stabilizing.

Comment on lines +95 to +96
* @param mapViewFactory factory for creating the [MapView] when [mapViewDelegateFactory] is not
* overridden

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone passes both mapViewFactory and mapViewDelegateFactory, the first one is silently ignored. Could we at least make it explicit in the KDoc?

Suggested change
* @param mapViewFactory factory for creating the [MapView] when [mapViewDelegateFactory] is not
* overridden
* @param mapViewFactory factory for creating the [MapView]. Ignored when a custom
* [mapViewDelegateFactory] is supplied; wrap your [MapView] in [DefaultMapViewDelegate] there instead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved structurally in 6624a123 by splitting mapViewDelegateFactory onto its own @MapsComposeExperimentalApi GoogleMap overload (with mapViewDelegateFactory required and no mapViewFactory), so callers can no longer pass both factories to the same call.

* can host either a standard [MapView] (via [DefaultMapViewDelegate]) or a custom map view such as
* the Navigation SDK's `NavigationView`.
*
* @param T the underlying [ViewGroup] type hosted by this delegate

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we document that GoogleMap owns the view? It overwrites the tag with MapTagData, adds a child container for info windows, and on release calls removeAllViews() and clears the tag. With a plain MapView this never mattered, but a custom container using its own tag will break without any hint.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — documented GoogleMap's view-ownership contract in MapViewDelegate's KDoc in 6624a123 (overwriting untagged View.tag, attaching an internal child container for Compose info windows/markers, and calling removeAllViews() + clearing tag on release).

<application>
<activity
android:name="androidx.activity.ComponentActivity"
android:exported="true" />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? It merges an exported ComponentActivity into the debug builds of maps-app and navigation-app. We already have androidx-test-compose-ui-manifest in the catalog, so testImplementation(libs.androidx.test.compose.ui.manifest) should do the same.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6624a123 — removed maps-compose/src/debug/AndroidManifest.xml, switched to testImplementation(libs.androidx.test.compose.ui.manifest) in maps-compose/build.gradle.kts, and confirmed all GoogleMapTest cases pass.

onMapLongClick = onMapDestinationSelected,
mapViewDelegateFactory = { context, options ->
val navView = NavigationView(context, options)
navigationViewInstance = navView

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we write Compose state from inside the factory and never clear it, so it keeps pointing to the destroyed NavigationView. It is harmless here, but people will copy this sample as the pattern for the new API.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up in 6624a123 — removed the navigationViewInstance Compose state and DisposableEffect from NavigationScreen, and moved OnNavigationUiChangedListener registration/removal into NavigationViewDelegate.onCreate/onDestroy via an onNavigationUiChanged callback (with unit test coverage in NavigationViewDelegateTest).

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments @dkhawk , but looks good! I would like to settle the experimental question before merging, though.

- Mark MapViewDelegate, DefaultMapViewDelegate, and the delegate-based GoogleMap overload (@JvmName("GoogleMapWithDelegate")) as @MapsComposeExperimentalApi, restoring the original non-experimental GoogleMap signature without a hidden compatibility shim.
- Add MapViewDelegate.onTrimMemory(level) with a default implementation delegating to onLowMemory() for level >= TRIM_MEMORY_UI_HIDDEN, and forward real trim levels in NavigationViewDelegate.
- Document GoogleMap view-ownership requirements on MapViewDelegate.
- Remove maps-compose/src/debug/AndroidManifest.xml in favor of testImplementation(libs.androidx.test.compose.ui.manifest).
- Manage OnNavigationUiChangedListener inside NavigationViewDelegate onCreate/onDestroy instead of storing NavigationView in Compose state.
- Regenerate maps-compose/api/maps-compose.api and update unit tests.
Comment thread gradle/libs.versions.toml
compose-bom = "2026.09.00"
constraintlayout = "2.2.2"
desugarJdkLibs = "2.1.5"
lifecycleRuntimeKtx = "2.11.0"
Comment thread gradle/libs.versions.toml
compose-bom = "2026.09.00"
constraintlayout = "2.2.2"
desugarJdkLibs = "2.1.5"
lifecycleRuntimeKtx = "2.11.0"
Comment thread gradle/libs.versions.toml
compose-bom = "2026.09.00"
constraintlayout = "2.2.2"
desugarJdkLibs = "2.1.5"
lifecycleRuntimeKtx = "2.11.0"
Comment thread gradle/libs.versions.toml
mapsecrets = "2.0.1"
mapsutils = "7.0.0"
navigation = "8.1.0"
places = "6.0.2"

@kikoso kikoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The branch is behind main, so it will need an update before merging.

@kikoso
kikoso merged commit 536cec6 into main Nov 24, 2026
14 checks passed
@kikoso
kikoso deleted the feat/navigation-sdk branch November 24, 2026 06:18
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.

4 participants