Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <T: Exception> assertExceptionIsNotThrown(exception: KClass<T>, block: () -> Unit) {
try {
block()
} catch (e: Exception) {
if (exception.isInstance(e)) {
fail("${e.javaClass.simpleName} was thrown")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -139,7 +138,7 @@ public fun GoogleMap(
locationSource = currentLocationSource,
mapProperties = currentMapProperties,
mapUiSettings = currentUiSettings,
colorMapScheme = currentColorScheme.value
colorMapScheme = currentColorScheme?.value
)

MapClickListenerUpdater()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down