Skip to content
Merged
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
Expand Up @@ -27,8 +27,11 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.platform.app.InstrumentationRegistry
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MapColorScheme
import com.google.common.truth.Truth.assertThat
import com.google.maps.android.compose.LatLngSubject.Companion.assertThat
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -88,15 +91,51 @@ class GoogleMapViewTests {

@Test
fun testRightInitialColorScheme() {
initMap()
assertThat(mapColorScheme).isEqualTo(ComposeMapColorScheme.FOLLOW_SYSTEM)
var capturedOptions: GoogleMapOptions? = null
composeTestRule.setContent {
GoogleMap(
mapColorScheme = ComposeMapColorScheme.FOLLOW_SYSTEM,
mapViewFactory = { context, options ->
capturedOptions = options
MapView(context, options)
}
)
}
assertThat(capturedOptions?.mapColorScheme).isEqualTo(MapColorScheme.FOLLOW_SYSTEM)
}

@Test
fun testRightColorSchemeAfterChangingIt() {
mapColorScheme = ComposeMapColorScheme.DARK
initMap()
assertThat(mapColorScheme).isEqualTo(ComposeMapColorScheme.DARK)
var capturedOptions: GoogleMapOptions? = null
composeTestRule.setContent {
GoogleMap(
mapColorScheme = ComposeMapColorScheme.DARK,
mapViewFactory = { context, options ->
capturedOptions = options
MapView(context, options)
}
)
}
assertThat(capturedOptions?.mapColorScheme).isEqualTo(MapColorScheme.DARK)
}

@Test
fun testColorSchemeInOptionsNotOverwritten() {
var capturedOptions: GoogleMapOptions? = null
composeTestRule.setContent {
GoogleMap(
googleMapOptionsFactory = {
GoogleMapOptions().mapColorScheme(MapColorScheme.DARK)
},
mapColorScheme = ComposeMapColorScheme.FOLLOW_SYSTEM,
mapViewFactory = { context, options ->
capturedOptions = options
MapView(context, options)
}
)
}
// When googleMapOptionsFactory explicitly sets a color scheme (e.g. DARK), it should not be overwritten by mapColorScheme
assertThat(capturedOptions?.mapColorScheme).isEqualTo(MapColorScheme.DARK)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,16 @@ public fun GoogleMap(
// out of focus traversal entirely.
modifier = if (focusable) modifier.focusable() else modifier,
factory = { context ->
val options = googleMapOptionsFactory()
val options = googleMapOptionsFactory().let { opts ->
// If mapColorScheme is passed to GoogleMap() and has not been explicitly set
// in googleMapOptionsFactory (where 0 / MapColorScheme.LIGHT is the Java int default),
// apply it to GoogleMapOptions so MapView is created with it.
if (mapColorScheme != null && opts.mapColorScheme == 0) {
opts.mapColorScheme(mapColorScheme.value)
} else {
opts
}
}
cameraPositionState.isLiteMode = options.liteMode == true
mapViewFactory(context, options).also { mapView ->
mapView.applyFocusability(focusable)
Expand Down