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
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -167,6 +168,7 @@ fun GoogleMapView(
var mapVisible by remember { mutableStateOf(true) }

var darkMode by remember { mutableStateOf(mapColorScheme) }
val systemInDarkTheme = isSystemInDarkTheme()

if (mapVisible) {
GoogleMap(
Expand Down Expand Up @@ -303,11 +305,7 @@ fun GoogleMapView(
MapButton(
text = "Toggle Dark Mode",
onClick = {
darkMode =
if (darkMode == ComposeMapColorScheme.DARK)
ComposeMapColorScheme.LIGHT
else
ComposeMapColorScheme.DARK
darkMode = toggledMapColorScheme(darkMode, systemInDarkTheme)
},
modifier = Modifier
.testTag("toggleDarkMode")
Expand Down Expand Up @@ -347,6 +345,19 @@ fun GoogleMapView(
}
}

internal fun toggledMapColorScheme(
current: ComposeMapColorScheme,
systemInDarkTheme: Boolean,
): ComposeMapColorScheme = when (current) {
ComposeMapColorScheme.LIGHT -> ComposeMapColorScheme.DARK
ComposeMapColorScheme.DARK -> ComposeMapColorScheme.LIGHT
ComposeMapColorScheme.FOLLOW_SYSTEM -> if (systemInDarkTheme) {
ComposeMapColorScheme.LIGHT
} else {
ComposeMapColorScheme.DARK
}
}

@Composable
private fun MapTypeControls(
onMapTypeClick: (MapType) -> Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.maps.android.compose

import com.google.common.truth.Truth.assertThat
import org.junit.Test

class BasicMapActivityTest {

@Test
fun lightSchemeTogglesToDark() {
val result = toggledMapColorScheme(
current = ComposeMapColorScheme.LIGHT,
systemInDarkTheme = false,
)

assertThat(result).isEqualTo(ComposeMapColorScheme.DARK)
}

@Test
fun darkSchemeTogglesToLight() {
val result = toggledMapColorScheme(
current = ComposeMapColorScheme.DARK,
systemInDarkTheme = true,
)

assertThat(result).isEqualTo(ComposeMapColorScheme.LIGHT)
}

@Test
fun followSystemTogglesAwayFromEffectiveScheme() {
assertThat(
toggledMapColorScheme(
current = ComposeMapColorScheme.FOLLOW_SYSTEM,
systemInDarkTheme = false,
)
).isEqualTo(ComposeMapColorScheme.DARK)
assertThat(
toggledMapColorScheme(
current = ComposeMapColorScheme.FOLLOW_SYSTEM,
systemInDarkTheme = true,
)
).isEqualTo(ComposeMapColorScheme.LIGHT)
}
}