Repository navigation
feat: support custom MapView delegates and add Navigation SDK sample app - #1061
Conversation
Coverage (unit tests)Compared against
Line and branch coverage from unit test reports. History is recorded on the |
af57c5e to
e681c01
Compare
a5df619 to
ce14db7
Compare
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
ce14db7 to
8e28a51
Compare
Coverage (instrumentation tests)
Files
|
8e28a51 to
1d3955d
Compare
| * | ||
| * @param T the underlying [ViewGroup] type hosted by this delegate | ||
| */ | ||
| public interface MapViewDelegate<out T : ViewGroup> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Agreed — addressed in 6624a123:
- Marked
MapViewDelegate,DefaultMapViewDelegate, and the delegate-basedGoogleMapoverload (@JvmName("GoogleMapWithDelegate")) with@MapsComposeExperimentalApi, restoring the standard non-experimentalGoogleMapsignature unchanged frommain(and removing the@Deprecated(HIDDEN)shim). - Added
onTrimMemory(level: Int)toMapViewDelegatewith a default implementation delegating toonLowMemory()whenlevel >= TRIM_MEMORY_UI_HIDDEN, wiredcomponentCallbacks2()to forward the real trim level directly, and updatedNavigationViewDelegateto pass the exact trim level through toNavigationView.
Keeping it @MapsComposeExperimentalApi also leaves room to evolve lifecycle hooks like onSaveInstanceState cleanly before stabilizing.
| * @param mapViewFactory factory for creating the [MapView] when [mapViewDelegateFactory] is not | ||
| * overridden |
There was a problem hiding this comment.
If someone passes both mapViewFactory and mapViewDelegateFactory, the first one is silently ignored. Could we at least make it explicit in the KDoc?
| * @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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
- 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.
| compose-bom = "2026.09.00" | ||
| constraintlayout = "2.2.2" | ||
| desugarJdkLibs = "2.1.5" | ||
| lifecycleRuntimeKtx = "2.11.0" |
| compose-bom = "2026.09.00" | ||
| constraintlayout = "2.2.2" | ||
| desugarJdkLibs = "2.1.5" | ||
| lifecycleRuntimeKtx = "2.11.0" |
| compose-bom = "2026.09.00" | ||
| constraintlayout = "2.2.2" | ||
| desugarJdkLibs = "2.1.5" | ||
| lifecycleRuntimeKtx = "2.11.0" |
| mapsecrets = "2.0.1" | ||
| mapsutils = "7.0.0" | ||
| navigation = "8.1.0" | ||
| places = "6.0.2" |
kikoso
left a comment
There was a problem hiding this comment.
Looks good to me. The branch is behind main, so it will need an update before merging.
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.