Skip to content

Commit 574a647

Browse files
dkhawkkikoso
andauthored
fix: Rollback of map delegate code and navigation SDK integration. (#689)
* fix: Rollback of map delegate code and navigation SDK integration. * fix: removed sarif old app * fix: fix usage of maps-app --------- Co-authored-by: Enrique López Mañas <[email protected]>
1 parent d9fb9df commit 574a647

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+33
-1318
lines changed

.github/workflows/lint-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141

4242
- name: Merge SARIF files
4343
run: |
44-
jq -s '{ "$schema": "https://json.schemastore.org/sarif-2.1.0", "version": "2.1.0", "runs": map(.runs) | add }' maps-compose/build/reports/lint-results.sarif maps-compose-utils/build/reports/lint-results.sarif maps-compose-widgets/build/reports/lint-results.sarif maps-app/build/reports/lint-results.sarif navigation-app/build/reports/lint-results.sarif > merged.sarif
44+
jq -s '{ "$schema": "https://json.schemastore.org/sarif-2.1.0", "version": "2.1.0", "runs": map(.runs) | add }' maps-compose/build/reports/lint-results.sarif maps-compose-utils/build/reports/lint-results.sarif maps-compose-widgets/build/reports/lint-results.sarif maps-app/build/reports/lint-results.sarif > merged.sarif
4545
4646
- name: Upload SARIF file
4747
uses: github/codeql-action/upload-sarif@v3

README.md

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,15 @@ dependencies {
4242

4343
## Sample App
4444

45-
Currently, there are two sample apps in the repository: [maps-app](maps-app) and [navigation-app](navigation-app). Each of them run a different version of the Android Maps Compose SDK, where either the maps or the navigation SDK are run, respectively.
45+
This repository includes a [sample app](maps-app).
4646

47-
To run the maps demo app, ensure you've met the requirements above then:
47+
To run the demo app, ensure you've met the requirements above then:
4848

4949
1. Open the `secrets.properties` file in your top-level directory, and then add the following code. Replace YOUR_API_KEY with your API key. Store your key in this file because secrets.properties is excluded from being checked into a version control system.
5050
If the `secrets.properties` file does not exist, create it in the same folder as the `local.default.properties` file.
5151
```
5252
MAPS_API_KEY=YOUR_API_KEY
5353
```
54-
55-
If you want to use also the Navigation SDK, make sure the PLACES_API_KEY also contains an entry.
56-
```
57-
PLACES_API_KEY=DEFAULT_API_KEY
58-
```
59-
6054
1. Build and run
6155

6256
## Documentation
@@ -397,18 +391,6 @@ GoogleMap(
397391
}
398392
```
399393

400-
## Using the Navigation SDK
401-
402-
In order to use the Navigation SDK, make sure to include the Composable `NavigationScreen` as follows:
403-
404-
```kotlin
405-
NavigationScreen(
406-
modifier = Modifier.padding(innerPadding),
407-
deviceLocation = location
408-
)
409-
```
410-
411-
412394
</details>
413395

414396
## Maps Compose Utility Library
@@ -444,7 +426,7 @@ The `fetchStreetViewData` method provides functionality to check whether a locat
444426
> Be sure to [enable Street View Static API](https://goo.gle/enable-sv-static-api) on the project associated with your API key.
445427
446428
You can see example usage
447-
in the [`StreetViewActivity`](maps-app/src/main/java/com/google/maps/android/compose/StreetViewActivity.kt) of the demo app:
429+
in the [`StreetViewActivity`](https://github.com/googlemaps/android-maps-compose/blob/main/maps-app/src/main/java/com/google/maps/android/compose/StreetViewActivity.kt) of the demo app:
448430

449431
```kotlin
450432
streetViewResult =
@@ -507,7 +489,7 @@ This library is not a Google Maps Platform Core Service. Therefore, the Google M
507489

508490
## Support
509491

510-
This library is offered via an open source [license]. It is not governed by the Google Maps Platform Support [Technical Support Services Guidelines], the [SLA], or the [Deprecation Policy]. However, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service.
492+
This library is offered via an open source [license]. It is not governed by the Google Maps Platform Support [Technical Support Services Guidelines, the SLA, or the [Deprecation Policy]. However, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service.
511493

512494
This library adheres to [semantic versioning] to indicate when backwards-incompatible changes are introduced. Accordingly, while the library is in version 0.x, backwards-incompatible changes may be introduced at any time.
513495

maps-compose/src/main/java/com/google/maps/android/compose/ComposeInfoWindowAdapter.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.google.maps.android.compose
1717
import android.view.View
1818
import androidx.compose.ui.platform.ComposeView
1919
import com.google.android.gms.maps.GoogleMap
20+
import com.google.android.gms.maps.MapView
2021
import com.google.android.gms.maps.model.Marker
2122

2223
/**
@@ -35,7 +36,7 @@ import com.google.android.gms.maps.model.Marker
3536
* implementation should be updated.
3637
*/
3738
internal class ComposeInfoWindowAdapter(
38-
private val mapViewDelegate: AbstractMapViewDelegate<*>,
39+
private val mapView: MapView,
3940
private val markerNodeFinder: (Marker) -> MarkerNode?
4041
) : GoogleMap.InfoWindowAdapter {
4142

@@ -45,10 +46,10 @@ internal class ComposeInfoWindowAdapter(
4546
if (content == null) {
4647
return null
4748
}
48-
val view = ComposeView(mapViewDelegate.mapView.context).apply {
49+
val view = ComposeView(mapView.context).apply {
4950
setContent { content(marker) }
5051
}
51-
mapViewDelegate.renderComposeViewOnce(view, parentContext = markerNode.compositionContext)
52+
mapView.renderComposeViewOnce(view, parentContext = markerNode.compositionContext)
5253
return view
5354
}
5455

@@ -58,10 +59,11 @@ internal class ComposeInfoWindowAdapter(
5859
if (infoWindow == null) {
5960
return null
6061
}
61-
val view = ComposeView(mapViewDelegate.mapView.context).apply {
62+
val view = ComposeView(mapView.context).apply {
6263
setContent { infoWindow(marker) }
6364
}
64-
mapViewDelegate.renderComposeViewOnce(view, parentContext = markerNode.compositionContext)
65+
mapView.renderComposeViewOnce(view, parentContext = markerNode.compositionContext)
6566
return view
6667
}
68+
6769
}

maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt

Lines changed: 13 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ package com.google.maps.android.compose
1616

1717
import android.content.ComponentCallbacks
1818
import android.content.ComponentCallbacks2
19-
import android.content.Context
2019
import android.content.res.Configuration
2120
import android.location.Location
2221
import android.os.Bundle
22+
import android.util.Log
2323
import android.view.View
2424
import androidx.compose.foundation.layout.Box
2525
import androidx.compose.foundation.layout.PaddingValues
@@ -36,15 +36,12 @@ import androidx.compose.runtime.rememberCoroutineScope
3636
import androidx.compose.runtime.rememberUpdatedState
3737
import androidx.compose.runtime.setValue
3838
import androidx.compose.ui.Modifier
39-
import androidx.compose.ui.platform.AbstractComposeView
40-
import androidx.compose.ui.platform.ComposeView
4139
import androidx.compose.ui.platform.LocalInspectionMode
4240
import androidx.compose.ui.viewinterop.AndroidView
4341
import androidx.lifecycle.Lifecycle
4442
import androidx.lifecycle.LifecycleEventObserver
4543
import androidx.lifecycle.LifecycleOwner
4644
import androidx.lifecycle.findViewTreeLifecycleOwner
47-
import com.google.android.gms.maps.GoogleMap
4845
import com.google.android.gms.maps.GoogleMapOptions
4946
import com.google.android.gms.maps.LocationSource
5047
import com.google.android.gms.maps.MapView
@@ -102,7 +99,6 @@ public fun GoogleMap(
10299
onPOIClick: ((PointOfInterest) -> Unit)? = null,
103100
contentPadding: PaddingValues = DefaultMapContentPadding,
104101
mapColorScheme: ComposeMapColorScheme? = null,
105-
mapViewCreator: ((Context, GoogleMapOptions) -> AbstractMapViewDelegate<*>)? = null,
106102
content: @Composable @GoogleMapComposable () -> Unit = {},
107103
) {
108104
// When in preview, early return a Box with the received modifier preserving layout
@@ -150,30 +146,19 @@ public fun GoogleMap(
150146
var subcompositionJob by remember { mutableStateOf<Job?>(null) }
151147
val parentCompositionScope = rememberCoroutineScope()
152148

153-
var delegate by remember {
154-
mutableStateOf<AbstractMapViewDelegate<*>?>(null)
155-
}
156-
157149
AndroidView(
158150
modifier = modifier,
159151
factory = { context ->
160-
if (mapViewCreator != null) {
161-
mapViewCreator(context, googleMapOptionsFactory())
162-
} else {
163-
MapViewDelegate(MapView(context, googleMapOptionsFactory()))
164-
}.also { mapViewDelegate: AbstractMapViewDelegate<*> ->
165-
delegate = mapViewDelegate
166-
val mapView = mapViewDelegate.mapView
167-
152+
MapView(context, googleMapOptionsFactory()).also { mapView ->
168153
val componentCallbacks = object : ComponentCallbacks2 {
169154
override fun onConfigurationChanged(newConfig: Configuration) {}
170155
@Deprecated("Deprecated in Java", ReplaceWith("onTrimMemory(level)"))
171-
override fun onLowMemory() { mapViewDelegate.onLowMemory() }
172-
override fun onTrimMemory(level: Int) { mapViewDelegate.onLowMemory() }
156+
override fun onLowMemory() { mapView.onLowMemory() }
157+
override fun onTrimMemory(level: Int) { mapView.onLowMemory() }
173158
}
174159
context.registerComponentCallbacks(componentCallbacks)
175160

176-
val lifecycleObserver = MapLifecycleEventObserver(mapViewDelegate)
161+
val lifecycleObserver = MapLifecycleEventObserver(mapView)
177162

178163
mapView.tag = MapTagData(componentCallbacks, lifecycleObserver)
179164

@@ -195,21 +180,22 @@ public fun GoogleMap(
195180
}
196181

197182
mapView.addOnAttachStateChangeListener(onAttachStateListener)
198-
}.mapView
183+
}
199184
},
200185
onReset = { /* View is detached. */ },
201186
onRelease = { mapView ->
202-
val (componentCallbacks, lifecycleObserver) = delegate!!.tagData
187+
val (componentCallbacks, lifecycleObserver) = mapView.tagData
203188
mapView.context.unregisterComponentCallbacks(componentCallbacks)
204189
lifecycleObserver.moveToDestroyedState()
205190
mapView.tag = null
206191
},
207192
update = { mapView ->
208193
if (subcompositionJob == null) {
194+
Log.d("Gollum", "subcomposition running")
209195
subcompositionJob = parentCompositionScope.launchSubcomposition(
210196
mapUpdaterState,
211197
parentComposition,
212-
delegate!!,
198+
mapView,
213199
mapClickListeners,
214200
currentContent,
215201
)
@@ -225,15 +211,15 @@ public fun GoogleMap(
225211
private fun CoroutineScope.launchSubcomposition(
226212
mapUpdaterState: MapUpdaterState,
227213
parentComposition: CompositionContext,
228-
mapViewDelegate: AbstractMapViewDelegate<*>,
214+
mapView: MapView,
229215
mapClickListeners: MapClickListeners,
230216
content: @Composable @GoogleMapComposable () -> Unit,
231217
): Job {
232218
// Use [CoroutineStart.UNDISPATCHED] to kick off GoogleMap loading immediately
233219
return launch(start = CoroutineStart.UNDISPATCHED) {
234-
val map = mapViewDelegate.awaitMap()
220+
val map = mapView.awaitMap()
235221
val composition = Composition(
236-
applier = MapApplier(map, mapViewDelegate, mapClickListeners),
222+
applier = MapApplier(map, mapView, mapClickListeners),
237223
parent = parentComposition
238224
)
239225

@@ -324,65 +310,7 @@ public fun googleMapFactory(
324310
}
325311
}
326312

327-
public interface AbstractMapViewDelegate<T : View> {
328-
public fun onCreate(savedInstanceState: Bundle?)
329-
public fun onStart()
330-
public fun onResume()
331-
public fun onPause()
332-
public fun onStop()
333-
public fun onLowMemory()
334-
public fun onDestroy()
335-
public suspend fun awaitMap(): GoogleMap
336-
public fun renderComposeViewOnce(
337-
view: AbstractComposeView,
338-
parentContext: CompositionContext,
339-
onAddedToWindow: ((View) -> Unit)? = null,
340-
)
341-
342-
public fun startRenderingComposeView(
343-
view: AbstractComposeView,
344-
parentContext: CompositionContext,
345-
): ComposeUiViewRenderer.RenderHandle
346-
347-
public val mapView: T
348-
}
349-
350-
private val <T : View> AbstractMapViewDelegate<T>.tagData: MapTagData
351-
get() = mapView.tag as MapTagData
352-
353-
public class MapViewDelegate(override val mapView: MapView) : AbstractMapViewDelegate<MapView> {
354-
override fun onCreate(savedInstanceState: Bundle?): Unit = mapView.onCreate(savedInstanceState)
355-
override fun onStart(): Unit = mapView.onStart()
356-
override fun onResume(): Unit = mapView.onResume()
357-
override fun onPause(): Unit = mapView.onPause()
358-
override fun onStop(): Unit = mapView.onStop()
359-
override fun onLowMemory(): Unit = mapView.onLowMemory()
360-
override fun onDestroy(): Unit = mapView.onDestroy()
361-
override suspend fun awaitMap(): GoogleMap = mapView.awaitMap()
362-
override fun renderComposeViewOnce(
363-
view: AbstractComposeView,
364-
parentContext: CompositionContext,
365-
onAddedToWindow: ((View) -> Unit)?
366-
) {
367-
mapView.renderComposeViewOnce(
368-
view = view,
369-
parentContext = parentContext,
370-
onAddedToWindow = onAddedToWindow
371-
)
372-
}
373-
374-
override fun startRenderingComposeView(
375-
view: AbstractComposeView,
376-
parentContext: CompositionContext
377-
): ComposeUiViewRenderer.RenderHandle {
378-
return mapView.startRenderingComposeView(
379-
view = view,
380-
parentContext = parentContext,
381-
)
382-
}
383-
}
384-
385-
private class MapLifecycleEventObserver(private val mapView: AbstractMapViewDelegate<*>) : LifecycleEventObserver {
313+
private class MapLifecycleEventObserver(private val mapView: MapView) : LifecycleEventObserver {
386314
private var currentLifecycleState: Lifecycle.State = Lifecycle.State.INITIALIZED
387315

388316
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {

maps-compose/src/main/java/com/google/maps/android/compose/MapApplier.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package com.google.maps.android.compose
1616

1717
import androidx.compose.runtime.AbstractApplier
1818
import com.google.android.gms.maps.GoogleMap
19+
import com.google.android.gms.maps.MapView
1920
import com.google.android.gms.maps.model.Circle
2021
import com.google.android.gms.maps.model.GroundOverlay
2122
import com.google.android.gms.maps.model.Marker
@@ -37,7 +38,7 @@ private object MapNodeRoot : MapNode
3738
// for that particular listener; yet MapClickListeners never actually changes.
3839
internal class MapApplier(
3940
val map: GoogleMap,
40-
internal val mapViewDelegate: AbstractMapViewDelegate<*>,
41+
internal val mapView: MapView,
4142
val mapClickListeners: MapClickListeners,
4243
) : AbstractApplier<MapNode>(MapNodeRoot) {
4344

@@ -210,7 +211,7 @@ internal class MapApplier(
210211
})
211212
map.setInfoWindowAdapter(
212213
ComposeInfoWindowAdapter(
213-
mapViewDelegate,
214+
mapView,
214215
markerNodeFinder = { marker ->
215216
decorations.firstOrNull { it is MarkerNode && it.marker == marker }
216217
as MarkerNode?

maps-compose/src/main/java/com/google/maps/android/compose/MapComposeViewRender.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.io.Closeable
2222
* to a window. [onAddedToWindow] is called in place, and then [view] is removed from the window
2323
* before returning.
2424
*/
25-
public fun MapView.renderComposeViewOnce(
25+
internal fun MapView.renderComposeViewOnce(
2626
view: AbstractComposeView,
2727
onAddedToWindow: ((View) -> Unit)? = null,
2828
parentContext: CompositionContext,
@@ -38,7 +38,7 @@ public fun MapView.renderComposeViewOnce(
3838
* to a window. A [ComposeUiViewRenderer.RenderHandle] is returned, which must be disposed after
3939
* this view no longer needs to render. Disposing removes [view] from the [MapView].
4040
*/
41-
public fun MapView.startRenderingComposeView(
41+
internal fun MapView.startRenderingComposeView(
4242
view: AbstractComposeView,
4343
parentContext: CompositionContext,
4444
): ComposeUiViewRenderer.RenderHandle {
@@ -69,7 +69,7 @@ private fun MapView.ensureContainerView(): NoDrawContainerView {
6969
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
7070
@Composable
7171
public fun rememberComposeUiViewRenderer(): ComposeUiViewRenderer {
72-
val mapView = (currentComposer.applier as MapApplier).mapViewDelegate
72+
val mapView = (currentComposer.applier as MapApplier).mapView
7373
val compositionContext = rememberCompositionContext()
7474

7575
return remember(compositionContext) {

maps-compose/src/main/java/com/google/maps/android/compose/MapUpdater.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public val DefaultMapContentPadding: PaddingValues = PaddingValues()
100100
@Composable
101101
internal inline fun MapUpdater(mapUpdaterState: MapUpdaterState) = with(mapUpdaterState) {
102102
val map = (currentComposer.applier as MapApplier).map
103-
val mapView = (currentComposer.applier as MapApplier).mapViewDelegate.mapView
103+
val mapView = (currentComposer.applier as MapApplier).mapView
104104
if (mergeDescendants) {
105105
mapView.importantForAccessibility = IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
106106
}

navigation-app/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)