diff --git a/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapTests.kt b/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapTests.kt new file mode 100644 index 000000000..18644ace9 --- /dev/null +++ b/app/src/androidTest/java/com/google/maps/android/compose/GoogleMapTests.kt @@ -0,0 +1,48 @@ +package com.google.maps.android.compose + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.ui.Modifier +import androidx.compose.ui.test.junit4.createComposeRule +import com.google.android.gms.maps.GoogleMapOptions +import org.junit.Assert.fail +import org.junit.Rule +import org.junit.Test +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit +import kotlin.reflect.KClass + +class GoogleMapTests { + + @get:Rule + val composeTestRule = createComposeRule() + + @Test + fun testMapInLiteModeDontCrashAfterUsingMapColorScheme() { + val countDownLatch = CountDownLatch(1) + assertExceptionIsNotThrown(UnsupportedOperationException::class) { + composeTestRule.setContent { + GoogleMap( + modifier = Modifier.fillMaxSize(), + googleMapOptionsFactory = { + GoogleMapOptions().liteMode(true) + }, + onMapLoaded = { + countDownLatch.countDown() + } + ) { + } + } + countDownLatch.await(30, TimeUnit.SECONDS) + } + } + + private fun assertExceptionIsNotThrown(exception: KClass, block: () -> Unit) { + try { + block() + } catch (e: Exception) { + if (exception.isInstance(e)) { + fail("${e.javaClass.simpleName} was thrown") + } + } + } +} \ No newline at end of file diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt b/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt index d8911d5b1..df54fcd88 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/GoogleMap.kt @@ -70,8 +70,7 @@ import kotlinx.coroutines.awaitCancellation * @param onPOIClick lambda invoked when a POI is clicked * @param contentPadding the padding values used to signal that portions of the map around the edges * may be obscured. The map will move the Google logo, etc. to avoid overlapping the padding. - * @param mapColorScheme Defines the color scheme for the Map. By default it will be - * [ComposeMapColorScheme.FOLLOW_SYSTEM]. + * @param mapColorScheme Defines the color scheme for the Map. * @param content the content of the map */ @Composable @@ -92,7 +91,7 @@ public fun GoogleMap( onMyLocationClick: ((Location) -> Unit)? = null, onPOIClick: ((PointOfInterest) -> Unit)? = null, contentPadding: PaddingValues = DefaultMapContentPadding, - mapColorScheme: ComposeMapColorScheme = ComposeMapColorScheme.FOLLOW_SYSTEM, + mapColorScheme: ComposeMapColorScheme? = null, content: @Composable @GoogleMapComposable () -> Unit = {}, ) { // When in preview, early return a Box with the received modifier preserving layout @@ -139,7 +138,7 @@ public fun GoogleMap( locationSource = currentLocationSource, mapProperties = currentMapProperties, mapUiSettings = currentUiSettings, - colorMapScheme = currentColorScheme.value + colorMapScheme = currentColorScheme?.value ) MapClickListenerUpdater() diff --git a/maps-compose/src/main/java/com/google/maps/android/compose/MapUpdater.kt b/maps-compose/src/main/java/com/google/maps/android/compose/MapUpdater.kt index 6282b52be..44a0b5df1 100644 --- a/maps-compose/src/main/java/com/google/maps/android/compose/MapUpdater.kt +++ b/maps-compose/src/main/java/com/google/maps/android/compose/MapUpdater.kt @@ -105,7 +105,7 @@ internal inline fun MapUpdater( locationSource: LocationSource?, mapProperties: MapProperties, mapUiSettings: MapUiSettings, - colorMapScheme: Int, + colorMapScheme: Int?, ) { val map = (currentComposer.applier as MapApplier).map val mapView = (currentComposer.applier as MapApplier).mapView @@ -141,7 +141,11 @@ internal inline fun MapUpdater( set(mapProperties.mapType) { map.mapType = it.value } set(mapProperties.maxZoomPreference) { map.setMaxZoomPreference(it) } set(mapProperties.minZoomPreference) { map.setMinZoomPreference(it) } - set(colorMapScheme) { map.mapColorScheme = it } + set(colorMapScheme) { + if (it != null) { + map.mapColorScheme = it + } + } set(contentPadding) { val node = this with(this.density) {