Skip to content

Commit 3ac3f52

Browse files
dkhawkakexorcist
andauthored
Fix/always dispose on main thread (#743)
* fix: always run the `launchSubcomposition` on the main thread (prevent running on non-main thread in instrumented test) * chore: fixes build --------- Co-authored-by: Akexorcist <[email protected]>
1 parent 55d9ca6 commit 3ac3f52

File tree

1 file changed

+6
-1
lines changed
  • maps-compose/src/main/java/com/google/maps/android/compose

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ import com.google.maps.android.compose.meta.AttributionId
5555
import com.google.maps.android.ktx.awaitMap
5656
import kotlinx.coroutines.CoroutineScope
5757
import kotlinx.coroutines.CoroutineStart
58+
import kotlinx.coroutines.Dispatchers
5859
import kotlinx.coroutines.Job
5960
import kotlinx.coroutines.awaitCancellation
6061
import kotlinx.coroutines.launch
62+
import kotlinx.coroutines.withContext
6163

6264
/**
6365
* A compose container for a [MapView].
@@ -235,7 +237,10 @@ private fun CoroutineScope.launchSubcomposition(
235237
content: @Composable @GoogleMapComposable () -> Unit,
236238
): Job {
237239
// Use [CoroutineStart.UNDISPATCHED] to kick off GoogleMap loading immediately
238-
return launch(start = CoroutineStart.UNDISPATCHED) {
240+
return launch(
241+
context = Dispatchers.Main,
242+
start = CoroutineStart.UNDISPATCHED
243+
) {
239244
val map = mapView.awaitMap()
240245
val composition = Composition(
241246
applier = MapApplier(map, mapView, mapClickListeners),

0 commit comments

Comments
 (0)